[-] BO: Fix multishop employee restriction on cart and catalog price rules PSCFV-2505
This commit is contained in:
+15
-5
@@ -252,7 +252,7 @@ class CartRuleCore extends ObjectModel
|
|||||||
$cart_rule['value'] = 0;
|
$cart_rule['value'] = 0;
|
||||||
$cart_rule['minimal'] = $cart_rule['minimum_amount'];
|
$cart_rule['minimal'] = $cart_rule['minimum_amount'];
|
||||||
$cart_rule['cumulable'] = !$cart_rule['cart_rule_restriction'];
|
$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;
|
$cart_rule['id_discount_type'] = Discount::FREE_SHIPPING;
|
||||||
elseif ($cart_rule['reduction_percent'] > 0)
|
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')))
|
if (!in_array($type, array('country', 'carrier', 'group', 'cart_rule', 'shop')))
|
||||||
return false;
|
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)
|
if (!Validate::isLoadedObject($this) OR $this->{$type.'_restriction'} == 0)
|
||||||
{
|
{
|
||||||
$array['selected'] = Db::getInstance()->executeS('
|
$array['selected'] = Db::getInstance()->executeS('
|
||||||
@@ -945,8 +953,9 @@ class CartRuleCore extends ObjectModel
|
|||||||
WHERE 1
|
WHERE 1
|
||||||
'.($active_only ? 'AND t.active = 1' : '').'
|
'.($active_only ? 'AND t.active = 1' : '').'
|
||||||
'.(in_array($type, array('carrier', 'shop')) ? ' AND t.deleted = 0' : '').'
|
'.(in_array($type, array('carrier', 'shop')) ? ' AND t.deleted = 0' : '').'
|
||||||
'.($type == 'cart_rule' ? 'AND t.id_cart_rule != '.(int)$this->id : '').'
|
'.($type == 'cart_rule' ? 'AND t.id_cart_rule != '.(int)$this->id : '').
|
||||||
ORDER BY name ASC');
|
$shop_list.
|
||||||
|
' ORDER BY name ASC');
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -959,8 +968,9 @@ class CartRuleCore extends ObjectModel
|
|||||||
FROM `'._DB_PREFIX_.$type.'` t
|
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.')' : '').'
|
'.($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.'
|
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' : '').'
|
WHERE 1 '.($active_only ? ' AND t.active = 1' : '').
|
||||||
ORDER BY name ASC',
|
$shop_list.
|
||||||
|
' ORDER BY name ASC',
|
||||||
false);
|
false);
|
||||||
while ($row = Db::getInstance()->nextRow($resource))
|
while ($row = Db::getInstance()->nextRow($resource))
|
||||||
$array[($row['selected'] || $this->{$type.'_restriction'} == 0) ? 'selected' : 'unselected'][] = $row;
|
$array[($row['selected'] || $this->{$type.'_restriction'} == 0) ? 'selected' : 'unselected'][] = $row;
|
||||||
|
|||||||
@@ -556,7 +556,7 @@ class ShopCore extends ObjectModel
|
|||||||
$shops->where('active', '=', 1);
|
$shops->where('active', '=', 1);
|
||||||
|
|
||||||
if ($id_shop_group)
|
if ($id_shop_group)
|
||||||
$shops->where('id_shop_group', '=', $id_shop_group);
|
$shops->where('id_shop_group', '=', (int)$id_shop_group);
|
||||||
|
|
||||||
return $shops;
|
return $shops;
|
||||||
}
|
}
|
||||||
@@ -664,7 +664,7 @@ class ShopCore extends ObjectModel
|
|||||||
*/
|
*/
|
||||||
public static function getShopById($id, $identifier, $table)
|
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)
|
public static function setContext($type, $id = null)
|
||||||
|
|||||||
@@ -130,6 +130,10 @@ class AdminSpecificPriceRuleControllerCore extends AdminController
|
|||||||
if (!$this->object->id)
|
if (!$this->object->id)
|
||||||
$this->object->price = -1;
|
$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(
|
$this->fields_form = array(
|
||||||
'legend' => array(
|
'legend' => array(
|
||||||
'title' => $this->l('Specific price rules'),
|
'title' => $this->l('Specific price rules'),
|
||||||
@@ -149,7 +153,7 @@ class AdminSpecificPriceRuleControllerCore extends AdminController
|
|||||||
'label' => $this->l('Shop:'),
|
'label' => $this->l('Shop:'),
|
||||||
'name' => 'id_shop',
|
'name' => 'id_shop',
|
||||||
'options' => array(
|
'options' => array(
|
||||||
'query' => array_merge(array(0 => array('id_shop' => 0, 'name' => $this->l('All shops'))), Shop::getShops()),
|
'query' => $shops,
|
||||||
'id' => 'id_shop',
|
'id' => 'id_shop',
|
||||||
'name' => 'name'
|
'name' => 'name'
|
||||||
),
|
),
|
||||||
|
|||||||
Reference in New Issue
Block a user