From 405e8181bc49492727328a5d68a8a112ead5dc14 Mon Sep 17 00:00:00 2001 From: mDeflotte Date: Fri, 16 Mar 2012 15:35:52 +0000 Subject: [PATCH] // Add multishop for the Blockwishlist git-svn-id: http://dev.prestashop.com/svn/v1/branches/1.5.x@14217 b9a71923-0436-4b27-9f14-aed3839534dd --- admin-dev/themes/default/template/header.tpl | 322 +++++++++--------- .../php/module_blockwishlist_multishop.php | 42 +++ install-dev/upgrade/sql/1.5.0.10.sql | 1 + modules/blockwishlist/WishList.php | 44 ++- modules/blockwishlist/blockwishlist.php | 4 +- modules/blockwishlist/cart.php | 3 + .../controllers/front/mywishlist.php | 2 + modules/blockwishlist/install.sql | 2 + 8 files changed, 251 insertions(+), 169 deletions(-) create mode 100644 install-dev/upgrade/php/module_blockwishlist_multishop.php create mode 100644 install-dev/upgrade/sql/1.5.0.10.sql diff --git a/admin-dev/themes/default/template/header.tpl b/admin-dev/themes/default/template/header.tpl index 9c9933762..1e57a2fe6 100644 --- a/admin-dev/themes/default/template/header.tpl +++ b/admin-dev/themes/default/template/header.tpl @@ -26,71 +26,71 @@ - - - {$meta_title} - PrestaShop™ + + + {$meta_title} - PrestaShop™ {if $display_header} - + var helpboxes = {$help_box}; + var roundMode = {$round_mode}; + {if isset($shop_context)} + {if $shop_context == Shop::CONTEXT_ALL} + var youEditFieldFor = "{l s='A modification of this field will be applied for all shops' slashes=1 }"; + {elseif $shop_context == Shop::CONTEXT_GROUP} + var youEditFieldFor = "{l s='A modification of this field will be applied for all shops of group ' slashes=1 }{$shop_name}"; + {else} + var youEditFieldFor = "{l s='A modification of this field will be applied for the shop ' slashes=1 }{$shop_name}"; + {/if} + {else} + var youEditFieldFor = ''; + {/if} + {* Notifications vars *} + var autorefresh_notifications = '{$autorefresh_notifications}'; + var new_order_msg = '{l s='A new order has been made on your shop.' slashes=1 }'; + var order_number_msg = '{l s='Order number : ' slashes=1 }'; + var total_msg = '{l s='Total : ' slashes=1 }'; + var from_msg = '{l s='From : ' slashes=1 }'; + var see_order_msg = '{l s='Click here to see that order' slashes=1 }'; + var new_customer_msg = '{l s='A new customer registered on your shop.' slashes=1}'; + var customer_name_msg = '{l s='Customer name : ' slashes=1 }'; + var see_customer_msg = '{l s='Click here to see that customer' slashes=1 }'; + var new_msg = '{l s='A new message posted on your shop.' slashes=1 }'; + var excerpt_msg = '{l s='Excerpt : ' slashes=1 }'; + var see_msg = '{l s='Click here to see that message' slashes=1 }'; + var token_admin_orders = '{getAdminToken tab='AdminOrders' slashes=1 }'; + var token_admin_customers = '{getAdminToken tab='AdminCustomers' slashes=1 }'; + var token_admin_customer_threads = '{getAdminToken tab='AdminCustomerThreads' slashes=1 }'; + {/if} {if isset($css_files)} - {foreach from=$css_files key=css_uri item=media} - - {/foreach} + {foreach from=$css_files key=css_uri item=media} + + {/foreach} {/if} {if isset($js_files)} - {foreach from=$js_files item=js_uri} - - {/foreach} + {foreach from=$js_files item=js_uri} + + {/foreach} {/if} - + {if $display_header} - {hook h="displayBackOfficeHeader"} + {hook h="displayBackOfficeHeader"} {/if} - - + + {if $display_header} @@ -99,131 +99,131 @@
0}style="margin:auto;width:{$bo_width}px"{/if}>
{* begin HEADER *} - {* end header *} {/if} -
-
- {if $display_header && $install_dir_exists} -
- {l s='For security reasons, you must also:'} {l s='delete the /install folder'} -
- {/if} +
+
+ {if $display_header && $install_dir_exists} +
+ {l s='For security reasons, you must also:'} {l s='delete the /install folder'} +
+ {/if} - {if $display_header && $is_multishop && ($multishop_context & Shop::CONTEXT_GROUP || $multishop_context & Shop::CONTEXT_SHOP)} -
- {l s='Multishop configuration for'} - {$shop_list} -
- {/if} + {if $display_header && $is_multishop && ($multishop_context & Shop::CONTEXT_GROUP || $multishop_context & Shop::CONTEXT_SHOP)} +
+ {l s='Multishop configuration for'} + {$shop_list} +
+ {/if} diff --git a/install-dev/upgrade/php/module_blockwishlist_multishop.php b/install-dev/upgrade/php/module_blockwishlist_multishop.php new file mode 100644 index 000000000..5d231696d --- /dev/null +++ b/install-dev/upgrade/php/module_blockwishlist_multishop.php @@ -0,0 +1,42 @@ + +* @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; +} + + diff --git a/install-dev/upgrade/sql/1.5.0.10.sql b/install-dev/upgrade/sql/1.5.0.10.sql new file mode 100644 index 000000000..21dd5e8b4 --- /dev/null +++ b/install-dev/upgrade/sql/1.5.0.10.sql @@ -0,0 +1 @@ +/* PHP:module_blockwishlist_multishop(); */; diff --git a/modules/blockwishlist/WishList.php b/modules/blockwishlist/WishList.php index 7e419f036..a05eeb726 100644 --- a/modules/blockwishlist/WishList.php +++ b/modules/blockwishlist/WishList.php @@ -48,6 +48,11 @@ class WishList extends ObjectModel /** @var string Object last modification date */ 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 */ @@ -60,6 +65,8 @@ class WishList extends ObjectModel 'name' => array('type' => self::TYPE_STRING, 'validate' => 'isMessage', 'required' => true), 'date_add' => 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) { + 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(); return Db::getInstance()->getValue(' SELECT COUNT(*) AS total FROM `'._DB_PREFIX_.'wishlist` 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) { + 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)) die (Tools::displayError()); return (Db::getInstance()->executeS(' SELECT w.`id_wishlist`, w.`name`, w.`token`, w.`date_add`, w.`date_upd`, w.`counter` FROM `'._DB_PREFIX_.'wishlist` w WHERE `id_customer` = '.(int)($id_customer).' + '.$shop_restriction.' ORDER BY w.`name` ASC')); } @@ -178,7 +201,7 @@ class WishList extends ObjectModel WHERE (wp.id_wishlist='.(int)($id_wishlist).' AND o.id_cart IS NULL) HAVING timecart >= 3600*6'); - if(isset($old_carts) AND $old_carts != false) + if (isset($old_carts) AND $old_carts != false) foreach ($old_carts AS $old_cart) Db::getInstance()->execute(' DELETE FROM `'._DB_PREFIX_.'cart_product` @@ -202,9 +225,9 @@ class WishList extends ObjectModel WHERE wp.id_wishlist='.(int)($id_wishlist) ); - if(isset($res) AND $res != false) + if (isset($res) AND $res != false) foreach ($res AS $refresh) - if($refresh['wish_quantity'] > $refresh['cart_quantity']) + if ($refresh['wish_quantity'] > $refresh['cart_quantity']) { Db::getInstance()->execute(' UPDATE `'._DB_PREFIX_.'wishlist_product` @@ -217,7 +240,7 @@ class WishList extends ObjectModel WHERE id_wishlist_product='.(int)($refresh['id_wishlist_product']).' AND id_cart='.(int)($refresh['id_cart']) ); } - if(isset($freshwish) AND $freshwish != false) + if (isset($freshwish) AND $freshwish != false) foreach ($freshwish AS $prodcustomer) { Db::getInstance()->execute(' @@ -258,7 +281,8 @@ class WishList extends ObjectModel AND pl.`id_lang` = '.(int)($id_lang).' AND wp.`id_wishlist` = '.(int)($id_wishlist). (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)) return array(); for ($i = 0; $i < sizeof($products); ++$i) @@ -296,6 +320,13 @@ class WishList extends ObjectModel */ 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)) die (Tools::displayError()); return (Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS(' @@ -303,6 +334,7 @@ class WishList extends ObjectModel FROM `'._DB_PREFIX_.'wishlist_product` wp INNER JOIN `'._DB_PREFIX_.'wishlist` w ON (w.`id_wishlist` = wp.`id_wishlist`) WHERE w.`id_customer` = '.(int)($id_customer).' + '.$shop_restriction.' GROUP BY w.`id_wishlist` ORDER BY w.`name` ASC')); } diff --git a/modules/blockwishlist/blockwishlist.php b/modules/blockwishlist/blockwishlist.php index 7be46c962..a0e8e8206 100644 --- a/modules/blockwishlist/blockwishlist.php +++ b/modules/blockwishlist/blockwishlist.php @@ -32,8 +32,8 @@ class BlockWishList extends Module { const INSTALL_SQL_FILE = 'install.sql'; - private $_html = ''; - private $_postErrors = array(); + private $_html = ''; + private $_postErrors = array(); public function __construct() { diff --git a/modules/blockwishlist/cart.php b/modules/blockwishlist/cart.php index 402a20e81..9c00600b8 100644 --- a/modules/blockwishlist/cart.php +++ b/modules/blockwishlist/cart.php @@ -53,6 +53,9 @@ if ($context->customer->isLogged()) if(!isset($context->cookie->id_wishlist) OR $context->cookie->id_wishlist == '') { $wishlist = new WishList(); + $wishlist->id_shop = $context->shop->id; + $wishlist->id_group_shop = $context->shop->id_group_shop; + $modWishlist = new BlockWishList(); $wishlist->name = $modWishlist->default_wishlist_name; $wishlist->id_customer = (int)($context->customer->id); diff --git a/modules/blockwishlist/controllers/front/mywishlist.php b/modules/blockwishlist/controllers/front/mywishlist.php index 052021bc4..f51e5d6ef 100644 --- a/modules/blockwishlist/controllers/front/mywishlist.php +++ b/modules/blockwishlist/controllers/front/mywishlist.php @@ -81,6 +81,8 @@ class BlockWishListMyWishListModuleFrontController extends ModuleFrontController if(!sizeof($errors)) { $wishlist = new WishList(); + $wishlist->id_shop = $this->context->shop->id; + $wishlist->id_group_shop = $this->context->shop->id_group_shop; $wishlist->name = $name; $wishlist->id_customer = (int)$this->context->customer->id; list($us, $s) = explode(' ', microtime()); diff --git a/modules/blockwishlist/install.sql b/modules/blockwishlist/install.sql index ba9407d91..8d0fece0e 100644 --- a/modules/blockwishlist/install.sql +++ b/modules/blockwishlist/install.sql @@ -4,6 +4,8 @@ CREATE TABLE IF NOT EXISTS `PREFIX_wishlist` ( `token` varchar(64) character set utf8 NOT NULL, `name` varchar(64) character set utf8 NOT 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_upd` datetime NOT NULL, PRIMARY KEY (`id_wishlist`)