[-] BO: Forbid to add a pack into a pack
This commit is contained in:
@@ -51,13 +51,16 @@ else
|
||||
|
||||
// Excluding downloadable products from packs because download from pack is not supported
|
||||
$excludeVirtuals = (bool)Tools::getValue('excludeVirtuals', false);
|
||||
$exclude_packs = (bool)Tools::getValue('exclude_packs', false);
|
||||
|
||||
$sql = 'SELECT p.`id_product`, `reference`, pl.name
|
||||
FROM `'._DB_PREFIX_.'product` p
|
||||
LEFT JOIN `'._DB_PREFIX_.'product_lang` pl ON (pl.id_product = p.id_product AND pl.id_lang = '.(int)Context::getContext()->language->id.Shop::addSqlRestrictionOnLang('pl').')
|
||||
WHERE (pl.name LIKE \'%'.pSQL($query).'%\' OR p.reference LIKE \'%'.pSQL($query).'%\')'.
|
||||
(!empty($excludeIds) ? ' AND p.id_product NOT IN ('.$excludeIds.') ' : ' ').
|
||||
($excludeVirtuals ? 'AND p.id_product NOT IN (SELECT pd.id_product FROM `'._DB_PREFIX_.'product_download` pd WHERE (pd.id_product = p.id_product))' : '');
|
||||
($excludeVirtuals ? 'AND p.id_product NOT IN (SELECT pd.id_product FROM `'._DB_PREFIX_.'product_download` pd WHERE (pd.id_product = p.id_product))' : '').
|
||||
($exclude_packs ? 'AND (p.cache_is_pack IS NULL OR p.cache_is_pack = 0)' : '');
|
||||
|
||||
$items = Db::getInstance()->executeS($sql);
|
||||
|
||||
if ($items)
|
||||
|
||||
@@ -97,9 +97,9 @@
|
||||
<label class="text">{$bullet_common_field} {l s='Type:'}</label>
|
||||
<input type="radio" name="type_product" id="simple_product" value="{Product::PTYPE_SIMPLE}" {if $product_type == Product::PTYPE_SIMPLE}checked="checked"{/if} />
|
||||
<label class="radioCheck" for="simple_product">{l s='Product'}</label>
|
||||
<input type="radio" name="type_product" id="pack_product" value="{Product::PTYPE_PACK}" {if $product_type == Product::PTYPE_PACK}checked="checked"{/if} />
|
||||
<input type="radio" name="type_product" {if $is_in_pack}disabled="disabled"{/if} id="pack_product" value="{Product::PTYPE_PACK}" {if $product_type == Product::PTYPE_PACK}checked="checked"{/if} />
|
||||
<label class="radioCheck" for="pack_product">{l s='Pack'}</label>
|
||||
<input type="radio" name="type_product" id="virtual_product" value="{Product::PTYPE_VIRTUAL}" {if $product_type == Product::PTYPE_VIRTUAL}checked="checked"{/if} />
|
||||
<input type="radio" name="type_product" id="virtual_product" {if $is_in_pack}disabled="disabled"{/if} value="{Product::PTYPE_VIRTUAL}" {if $product_type == Product::PTYPE_VIRTUAL}checked="checked"{/if} />
|
||||
<label class="radioCheck" for="virtual_product">{l s='Virtual Product (services, booking or downloadable products)'}</label>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -3379,6 +3379,7 @@ class AdminProductsControllerCore extends AdminController
|
||||
$product->tags = Tag::getProductTags($product->id);
|
||||
|
||||
$data->assign('product_type', (int)Tools::getValue('type_product', $product->getType()));
|
||||
$data->assign('is_in_pack', (int)Pack::isPacked($product->id));
|
||||
|
||||
$check_product_association_ajax = false;
|
||||
if (Shop::isFeatureActive() && Shop::getContext() != Shop::CONTEXT_ALL)
|
||||
@@ -4115,10 +4116,6 @@ class AdminProductsControllerCore extends AdminController
|
||||
$this->tpl_form_vars['custom_form'] = Hook::exec('displayAdminProductsExtra', array(), (int)$id_module);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* delete all items in pack, then check if type_product value is 2.
|
||||
* if yes, add the pack items from input "inputPackItems"
|
||||
@@ -4143,7 +4140,9 @@ class AdminProductsControllerCore extends AdminController
|
||||
list($qty, $item_id) = explode('x', $line);
|
||||
if ($qty > 0 && isset($item_id))
|
||||
{
|
||||
if (!Pack::addItem((int)$product->id, (int)$item_id, (int)$qty))
|
||||
if (Pack::isPack((int)$item_id))
|
||||
$this->errors[] = Tools::displayError('You can\'t add product packs into a pack');
|
||||
elseif (!Pack::addItem((int)$product->id, (int)$item_id, (int)$qty))
|
||||
$this->errors[] = Tools::displayError('An error occurred while adding products to the pack.');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -991,7 +991,8 @@ product_tabs['Pack'] = new function(){
|
||||
},
|
||||
extraParams: {
|
||||
excludeIds : getSelectedIds(),
|
||||
excludeVirtuals : 1
|
||||
excludeVirtuals : 1,
|
||||
exclude_packs: 1
|
||||
}
|
||||
}).result(function(event, item){
|
||||
$('#curPackItemId').val(item[1]);
|
||||
|
||||
Reference in New Issue
Block a user