From be1cd70887e86da1e752531cfb9bd5ebe4b95fee Mon Sep 17 00:00:00 2001 From: rGaillard Date: Fri, 25 May 2012 17:12:55 +0000 Subject: [PATCH] [-] BO: Fix multishop employee restriction on cart and catalog price rules PSCFV-2505 --- classes/CartRule.php | 20 ++++++++++++++----- classes/shop/Shop.php | 4 ++-- .../AdminSpecificPriceRuleController.php | 6 +++++- 3 files changed, 22 insertions(+), 8 deletions(-) diff --git a/classes/CartRule.php b/classes/CartRule.php index ec2f684d9..4dbac9b32 100644 --- a/classes/CartRule.php +++ b/classes/CartRule.php @@ -252,7 +252,7 @@ class CartRuleCore extends ObjectModel $cart_rule['value'] = 0; $cart_rule['minimal'] = $cart_rule['minimum_amount']; $cart_rule['cumulable'] = !$cart_rule['cart_rule_restriction']; - if ($cart_rule['free_shipping']) + if ($cart_rule['free_shipping'] == 0) $cart_rule['id_discount_type'] = Discount::FREE_SHIPPING; elseif ($cart_rule['reduction_percent'] > 0) { @@ -936,6 +936,14 @@ class CartRuleCore extends ObjectModel if (!in_array($type, array('country', 'carrier', 'group', 'cart_rule', 'shop'))) return false; + $shop_list = ''; + if ($type == 'shop') + { + $shop_list = ' AND t.id_shop IN ('; + $shops = Context::getContext()->employee->getAssociatedShops(); + $shop_list .= implode(array_map('intval', $shops), ',').')'; + } + if (!Validate::isLoadedObject($this) OR $this->{$type.'_restriction'} == 0) { $array['selected'] = Db::getInstance()->executeS(' @@ -945,8 +953,9 @@ class CartRuleCore extends ObjectModel WHERE 1 '.($active_only ? 'AND t.active = 1' : '').' '.(in_array($type, array('carrier', 'shop')) ? ' AND t.deleted = 0' : '').' - '.($type == 'cart_rule' ? 'AND t.id_cart_rule != '.(int)$this->id : '').' - ORDER BY name ASC'); + '.($type == 'cart_rule' ? 'AND t.id_cart_rule != '.(int)$this->id : ''). + $shop_list. + ' ORDER BY name ASC'); } else { @@ -959,8 +968,9 @@ class CartRuleCore extends ObjectModel FROM `'._DB_PREFIX_.$type.'` t '.($i18n ? 'LEFT JOIN `'._DB_PREFIX_.$type.'_lang` tl ON (t.id_'.$type.' = tl.id_'.$type.' AND tl.id_lang = '.(int)Context::getContext()->language->id.')' : '').' LEFT JOIN (SELECT id_'.$type.' FROM `'._DB_PREFIX_.'cart_rule_'.$type.'` WHERE id_cart_rule = '.(int)$this->id.') crt ON t.id_'.$type.' = crt.id_'.$type.' - '.($active_only ? 'WHERE t.active = 1' : '').' - ORDER BY name ASC', + WHERE 1 '.($active_only ? ' AND t.active = 1' : ''). + $shop_list. + ' ORDER BY name ASC', false); while ($row = Db::getInstance()->nextRow($resource)) $array[($row['selected'] || $this->{$type.'_restriction'} == 0) ? 'selected' : 'unselected'][] = $row; diff --git a/classes/shop/Shop.php b/classes/shop/Shop.php index c5e17f00e..f781dc728 100644 --- a/classes/shop/Shop.php +++ b/classes/shop/Shop.php @@ -556,7 +556,7 @@ class ShopCore extends ObjectModel $shops->where('active', '=', 1); if ($id_shop_group) - $shops->where('id_shop_group', '=', $id_shop_group); + $shops->where('id_shop_group', '=', (int)$id_shop_group); return $shops; } @@ -664,7 +664,7 @@ class ShopCore extends ObjectModel */ public static function getShopById($id, $identifier, $table) { - return Db::getInstance()->executeS('SELECT `id_shop`, `'.pSQL($identifier).'` FROM `'._DB_PREFIX_.pSQL($table).'_shop` WHERE `'.pSQL($identifier).'` = '.(int)$id); + return Db::getInstance()->executeS('SELECT `id_shop`, `'.bqSQL($identifier).'` FROM `'._DB_PREFIX_.bqSQL($table).'_shop` WHERE `'.bqSQL($identifier).'` = '.(int)$id); } public static function setContext($type, $id = null) diff --git a/controllers/admin/AdminSpecificPriceRuleController.php b/controllers/admin/AdminSpecificPriceRuleController.php index 12450bf4a..1e23d479a 100755 --- a/controllers/admin/AdminSpecificPriceRuleController.php +++ b/controllers/admin/AdminSpecificPriceRuleController.php @@ -130,6 +130,10 @@ class AdminSpecificPriceRuleControllerCore extends AdminController if (!$this->object->id) $this->object->price = -1; + $shops = Shop::getShops(); + if (count($this->context->employee->getAssociatedShops()) > 1) + $shops = array_merge(array(0 => array('id_shop' => 0, 'name' => $this->l('All shops'))), $shops); + $this->fields_form = array( 'legend' => array( 'title' => $this->l('Specific price rules'), @@ -149,7 +153,7 @@ class AdminSpecificPriceRuleControllerCore extends AdminController 'label' => $this->l('Shop:'), 'name' => 'id_shop', 'options' => array( - 'query' => array_merge(array(0 => array('id_shop' => 0, 'name' => $this->l('All shops'))), Shop::getShops()), + 'query' => $shops, 'id' => 'id_shop', 'name' => 'name' ),