[-] BO: Fix multishop employee restriction on cart and catalog price rules PSCFV-2505

This commit is contained in:
rGaillard
2012-05-25 17:12:55 +00:00
parent 9e8dbc60df
commit be1cd70887
3 changed files with 22 additions and 8 deletions
+15 -5
View File
@@ -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;
+2 -2
View File
@@ -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)
@@ -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'
),