[-] MO : HomeSlider - Added PS_USE_SQL_SLAVE
[-] MO : FavoriteProducts - Fixed link git-svn-id: http://dev.prestashop.com/svn/v1/branches/1.5.x@8177 b9a71923-0436-4b27-9f14-aed3839534dd
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
/*
|
||||
* 2007-2011 PrestaShop
|
||||
* 2007-2011 PrestaShop
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
@@ -28,44 +28,44 @@
|
||||
class FavoriteProduct extends ObjectModel
|
||||
{
|
||||
public $id;
|
||||
|
||||
|
||||
public $id_product;
|
||||
|
||||
|
||||
public $id_customer;
|
||||
|
||||
|
||||
public $id_shop;
|
||||
|
||||
|
||||
public $date_add;
|
||||
|
||||
|
||||
public $date_upd;
|
||||
|
||||
|
||||
protected $fieldRequired = array(
|
||||
'id_product',
|
||||
'id_customer',
|
||||
'id_shop'
|
||||
);
|
||||
|
||||
|
||||
protected $fieldsValidate = array(
|
||||
'id_product' => 'isUnsignedInt',
|
||||
'id_customer' => 'isUnsignedInt',
|
||||
'id_shop' => 'isUnsignedInt'
|
||||
);
|
||||
|
||||
|
||||
protected $table = 'favorite_product';
|
||||
|
||||
|
||||
protected $identifier = 'id_favorite_product';
|
||||
|
||||
|
||||
public function getFields()
|
||||
{
|
||||
$this->validateFields();
|
||||
|
||||
|
||||
$fields['id_product'] = (int)$this->id_product;
|
||||
$fields['id_customer'] = (int)$this->id_customer;
|
||||
$fields['id_shop'] = (int)$this->id_shop;
|
||||
|
||||
|
||||
return $fields;
|
||||
}
|
||||
|
||||
|
||||
public static function getFavoriteProducts($id_customer, $id_lang, Shop $shop = null)
|
||||
{
|
||||
if (!$shop)
|
||||
@@ -74,42 +74,42 @@ class FavoriteProduct extends ObjectModel
|
||||
return Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS('
|
||||
SELECT fp.`id_shop`, p.`id_product`, pl.`description_short`, pl.`link_rewrite`, pl.`name`, i.`id_image`, CONCAT(p.`id_product`, \'-\', i.`id_image`) as image
|
||||
FROM `'._DB_PREFIX_.'favorite_product` fp
|
||||
LEFT JOIN `'._DB_PREFIX_.'product` p ON (p.`id_product` = fp.`id_product`)
|
||||
LEFT JOIN `'._DB_PREFIX_.'product` p ON (p.`id_product` = fp.`id_product`)
|
||||
LEFT JOIN `'._DB_PREFIX_.'product_lang` pl ON (p.`id_product` = pl.`id_product` AND pl.`id_lang` = '.(int)$id_lang.$shop->sqlLang('pl').')
|
||||
LEFT OUTER JOIN `'._DB_PREFIX_.'product_attribute` pa ON (p.`id_product` = pa.`id_product` AND `default_on` = 1)
|
||||
LEFT JOIN `'._DB_PREFIX_.'image` i ON (i.`id_product` = p.`id_product` AND i.`cover` = 1)
|
||||
LEFT JOIN `'._DB_PREFIX_.'image_lang` il ON (i.`id_image` = il.`id_image` AND il.`id_lang` = '.(int)($id_lang).')
|
||||
LEFT JOIN `'._DB_PREFIX_.'image_lang` il ON (i.`id_image` = il.`id_image` AND il.`id_lang` = '.(int)($id_lang).')
|
||||
WHERE p.`active` = 1
|
||||
'.$shop->sqlRestriction(false, 'fp'));
|
||||
}
|
||||
|
||||
|
||||
public static function getFavoriteProduct($id_customer, $id_product, Shop $shop = null)
|
||||
{
|
||||
if (!$shop)
|
||||
$shop = Context::getContext()->shop;
|
||||
|
||||
|
||||
$id_favorite_product = Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue('
|
||||
SELECT `id_favorite_product`
|
||||
FROM `'._DB_PREFIX_.'favorite_product`
|
||||
WHERE `id_customer` = '.(int)($id_customer).'
|
||||
AND `id_product` = '.(int)($id_product).'
|
||||
WHERE `id_customer` = '.(int)($id_customer).'
|
||||
AND `id_product` = '.(int)($id_product).'
|
||||
AND `id_shop` = '.(int)($shop->getID()));
|
||||
|
||||
if ($id_favorite_product)
|
||||
return new FavoriteProduct($id_favorite_product);
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public static function isCustomerFavoriteProduct($id_customer, $id_product, Shop $shop = null)
|
||||
{
|
||||
if (!$shop)
|
||||
$shop = Context::getContext()->shop;
|
||||
|
||||
|
||||
return (bool)Db::getInstance()->getValue('
|
||||
SELECT COUNT(*)
|
||||
FROM `'._DB_PREFIX_.'favorite_product`
|
||||
WHERE `id_customer` = '.(int)($id_customer).'
|
||||
AND `id_product` = '.(int)($id_product).'
|
||||
SELECT COUNT(*)
|
||||
FROM `'._DB_PREFIX_.'favorite_product`
|
||||
WHERE `id_customer` = '.(int)($id_customer).'
|
||||
AND `id_product` = '.(int)($id_product).'
|
||||
AND `id_shop` = '.(int)($shop->getID()));
|
||||
}
|
||||
}
|
||||
@@ -27,7 +27,7 @@
|
||||
<script type="text/javascript">
|
||||
{literal}
|
||||
$('document').ready(function(){
|
||||
$('#add_favorites_btn').click(function(){
|
||||
$('#favoriteproducts_block_extra').click(function(){
|
||||
$.ajax({
|
||||
{/literal}url: "{$module_dir}favoriteproducts-ajax.php",{literal}
|
||||
post: "POST",
|
||||
@@ -35,8 +35,8 @@ $('document').ready(function(){
|
||||
success: function(result){
|
||||
if (result == '0')
|
||||
{
|
||||
$('#add_favorites_btn').fadeOut("normal", function() {
|
||||
$('#add_favorites_btn').remove();
|
||||
$('#favoriteproducts_block_extra').fadeOut("normal", function() {
|
||||
$('#favoriteproducts_block_extra').remove();
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -50,4 +50,8 @@ $('document').ready(function(){
|
||||
<li id="favoriteproducts_block_extra">
|
||||
{l s='Add this product to my favorites' mod='favoriteproducts'}
|
||||
</li>
|
||||
{elseif $isCustomerFavoriteProduct AND $isLogged}
|
||||
<li id="afavoriteproducts_block_extra_added">
|
||||
{l s='This product is already one of my favorites' mod='favoriteproducts'}
|
||||
</li>
|
||||
{/if}
|
||||
@@ -44,4 +44,5 @@
|
||||
#usefull_link_block li#favoriteproducts_block_extra {
|
||||
padding-left:20px;
|
||||
background:url(img/add_favorite.gif) no-repeat 0 0;
|
||||
cursor: pointer;
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
/*
|
||||
* 2007-2011 PrestaShop
|
||||
* 2007-2011 PrestaShop
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
@@ -27,7 +27,7 @@
|
||||
|
||||
if (!defined('_CAN_LOAD_FILES_'))
|
||||
exit;
|
||||
|
||||
|
||||
class FavoriteProducts extends Module
|
||||
{
|
||||
public function __construct()
|
||||
@@ -46,12 +46,12 @@ class FavoriteProducts extends Module
|
||||
|
||||
public function install()
|
||||
{
|
||||
if (!parent::install()
|
||||
if (!parent::install()
|
||||
OR !$this->registerHook('myAccountBlock')
|
||||
OR !$this->registerHook('extraLeft')
|
||||
OR !$this->registerHook('extraLeft')
|
||||
OR !$this->registerHook('header'))
|
||||
return false;
|
||||
|
||||
|
||||
if (!Db::getInstance()->Execute('
|
||||
CREATE TABLE `'._DB_PREFIX_.'favorite_product` (
|
||||
`id_favorite_product` int(10) unsigned NOT NULL auto_increment,
|
||||
@@ -63,44 +63,43 @@ class FavoriteProducts extends Module
|
||||
PRIMARY KEY (`id_favorite_product`))
|
||||
ENGINE='._MYSQL_ENGINE_.' DEFAULT CHARSET=utf8'))
|
||||
return false;
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
public function uninstall()
|
||||
{
|
||||
if (!parent::uninstall() OR !Db::getInstance()->Execute('DROP TABLE `'._DB_PREFIX_.'favorite_product`'))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
public function hookCustomerAccount($params)
|
||||
{
|
||||
include_once(dirname(__FILE__).'/FavoriteProduct.php');
|
||||
|
||||
|
||||
$favoriteProducts = FavoriteProduct::getFavoriteProducts($this->context->customer->id, $this->context->language->id);
|
||||
|
||||
|
||||
$this->context->smarty->assign(array('favorite_products' => $favoriteProducts));
|
||||
|
||||
|
||||
return $this->display(__FILE__, 'my-account.tpl');
|
||||
}
|
||||
|
||||
|
||||
public function hookMyAccountBlock($params)
|
||||
{
|
||||
return $this->hookCustomerAccount($params);
|
||||
}
|
||||
|
||||
|
||||
public function hookExtraLeft($params)
|
||||
{
|
||||
include_once(dirname(__FILE__).'/FavoriteProduct.php');
|
||||
|
||||
|
||||
$this->context->smarty->assign(array(
|
||||
'isCustomerFavoriteProduct' => (FavoriteProduct::isCustomerFavoriteProduct($this->context->customer->id, Tools::getValue('id_product')) ? 1 : 0),
|
||||
'isLogged' => (int)$this->context->customer->logged));
|
||||
|
||||
return $this->display(__FILE__, 'favoriteproducts-extra.tpl');
|
||||
}
|
||||
|
||||
|
||||
public function hookHeader($params)
|
||||
{
|
||||
$this->context->controller->addCSS($this->_path.'favoriteproducts.css', 'all');
|
||||
|
||||
Reference in New Issue
Block a user