// Add multishop for the Blockwishlist

This commit is contained in:
mDeflotte committed 2012-03-16 15:35:52 +00:00
1 parent 03cb569a17
commit 2e28cf14a3
6 files changed
+84 -2

No files matched your search

@@ -0,0 +1,42 @@
<?php
/*
* 2007-2012 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/osl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2012 PrestaShop SA
* @version Release: $Revision$
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
function module_blockwishlist_multishop()
{
$id_module = Db::getInstance()->getValue('SELECT id_module FROM '._DB_PREFIX_.'module where name="blockwishlist"');
if ($id_module)
{
$res = Db::getInstance()->execute('ALTER TABLE `'._DB_PREFIX_.'wishlist`
ADD `id_shop` INTEGER NOT NULL default \'1\' AFTER `counter`,
ADD `id_group_shop` INTEGER NOT NULL default \'1\' AFTER `id_shop`');
return $res;
}
return true;
}
+1
View File
@@ -0,0 +1 @@
/* PHP:module_blockwishlist_multishop(); */;
+34 -2
View File
@@ -48,6 +48,11 @@ class WishList extends ObjectModel
/** @var string Object last modification date */ /** @var string Object last modification date */
public $date_upd; public $date_upd;
/** @var string Object last modification date */
public $id_shop;
/** @var string Object last modification date */
public $id_group_shop;
/** /**
* @see ObjectModel::$definition * @see ObjectModel::$definition
*/ */
@@ -60,6 +65,8 @@ class WishList extends ObjectModel
'name' => array('type' => self::TYPE_STRING, 'validate' => 'isMessage', 'required' => true), 'name' => array('type' => self::TYPE_STRING, 'validate' => 'isMessage', 'required' => true),
'date_add' => array('type' => self::TYPE_DATE, 'validate' => 'isDate'), 'date_add' => array('type' => self::TYPE_DATE, 'validate' => 'isDate'),
'date_upd' => array('type' => self::TYPE_DATE, 'validate' => 'isDate'), 'date_upd' => array('type' => self::TYPE_DATE, 'validate' => 'isDate'),
'id_shop' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId'),
'id_group_shop' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId'),
) )
); );
@@ -100,12 +107,20 @@ class WishList extends ObjectModel
public static function isExistsByNameForUser($name) public static function isExistsByNameForUser($name)
{ {
if (Shop::getContextShopID())
$shop_restriction = 'AND id_shop = '.(int)Shop::getContextShopID();
elseif (Shop::getContextGroupShopID())
$shop_restriction = 'AND id_group_shop = '.(int)Shop::getContextGroupShopID();
else
$shop_restriction = '';
$context = Context::getContext(); $context = Context::getContext();
return Db::getInstance()->getValue(' return Db::getInstance()->getValue('
SELECT COUNT(*) AS total SELECT COUNT(*) AS total
FROM `'._DB_PREFIX_.'wishlist` FROM `'._DB_PREFIX_.'wishlist`
WHERE `name` = \''.pSQL($name).'\' WHERE `name` = \''.pSQL($name).'\'
AND `id_customer` = '.(int)$context->customer->id AND `id_customer` = '.(int)$context->customer->id.'
'.$shop_restriction
); );
} }
@@ -157,12 +172,20 @@ class WishList extends ObjectModel
*/ */
public static function getByIdCustomer($id_customer) public static function getByIdCustomer($id_customer)
{ {
if (Shop::getContextShopID())
$shop_restriction = 'AND id_shop = '.(int)Shop::getContextShopID();
elseif (Shop::getContextGroupShopID())
$shop_restriction = 'AND id_group_shop = '.(int)Shop::getContextGroupShopID();
else
$shop_restriction = '';
if (!Validate::isUnsignedId($id_customer)) if (!Validate::isUnsignedId($id_customer))
die (Tools::displayError()); die (Tools::displayError());
return (Db::getInstance()->executeS(' return (Db::getInstance()->executeS('
SELECT w.`id_wishlist`, w.`name`, w.`token`, w.`date_add`, w.`date_upd`, w.`counter` SELECT w.`id_wishlist`, w.`name`, w.`token`, w.`date_add`, w.`date_upd`, w.`counter`
FROM `'._DB_PREFIX_.'wishlist` w FROM `'._DB_PREFIX_.'wishlist` w
WHERE `id_customer` = '.(int)($id_customer).' WHERE `id_customer` = '.(int)($id_customer).'
'.$shop_restriction.'
ORDER BY w.`name` ASC')); ORDER BY w.`name` ASC'));
} }
@@ -258,7 +281,8 @@ class WishList extends ObjectModel
AND pl.`id_lang` = '.(int)($id_lang).' AND pl.`id_lang` = '.(int)($id_lang).'
AND wp.`id_wishlist` = '.(int)($id_wishlist). AND wp.`id_wishlist` = '.(int)($id_wishlist).
(empty($id_product) === false ? ' AND wp.`id_product` = '.(int)($id_product) : ''). (empty($id_product) === false ? ' AND wp.`id_product` = '.(int)($id_product) : '').
($quantity == true ? ' AND wp.`quantity` != 0': '')); ($quantity == true ? ' AND wp.`quantity` != 0': '').'
GROUP BY p.id_product');
if (empty($products) === true OR !sizeof($products)) if (empty($products) === true OR !sizeof($products))
return array(); return array();
for ($i = 0; $i < sizeof($products); ++$i) for ($i = 0; $i < sizeof($products); ++$i)
@@ -296,6 +320,13 @@ class WishList extends ObjectModel
*/ */
public static function getInfosByIdCustomer($id_customer) public static function getInfosByIdCustomer($id_customer)
{ {
if (Shop::getContextShopID())
$shop_restriction = 'AND id_shop = '.(int)Shop::getContextShopID();
elseif (Shop::getContextGroupShopID())
$shop_restriction = 'AND id_group_shop = '.(int)Shop::getContextGroupShopID();
else
$shop_restriction = '';
if (!Validate::isUnsignedId($id_customer)) if (!Validate::isUnsignedId($id_customer))
die (Tools::displayError()); die (Tools::displayError());
return (Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS(' return (Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('
@@ -303,6 +334,7 @@ class WishList extends ObjectModel
FROM `'._DB_PREFIX_.'wishlist_product` wp FROM `'._DB_PREFIX_.'wishlist_product` wp
INNER JOIN `'._DB_PREFIX_.'wishlist` w ON (w.`id_wishlist` = wp.`id_wishlist`) INNER JOIN `'._DB_PREFIX_.'wishlist` w ON (w.`id_wishlist` = wp.`id_wishlist`)
WHERE w.`id_customer` = '.(int)($id_customer).' WHERE w.`id_customer` = '.(int)($id_customer).'
'.$shop_restriction.'
GROUP BY w.`id_wishlist` GROUP BY w.`id_wishlist`
ORDER BY w.`name` ASC')); ORDER BY w.`name` ASC'));
} }
+3
View File
@@ -53,6 +53,9 @@ if ($context->customer->isLogged())
if(!isset($context->cookie->id_wishlist) OR $context->cookie->id_wishlist == '') if(!isset($context->cookie->id_wishlist) OR $context->cookie->id_wishlist == '')
{ {
$wishlist = new WishList(); $wishlist = new WishList();
$wishlist->id_shop = $context->shop->id;
$wishlist->id_group_shop = $context->shop->id_group_shop;
$modWishlist = new BlockWishList(); $modWishlist = new BlockWishList();
$wishlist->name = $modWishlist->default_wishlist_name; $wishlist->name = $modWishlist->default_wishlist_name;
$wishlist->id_customer = (int)($context->customer->id); $wishlist->id_customer = (int)($context->customer->id);
@@ -81,6 +81,8 @@ class BlockWishListMyWishListModuleFrontController extends ModuleFrontController
if(!sizeof($errors)) if(!sizeof($errors))
{ {
$wishlist = new WishList(); $wishlist = new WishList();
$wishlist->id_shop = $this->context->shop->id;
$wishlist->id_group_shop = $this->context->shop->id_group_shop;
$wishlist->name = $name; $wishlist->name = $name;
$wishlist->id_customer = (int)$this->context->customer->id; $wishlist->id_customer = (int)$this->context->customer->id;
list($us, $s) = explode(' ', microtime()); list($us, $s) = explode(' ', microtime());
+2
View File
@@ -4,6 +4,8 @@ CREATE TABLE IF NOT EXISTS `PREFIX_wishlist` (
`token` varchar(64) character set utf8 NOT NULL, `token` varchar(64) character set utf8 NOT NULL,
`name` varchar(64) character set utf8 NOT NULL, `name` varchar(64) character set utf8 NOT NULL,
`counter` int(10) unsigned NULL, `counter` int(10) unsigned NULL,
`id_shop` int(10) unsigned default 1,
`id_group_shop` int(10) unsigned default 1,
`date_add` datetime NOT NULL, `date_add` datetime NOT NULL,
`date_upd` datetime NOT NULL, `date_upd` datetime NOT NULL,
PRIMARY KEY (`id_wishlist`) PRIMARY KEY (`id_wishlist`)