[*] BO : shop restriction added to the cart rules
This commit is contained in:
@@ -179,4 +179,36 @@
|
||||
<a href="javascript:addProductRuleGroup();">
|
||||
<img src="../img/admin/add.gif" alt="{l s='Add'}" title="{l s='Add'}" /> {l s='Add a new rule group'}
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
{if $shops.unselected|@count + $shops.selected|@count > 1}
|
||||
<br />
|
||||
<input type="checkbox" id="shop_restriction" name="shop_restriction" value="1" {if $shops.unselected|@count}checked="checked"{/if} /> <strong>{l s='Shop selection'}</strong>
|
||||
<div id="shop_restriction_div" style="border:1px solid #AAAAAA;margin-top:10px;padding:0 10px 10px 10px;background-color:#FFF5D3">
|
||||
<table>
|
||||
<tr>
|
||||
<td>
|
||||
<p><strong>{l s='Selected shops'}</strong></p>
|
||||
<select name="shop_select[]" id="shop_select_2" style="border:1px solid #AAAAAA;width:400px;height:160px" multiple>
|
||||
{foreach from=$shops.selected item='shop'}
|
||||
<option value="{$shop.id_shop|intval}"> {$shop.name}</option>
|
||||
{/foreach}
|
||||
</select><br /><br />
|
||||
<a style="text-align:center;display:block;border:1px solid #aaa;text-decoration:none;background-color:#fafafa;color:#123456;margin:2px;padding:2px" id="shop_select_remove">
|
||||
{l s='Remove'} >>
|
||||
</a>
|
||||
</td>
|
||||
<td style="padding-left:20px;">
|
||||
<p><strong>{l s='Unselected shops'}</strong></p>
|
||||
<select id="shop_select_1" style="border:1px solid #AAAAAA;width:400px;height:160px" multiple>
|
||||
{foreach from=$shops.unselected item='shop'}
|
||||
<option value="{$shop.id_shop|intval}"> {$shop.name}</option>
|
||||
{/foreach}
|
||||
</select><br /><br />
|
||||
<a style="text-align:center;display:block;border:1px solid #aaa;text-decoration:none;background-color:#fafafa;color:#123456;margin:2px;padding:2px" id="shop_select_add">
|
||||
<< {l s='Add'}
|
||||
</a>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
{/if}
|
||||
@@ -28,6 +28,7 @@ function addProductRuleGroup()
|
||||
{
|
||||
product_rule_groups_counter += 1;
|
||||
product_rule_counters[product_rule_groups_counter] = 0;
|
||||
|
||||
$.get(
|
||||
'ajax-tab.php',
|
||||
{controller:'AdminCartRules',token:currentToken,newProductRuleGroup:1,product_rule_group_id:product_rule_groups_counter},
|
||||
@@ -93,7 +94,7 @@ function updateProductRuleShortDescription(item)
|
||||
$('#' + id2 + '_match').val(length);
|
||||
}
|
||||
|
||||
var restrictions = new Array('country', 'carrier', 'group', 'cart_rule');
|
||||
var restrictions = new Array('country', 'carrier', 'group', 'cart_rule', 'shop');
|
||||
for (i in restrictions)
|
||||
{
|
||||
toggleCartRuleFilter($('#' + restrictions[i] + '_restriction'));
|
||||
|
||||
+31
-8
@@ -47,6 +47,7 @@ class CartRuleCore extends ObjectModel
|
||||
public $group_restriction;
|
||||
public $cart_rule_restriction;
|
||||
public $product_restriction;
|
||||
public $shop_restriction;
|
||||
public $free_shipping;
|
||||
public $reduction_percent;
|
||||
public $reduction_amount;
|
||||
@@ -84,6 +85,7 @@ class CartRuleCore extends ObjectModel
|
||||
'group_restriction' => array('type' => self::TYPE_BOOL, 'validate' => 'isBool'),
|
||||
'cart_rule_restriction' => array('type' => self::TYPE_BOOL, 'validate' => 'isBool'),
|
||||
'product_restriction' => array('type' => self::TYPE_BOOL, 'validate' => 'isBool'),
|
||||
'shop_restriction' => array('type' => self::TYPE_BOOL, 'validate' => 'isBool'),
|
||||
'free_shipping' => array('type' => self::TYPE_BOOL, 'validate' => 'isBool'),
|
||||
'reduction_percent' => array('type' => self::TYPE_FLOAT, 'validate' => 'isFloat'),
|
||||
'reduction_amount' => array('type' => self::TYPE_FLOAT, 'validate' => 'isFloat'),
|
||||
@@ -124,6 +126,7 @@ class CartRuleCore extends ObjectModel
|
||||
|
||||
$r = Db::getInstance()->Execute('DELETE FROM `'._DB_PREFIX_.'cart_cart_rule` WHERE `id_cart_rule` = '.(int)$this->id);
|
||||
$r &= Db::getInstance()->Execute('DELETE FROM `'._DB_PREFIX_.'cart_rule_carrier` WHERE `id_cart_rule` = '.(int)$this->id);
|
||||
$r &= Db::getInstance()->Execute('DELETE FROM `'._DB_PREFIX_.'cart_rule_shop` WHERE `id_cart_rule` = '.(int)$this->id);
|
||||
$r &= Db::getInstance()->Execute('DELETE FROM `'._DB_PREFIX_.'cart_rule_group` WHERE `id_cart_rule` = '.(int)$this->id);
|
||||
$r &= Db::getInstance()->Execute('DELETE FROM `'._DB_PREFIX_.'cart_rule_country` WHERE `id_cart_rule` = '.(int)$this->id);
|
||||
$r &= Db::getInstance()->Execute('DELETE FROM `'._DB_PREFIX_.'cart_rule_combination` WHERE `id_cart_rule_1` = '.(int)$this->id.' OR `id_cart_rule_2` = '.(int)$this->id);
|
||||
@@ -143,6 +146,9 @@ class CartRuleCore extends ObjectModel
|
||||
*/
|
||||
public static function copyConditions($id_cart_rule_source, $id_cart_rule_destination)
|
||||
{
|
||||
Db::getInstance()->Execute('
|
||||
INSERT INTO `'._DB_PREFIX_.'cart_rule_shop` (`id_cart_rule`, `id_shop`)
|
||||
(SELECT '.(int)$id_cart_rule_destination.', id_shop FROM `'._DB_PREFIX_.'cart_rule_shop` WHERE `id_cart_rule` = '.(int)$id_cart_rule_source.')');
|
||||
Db::getInstance()->Execute('
|
||||
INSERT INTO `'._DB_PREFIX_.'cart_rule_carrier` (`id_cart_rule`, `id_carrier`)
|
||||
(SELECT '.(int)$id_cart_rule_destination.', id_carrier FROM `'._DB_PREFIX_.'cart_rule_carrier` WHERE `id_cart_rule` = '.(int)$id_cart_rule_source.')');
|
||||
@@ -409,6 +415,18 @@ class CartRuleCore extends ObjectModel
|
||||
return Tools::displayError('You cannot use this voucher with this carrier');
|
||||
}
|
||||
|
||||
// Check if the cart rules appliy to the shop browsed by the customer
|
||||
if ($this->shop_restriction && $context->shop->id && Shop::isFeatureActive())
|
||||
{
|
||||
$id_cart_rule = (int)Db::getInstance()->getValue('
|
||||
SELECT crs.id_cart_rule
|
||||
FROM '._DB_PREFIX_.'cart_rule_shop crs
|
||||
WHERE crs.id_cart_rule = '.(int)$this->id.'
|
||||
AND crs.id_shop = '.(int)$context->shop->id);
|
||||
if (!$id_cart_rule)
|
||||
return Tools::displayError('You cannot use this voucher');
|
||||
}
|
||||
|
||||
// Check if the products chosen by the customer are usable with the cart rule
|
||||
if ($this->product_restriction)
|
||||
{
|
||||
@@ -724,21 +742,21 @@ class CartRuleCore extends ObjectModel
|
||||
return $array;
|
||||
}
|
||||
|
||||
public function getAssociatedRestrictions($type, $active = 1)
|
||||
public function getAssociatedRestrictions($type, $active_only, $i18n)
|
||||
{
|
||||
$array = array('selected' => array(), 'unselected' => array());
|
||||
|
||||
if (!in_array($type, array('country', 'carrier', 'group', 'cart_rule')))
|
||||
if (!in_array($type, array('country', 'carrier', 'group', 'cart_rule', 'shop')))
|
||||
return false;
|
||||
|
||||
if (!Validate::isLoadedObject($this) OR $this->{$type.'_restriction'} == 0)
|
||||
{
|
||||
$array['selected'] = Db::getInstance()->ExecuteS('
|
||||
SELECT t.*, tl.*, 1 as selected
|
||||
SELECT t.*'.($i18n ? ', tl.*' : '').', 1 as selected
|
||||
FROM `'._DB_PREFIX_.$type.'` t
|
||||
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 : '').'
|
||||
WHERE 1
|
||||
'.($active ? 'AND t.active = 1' : '').'
|
||||
'.($active_only ? 'AND t.active = 1' : '').'
|
||||
'.($type == 'cart_rule' ? 'AND t.id_cart_rule != '.(int)$this->id : '').'
|
||||
ORDER BY name ASC');
|
||||
}
|
||||
@@ -749,11 +767,11 @@ class CartRuleCore extends ObjectModel
|
||||
else
|
||||
{
|
||||
$resource = Db::getInstance()->query('
|
||||
SELECT t.*, tl.*, IF(crt.id_'.$type.' IS NULL, 0, 1) as selected
|
||||
SELECT t.*'.($i18n ? ', tl.*' : '').', IF(crt.id_'.$type.' IS NULL, 0, 1) as selected
|
||||
FROM `'._DB_PREFIX_.$type.'` t
|
||||
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.'
|
||||
'.($active ? 'WHERE t.active = 1' : '').'
|
||||
'.($active_only ? 'WHERE t.active = 1' : '').'
|
||||
ORDER BY name ASC',
|
||||
false);
|
||||
while ($row = Db::getInstance()->nextRow($resource))
|
||||
@@ -798,6 +816,7 @@ class CartRuleCore extends ObjectModel
|
||||
$result = Db::getInstance()->executeS('
|
||||
SELECT cr.*
|
||||
FROM '._DB_PREFIX_.'cart_rule cr
|
||||
LEFT JOIN '._DB_PREFIX_.'cart_rule_shop crs ON cr.id_cart_rule = crs.id_cart_rule
|
||||
LEFT JOIN '._DB_PREFIX_.'cart_rule_carrier crca ON cr.id_cart_rule = crca.id_cart_rule
|
||||
LEFT JOIN '._DB_PREFIX_.'cart_rule_country crco ON cr.id_cart_rule = crco.id_cart_rule
|
||||
WHERE cr.active = 1
|
||||
@@ -814,6 +833,10 @@ class CartRuleCore extends ObjectModel
|
||||
cr.carrier_restriction = 0
|
||||
'.($context->cart->id_carrier ? 'OR crca.id_carrier = '.(int)$context->cart->id_carrier : '').'
|
||||
)
|
||||
AND (
|
||||
cr.shop_restriction = 0
|
||||
'.((Shop::isFeatureActive() && $context->shop->id) ? 'OR crs.id_shop = '.(int)$context->shop->id : '').'
|
||||
)
|
||||
AND (
|
||||
cr.group_restriction = 0
|
||||
'.($context->customer->id ? 'OR 0 < (
|
||||
|
||||
@@ -54,7 +54,7 @@ class AdminCartRulesControllerCore extends AdminController
|
||||
if (Tools::isSubmit('submitAddcart_rule') || Tools::isSubmit('submitAddcart_ruleAndStay'))
|
||||
{
|
||||
// These are checkboxes (which aren't sent through POST when they are not check), so they are forced to 0
|
||||
foreach (array('country', 'carrier', 'group', 'cart_rule', 'product') as $type)
|
||||
foreach (array('country', 'carrier', 'group', 'cart_rule', 'product', 'shop') as $type)
|
||||
if (!Tools::getValue($type.'_restriction'))
|
||||
$_POST[$type.'_restriction'] = 0;
|
||||
|
||||
@@ -76,7 +76,7 @@ class AdminCartRulesControllerCore extends AdminController
|
||||
{
|
||||
// All the associations are deleted for an update, then recreated when we call the "afterAdd" method
|
||||
$id_cart_rule = Tools::getValue('id_cart_rule');
|
||||
foreach (array('country', 'carrier', 'group', 'product_rule_group') as $type)
|
||||
foreach (array('country', 'carrier', 'group', 'product_rule_group', 'shop') as $type)
|
||||
Db::getInstance()->Execute('DELETE FROM `'._DB_PREFIX_.'cart_rule_'.$type.'` WHERE `id_cart_rule` = '.(int)$id_cart_rule);
|
||||
Db::getInstance()->Execute('DELETE FROM `'._DB_PREFIX_.'cart_rule_product_rule` WHERE `id_product_rule_group` NOT IN (SELECT `id_product_rule_group` FROM `'._DB_PREFIX_.'cart_rule_product_rule_group`)');
|
||||
Db::getInstance()->Execute('DELETE FROM `'._DB_PREFIX_.'cart_rule_product_rule_value` WHERE `id_product_rule` NOT IN (SELECT `id_product_rule` FROM `'._DB_PREFIX_.'cart_rule_product_rule`)');
|
||||
@@ -89,7 +89,7 @@ class AdminCartRulesControllerCore extends AdminController
|
||||
protected function afterAdd($currentObject)
|
||||
{
|
||||
// Add restrictions for generic entities like country, carrier and group
|
||||
foreach (array('country', 'carrier', 'group') as $type)
|
||||
foreach (array('country', 'carrier', 'group', 'shop') as $type)
|
||||
if (Tools::getValue($type.'_restriction') && is_array($array = Tools::getValue($type.'_select')) && count($array))
|
||||
{
|
||||
$values = array();
|
||||
@@ -304,7 +304,7 @@ class AdminCartRulesControllerCore extends AdminController
|
||||
if (Tools::isSubmit('newProductRule'))
|
||||
die ($this->getProductRuleDisplay(Tools::getValue('product_rule_group_id'), Tools::getValue('product_rule_id'), Tools::getValue('product_rule_type')));
|
||||
if (Tools::isSubmit('newProductRuleGroup') && $product_rule_group_id = Tools::getValue('product_rule_group_id'))
|
||||
die ($this->getProductRuleGroupDisplay($product_rule_group_id, Tools::getValue('product_rule_group_'.$product_rule_group_id.'_quantity')));
|
||||
die ($this->getProductRuleGroupDisplay($product_rule_group_id, Tools::getValue('product_rule_group_'.$product_rule_group_id.'_quantity', 1)));
|
||||
|
||||
if (Tools::isSubmit('customerFilter'))
|
||||
{
|
||||
@@ -386,10 +386,11 @@ class AdminCartRulesControllerCore extends AdminController
|
||||
'defaultCurrency' => Configuration::get('PS_CURRENCY_DEFAULT'),
|
||||
'defaultLanguage' => Configuration::get('PS_LANG_DEFAULT'),
|
||||
'currencies' => Currency::getCurrencies(),
|
||||
'countries' => $current_object->getAssociatedRestrictions('country', 1),
|
||||
'carriers' => $current_object->getAssociatedRestrictions('carrier', 1),
|
||||
'groups' => $current_object->getAssociatedRestrictions('group', 0),
|
||||
'cart_rules' => $current_object->getAssociatedRestrictions('cart_rule', 1),
|
||||
'countries' => $current_object->getAssociatedRestrictions('country', true, true),
|
||||
'carriers' => $current_object->getAssociatedRestrictions('carrier', true, true),
|
||||
'groups' => $current_object->getAssociatedRestrictions('group', false, true),
|
||||
'shops' => $current_object->getAssociatedRestrictions('shop', false, false),
|
||||
'cart_rules' => $current_object->getAssociatedRestrictions('cart_rule', false, true),
|
||||
'product_rule_groups' => $product_rule_groups,
|
||||
'product_rule_groups_counter' => count($product_rule_groups),
|
||||
'attribute_groups' => AttributeGroup::getAttributesGroups(Context::getContext()->language->id),
|
||||
@@ -413,5 +414,4 @@ class AdminCartRulesControllerCore extends AdminController
|
||||
$found = true;
|
||||
echo Tools::jsonEncode(array('found' => $found, 'vouchers' => $vouchers));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -216,6 +216,7 @@ CREATE TABLE `PREFIX_cart_rule` (
|
||||
`group_restriction` tinyint(1) unsigned NOT NULL default 0,
|
||||
`cart_rule_restriction` tinyint(1) unsigned NOT NULL default 0,
|
||||
`product_restriction` tinyint(1) unsigned NOT NULL default 0,
|
||||
`shop_restriction` tinyint(1) unsigned NOT NULL default 0,
|
||||
`free_shipping` tinyint(1) NOT NULL default 0,
|
||||
`reduction_percent` decimal(5,2) NOT NULL default 0,
|
||||
`reduction_amount` decimal(17,2) NOT NULL default 0,
|
||||
@@ -287,6 +288,12 @@ CREATE TABLE `PREFIX_cart_cart_rule` (
|
||||
KEY (`id_cart_rule`)
|
||||
) ENGINE=ENGINE_TYPE DEFAULT CHARSET=utf8;
|
||||
|
||||
CREATE TABLE `PREFIX_cart_rule_shop` (
|
||||
`id_cart_rule` int(10) unsigned NOT NULL,
|
||||
`id_shop` int(10) unsigned NOT NULL,
|
||||
PRIMARY KEY (`id_cart_rule`, `id_shop`)
|
||||
) ENGINE=ENGINE_TYPE DEFAULT CHARSET=utf8;
|
||||
|
||||
CREATE TABLE `PREFIX_cart_product` (
|
||||
`id_cart` int(10) unsigned NOT NULL,
|
||||
`id_product` int(10) unsigned NOT NULL,
|
||||
|
||||
@@ -1 +1,9 @@
|
||||
SET NAMES 'utf8';
|
||||
|
||||
ALTER TABLE `PREFIX_cart_rule` ADD `shop_restriction` tinyint(1) unsigned NOT NULL default 0 AFTER `product_restriction`;
|
||||
|
||||
CREATE TABLE `PREFIX_cart_rule_shop` (
|
||||
`id_cart_rule` int(10) unsigned NOT NULL,
|
||||
`id_shop` int(10) unsigned NOT NULL,
|
||||
PRIMARY KEY (`id_cart_rule`, `id_shop`)
|
||||
) ENGINE=ENGINE_TYPE DEFAULT CHARSET=utf8;
|
||||
|
||||
Reference in New Issue
Block a user