[-] 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:
bMancone
2011-08-24 14:23:36 +00:00
parent 0c68e37e40
commit 829ad87f8a
6 changed files with 60 additions and 56 deletions
+26 -26
View File
@@ -1,6 +1,6 @@
<?php <?php
/* /*
* 2007-2011 PrestaShop * 2007-2011 PrestaShop
* *
* NOTICE OF LICENSE * NOTICE OF LICENSE
* *
@@ -28,44 +28,44 @@
class FavoriteProduct extends ObjectModel class FavoriteProduct extends ObjectModel
{ {
public $id; public $id;
public $id_product; public $id_product;
public $id_customer; public $id_customer;
public $id_shop; public $id_shop;
public $date_add; public $date_add;
public $date_upd; public $date_upd;
protected $fieldRequired = array( protected $fieldRequired = array(
'id_product', 'id_product',
'id_customer', 'id_customer',
'id_shop' 'id_shop'
); );
protected $fieldsValidate = array( protected $fieldsValidate = array(
'id_product' => 'isUnsignedInt', 'id_product' => 'isUnsignedInt',
'id_customer' => 'isUnsignedInt', 'id_customer' => 'isUnsignedInt',
'id_shop' => 'isUnsignedInt' 'id_shop' => 'isUnsignedInt'
); );
protected $table = 'favorite_product'; protected $table = 'favorite_product';
protected $identifier = 'id_favorite_product'; protected $identifier = 'id_favorite_product';
public function getFields() public function getFields()
{ {
$this->validateFields(); $this->validateFields();
$fields['id_product'] = (int)$this->id_product; $fields['id_product'] = (int)$this->id_product;
$fields['id_customer'] = (int)$this->id_customer; $fields['id_customer'] = (int)$this->id_customer;
$fields['id_shop'] = (int)$this->id_shop; $fields['id_shop'] = (int)$this->id_shop;
return $fields; return $fields;
} }
public static function getFavoriteProducts($id_customer, $id_lang, Shop $shop = null) public static function getFavoriteProducts($id_customer, $id_lang, Shop $shop = null)
{ {
if (!$shop) if (!$shop)
@@ -74,42 +74,42 @@ class FavoriteProduct extends ObjectModel
return Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS(' 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 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 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 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 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` 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 WHERE p.`active` = 1
'.$shop->sqlRestriction(false, 'fp')); '.$shop->sqlRestriction(false, 'fp'));
} }
public static function getFavoriteProduct($id_customer, $id_product, Shop $shop = null) public static function getFavoriteProduct($id_customer, $id_product, Shop $shop = null)
{ {
if (!$shop) if (!$shop)
$shop = Context::getContext()->shop; $shop = Context::getContext()->shop;
$id_favorite_product = Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue(' $id_favorite_product = Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue('
SELECT `id_favorite_product` SELECT `id_favorite_product`
FROM `'._DB_PREFIX_.'favorite_product` FROM `'._DB_PREFIX_.'favorite_product`
WHERE `id_customer` = '.(int)($id_customer).' WHERE `id_customer` = '.(int)($id_customer).'
AND `id_product` = '.(int)($id_product).' AND `id_product` = '.(int)($id_product).'
AND `id_shop` = '.(int)($shop->getID())); AND `id_shop` = '.(int)($shop->getID()));
if ($id_favorite_product) if ($id_favorite_product)
return new FavoriteProduct($id_favorite_product); return new FavoriteProduct($id_favorite_product);
return null; return null;
} }
public static function isCustomerFavoriteProduct($id_customer, $id_product, Shop $shop = null) public static function isCustomerFavoriteProduct($id_customer, $id_product, Shop $shop = null)
{ {
if (!$shop) if (!$shop)
$shop = Context::getContext()->shop; $shop = Context::getContext()->shop;
return (bool)Db::getInstance()->getValue(' return (bool)Db::getInstance()->getValue('
SELECT COUNT(*) SELECT COUNT(*)
FROM `'._DB_PREFIX_.'favorite_product` FROM `'._DB_PREFIX_.'favorite_product`
WHERE `id_customer` = '.(int)($id_customer).' WHERE `id_customer` = '.(int)($id_customer).'
AND `id_product` = '.(int)($id_product).' AND `id_product` = '.(int)($id_product).'
AND `id_shop` = '.(int)($shop->getID())); AND `id_shop` = '.(int)($shop->getID()));
} }
} }
@@ -27,7 +27,7 @@
<script type="text/javascript"> <script type="text/javascript">
{literal} {literal}
$('document').ready(function(){ $('document').ready(function(){
$('#add_favorites_btn').click(function(){ $('#favoriteproducts_block_extra').click(function(){
$.ajax({ $.ajax({
{/literal}url: "{$module_dir}favoriteproducts-ajax.php",{literal} {/literal}url: "{$module_dir}favoriteproducts-ajax.php",{literal}
post: "POST", post: "POST",
@@ -35,8 +35,8 @@ $('document').ready(function(){
success: function(result){ success: function(result){
if (result == '0') if (result == '0')
{ {
$('#add_favorites_btn').fadeOut("normal", function() { $('#favoriteproducts_block_extra').fadeOut("normal", function() {
$('#add_favorites_btn').remove(); $('#favoriteproducts_block_extra').remove();
}); });
} }
} }
@@ -50,4 +50,8 @@ $('document').ready(function(){
<li id="favoriteproducts_block_extra"> <li id="favoriteproducts_block_extra">
{l s='Add this product to my favorites' mod='favoriteproducts'} {l s='Add this product to my favorites' mod='favoriteproducts'}
</li> </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} {/if}
@@ -44,4 +44,5 @@
#usefull_link_block li#favoriteproducts_block_extra { #usefull_link_block li#favoriteproducts_block_extra {
padding-left:20px; padding-left:20px;
background:url(img/add_favorite.gif) no-repeat 0 0; background:url(img/add_favorite.gif) no-repeat 0 0;
cursor: pointer;
} }
+15 -16
View File
@@ -1,6 +1,6 @@
<?php <?php
/* /*
* 2007-2011 PrestaShop * 2007-2011 PrestaShop
* *
* NOTICE OF LICENSE * NOTICE OF LICENSE
* *
@@ -27,7 +27,7 @@
if (!defined('_CAN_LOAD_FILES_')) if (!defined('_CAN_LOAD_FILES_'))
exit; exit;
class FavoriteProducts extends Module class FavoriteProducts extends Module
{ {
public function __construct() public function __construct()
@@ -46,12 +46,12 @@ class FavoriteProducts extends Module
public function install() public function install()
{ {
if (!parent::install() if (!parent::install()
OR !$this->registerHook('myAccountBlock') OR !$this->registerHook('myAccountBlock')
OR !$this->registerHook('extraLeft') OR !$this->registerHook('extraLeft')
OR !$this->registerHook('header')) OR !$this->registerHook('header'))
return false; return false;
if (!Db::getInstance()->Execute(' if (!Db::getInstance()->Execute('
CREATE TABLE `'._DB_PREFIX_.'favorite_product` ( CREATE TABLE `'._DB_PREFIX_.'favorite_product` (
`id_favorite_product` int(10) unsigned NOT NULL auto_increment, `id_favorite_product` int(10) unsigned NOT NULL auto_increment,
@@ -63,44 +63,43 @@ class FavoriteProducts extends Module
PRIMARY KEY (`id_favorite_product`)) PRIMARY KEY (`id_favorite_product`))
ENGINE='._MYSQL_ENGINE_.' DEFAULT CHARSET=utf8')) ENGINE='._MYSQL_ENGINE_.' DEFAULT CHARSET=utf8'))
return false; return false;
return true; return true;
} }
public function uninstall() public function uninstall()
{ {
if (!parent::uninstall() OR !Db::getInstance()->Execute('DROP TABLE `'._DB_PREFIX_.'favorite_product`')) if (!parent::uninstall() OR !Db::getInstance()->Execute('DROP TABLE `'._DB_PREFIX_.'favorite_product`'))
return false; return false;
return true; return true;
} }
public function hookCustomerAccount($params) public function hookCustomerAccount($params)
{ {
include_once(dirname(__FILE__).'/FavoriteProduct.php'); include_once(dirname(__FILE__).'/FavoriteProduct.php');
$favoriteProducts = FavoriteProduct::getFavoriteProducts($this->context->customer->id, $this->context->language->id); $favoriteProducts = FavoriteProduct::getFavoriteProducts($this->context->customer->id, $this->context->language->id);
$this->context->smarty->assign(array('favorite_products' => $favoriteProducts)); $this->context->smarty->assign(array('favorite_products' => $favoriteProducts));
return $this->display(__FILE__, 'my-account.tpl'); return $this->display(__FILE__, 'my-account.tpl');
} }
public function hookMyAccountBlock($params) public function hookMyAccountBlock($params)
{ {
return $this->hookCustomerAccount($params); return $this->hookCustomerAccount($params);
} }
public function hookExtraLeft($params) public function hookExtraLeft($params)
{ {
include_once(dirname(__FILE__).'/FavoriteProduct.php'); include_once(dirname(__FILE__).'/FavoriteProduct.php');
$this->context->smarty->assign(array( $this->context->smarty->assign(array(
'isCustomerFavoriteProduct' => (FavoriteProduct::isCustomerFavoriteProduct($this->context->customer->id, Tools::getValue('id_product')) ? 1 : 0), 'isCustomerFavoriteProduct' => (FavoriteProduct::isCustomerFavoriteProduct($this->context->customer->id, Tools::getValue('id_product')) ? 1 : 0),
'isLogged' => (int)$this->context->customer->logged)); 'isLogged' => (int)$this->context->customer->logged));
return $this->display(__FILE__, 'favoriteproducts-extra.tpl'); return $this->display(__FILE__, 'favoriteproducts-extra.tpl');
} }
public function hookHeader($params) public function hookHeader($params)
{ {
$this->context->controller->addCSS($this->_path.'favoriteproducts.css', 'all'); $this->context->controller->addCSS($this->_path.'favoriteproducts.css', 'all');
+4 -4
View File
@@ -96,7 +96,7 @@ class HomeSlide extends ObjectModel
$id_shop = $context->shop->getID(); $id_shop = $context->shop->getID();
$res = parent::add(); $res = parent::add();
$res &= Db::getInstance()->Execute(' $res &= Db::getInstance(_PS_USE_SQL_SLAVE_)->Execute('
INSERT INTO `'._DB_PREFIX_.'homeslider` (`id_shop`, `id_slide`) INSERT INTO `'._DB_PREFIX_.'homeslider` (`id_shop`, `id_slide`)
VALUES('.(int)$id_shop.', '.(int)$this->id.')' VALUES('.(int)$id_shop.', '.(int)$this->id.')'
); );
@@ -115,7 +115,7 @@ class HomeSlide extends ObjectModel
} }
$res &= $this->reOrderPositions(); $res &= $this->reOrderPositions();
$res &= Db::getInstance()->Execute(' $res &= Db::getInstance(_PS_USE_SQL_SLAVE_)->Execute('
DELETE FROM `'._DB_PREFIX_.'homeslider` DELETE FROM `'._DB_PREFIX_.'homeslider`
WHERE `id_slide` = '.(int)$this->id WHERE `id_slide` = '.(int)$this->id
); );
@@ -130,7 +130,7 @@ class HomeSlide extends ObjectModel
$context = Context::getContext(); $context = Context::getContext();
$id_shop = $context->shop->getID(); $id_shop = $context->shop->getID();
$max = Db::getInstance()->ExecuteS(' $max = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS('
SELECT MAX(hss.`position`) as position SELECT MAX(hss.`position`) as position
FROM `'._DB_PREFIX_.'homeslider_slides` hss, `'._DB_PREFIX_.'homeslider` hs FROM `'._DB_PREFIX_.'homeslider_slides` hss, `'._DB_PREFIX_.'homeslider` hs
WHERE hss.`id_slide` = hs.`id_slide` AND hs.`id_shop` = '.(int)$id_shop WHERE hss.`id_slide` = hs.`id_slide` AND hs.`id_shop` = '.(int)$id_shop
@@ -139,7 +139,7 @@ class HomeSlide extends ObjectModel
if ((int)$max == (int)$id_slide) if ((int)$max == (int)$id_slide)
return true; return true;
$rows = Db::getInstance()->ExecuteS(' $rows = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS('
SELECT hss.`position` as position, hss.`id_slide` as id_slide SELECT hss.`position` as position, hss.`id_slide` as id_slide
FROM `'._DB_PREFIX_.'homeslider_slides` hss, `'._DB_PREFIX_.'homeslider` hs FROM `'._DB_PREFIX_.'homeslider_slides` hss, `'._DB_PREFIX_.'homeslider` hs
WHERE hss.`id_slide` = hs.`id_slide` AND hs.`id_shop` = '.(int)$id_shop.' AND hss.`position` > '.(int)$this->position WHERE hss.`id_slide` = hs.`id_slide` AND hs.`id_shop` = '.(int)$id_shop.' AND hss.`position` > '.(int)$this->position
+7 -7
View File
@@ -85,7 +85,7 @@ class HomeSlider extends Module
protected function createTables() protected function createTables()
{ {
/* Slides */ /* Slides */
$res = Db::getInstance()->Execute(' $res = Db::getInstance(_PS_USE_SQL_SLAVE_)->Execute('
CREATE TABLE IF NOT EXISTS `'._DB_PREFIX_.'homeslider` ( CREATE TABLE IF NOT EXISTS `'._DB_PREFIX_.'homeslider` (
`id_slide` int(10) unsigned NOT NULL AUTO_INCREMENT, `id_slide` int(10) unsigned NOT NULL AUTO_INCREMENT,
`id_shop` int(10) unsigned NOT NULL, `id_shop` int(10) unsigned NOT NULL,
@@ -94,7 +94,7 @@ class HomeSlider extends Module
'); ');
/* Slides configuration */ /* Slides configuration */
$res &= Db::getInstance()->Execute(' $res &= Db::getInstance(_PS_USE_SQL_SLAVE_)->Execute('
CREATE TABLE IF NOT EXISTS `'._DB_PREFIX_.'homeslider_slides` ( CREATE TABLE IF NOT EXISTS `'._DB_PREFIX_.'homeslider_slides` (
`id_slide` int(10) unsigned NOT NULL AUTO_INCREMENT, `id_slide` int(10) unsigned NOT NULL AUTO_INCREMENT,
`position` int(10) unsigned NOT NULL DEFAULT \'0\', `position` int(10) unsigned NOT NULL DEFAULT \'0\',
@@ -104,7 +104,7 @@ class HomeSlider extends Module
'); ');
/* Slides lang configuration */ /* Slides lang configuration */
$res &= Db::getInstance()->Execute(' $res &= Db::getInstance(_PS_USE_SQL_SLAVE_)->Execute('
CREATE TABLE IF NOT EXISTS `'._DB_PREFIX_.'homeslider_slides_lang` ( CREATE TABLE IF NOT EXISTS `'._DB_PREFIX_.'homeslider_slides_lang` (
`id_slide` int(10) unsigned NOT NULL, `id_slide` int(10) unsigned NOT NULL,
`id_lang` int(10) unsigned NOT NULL, `id_lang` int(10) unsigned NOT NULL,
@@ -128,7 +128,7 @@ class HomeSlider extends Module
$toDel = new HomeSlide($slide['id_slide']); $toDel = new HomeSlide($slide['id_slide']);
$toDel->delete(); $toDel->delete();
} }
return Db::getInstance()->Execute(' return Db::getInstance(_PS_USE_SQL_SLAVE_)->Execute('
DROP TABLE `'._DB_PREFIX_.'homeslider`, `'._DB_PREFIX_.'homeslider_slides`, `'._DB_PREFIX_.'homeslider_slides_lang`; DROP TABLE `'._DB_PREFIX_.'homeslider`, `'._DB_PREFIX_.'homeslider_slides`, `'._DB_PREFIX_.'homeslider_slides_lang`;
'); ');
} }
@@ -612,7 +612,7 @@ class HomeSlider extends Module
public function getNextPosition() public function getNextPosition()
{ {
$row = Db::getInstance()->getRow(' $row = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow('
SELECT MAX(hss.`position`) AS `next_position` SELECT MAX(hss.`position`) AS `next_position`
FROM `'._DB_PREFIX_.'homeslider_slides` hss, `'._DB_PREFIX_.'homeslider` hs FROM `'._DB_PREFIX_.'homeslider_slides` hss, `'._DB_PREFIX_.'homeslider` hs
WHERE hss.`id_slide` = hs.`id_slide` AND hs.`id_shop` = '.(int)$this->context->shop->getId() WHERE hss.`id_slide` = hs.`id_slide` AND hs.`id_shop` = '.(int)$this->context->shop->getId()
@@ -627,7 +627,7 @@ class HomeSlider extends Module
$idShop = $this->context->shop->getID(); $idShop = $this->context->shop->getID();
$idLang = $this->context->language->id; $idLang = $this->context->language->id;
return Db::getInstance()->ExecuteS(' return Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS('
SELECT hs.`id_slide` AS id_slide, hssl.`image` as image, hss.`position` AS position, hss.`active` as active, hssl.`title` as title, hssl.`url` as url, hssl.`legend` as legend SELECT hs.`id_slide` AS id_slide, hssl.`image` as image, hss.`position` AS position, hss.`active` as active, hssl.`title` as title, hssl.`url` as url, hssl.`legend` as legend
FROM `'._DB_PREFIX_.'homeslider` hs, `'._DB_PREFIX_.'homeslider_slides` hss, `'._DB_PREFIX_.'homeslider_slides_lang` hssl FROM `'._DB_PREFIX_.'homeslider` hs, `'._DB_PREFIX_.'homeslider_slides` hss, `'._DB_PREFIX_.'homeslider_slides_lang` hssl
WHERE hs.`id_shop` = '.(int)$idShop. ((int)$idShop != 0 ? ' OR hs.`id_shop` = 0' : '').' AND hs.`id_slide` = hss.`id_slide` AND hss.`id_slide` = hssl.`id_slide` AND hs.`id_slide` = hssl.`id_slide` WHERE hs.`id_shop` = '.(int)$idShop. ((int)$idShop != 0 ? ' OR hs.`id_shop` = 0' : '').' AND hs.`id_slide` = hss.`id_slide` AND hss.`id_slide` = hssl.`id_slide` AND hs.`id_slide` = hssl.`id_slide`
@@ -649,7 +649,7 @@ class HomeSlider extends Module
$req = 'SELECT hs.`id_slide` $req = 'SELECT hs.`id_slide`
FROM `'._DB_PREFIX_.'homeslider` hs FROM `'._DB_PREFIX_.'homeslider` hs
WHERE hs.`id_slide` = '.(int)$id_slide; WHERE hs.`id_slide` = '.(int)$id_slide;
$row = Db::getInstance()->getRow($req); $row = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow($req);
return ($row); return ($row);
} }
} }