Skip to content
Permalink
Browse files

BO: Prevent adding pack in itself

  • Loading branch information...
hibatallahAouadni committed Jun 15, 2017
1 parent 75d8b84 commit 18f57b62e897ed5b472e51f7ed69ce4e390d105e
Showing with 5 additions and 2 deletions.
  1. +2 −0 admin-dev/ajax_products_list.php
  2. +1 −1 controllers/admin/AdminProductsController.php
  3. +2 −1 js/admin/products.js
@@ -51,6 +51,7 @@
$excludeIds = implode(',', array_map('intval', explode(',', $excludeIds)));
} else {
$excludeIds = '';
$excludePackItself= Tools::getValue('packItself', false);
}
// Excluding downloadable products from packs because download from pack is not supported
@@ -68,6 +69,7 @@
LEFT JOIN `'._DB_PREFIX_.'image_lang` il ON (image_shop.`id_image` = il.`id_image` AND il.`id_lang` = '.(int)$context->language->id.')
WHERE (pl.name LIKE \'%'.pSQL($query).'%\' OR p.reference LIKE \'%'.pSQL($query).'%\')'.
(!empty($excludeIds) ? ' AND p.id_product NOT IN ('.$excludeIds.') ' : ' ').
(!empty($excludePackItself) ? ' AND p.id_product <> '.$excludePackItself.' ' : ' ').
($excludeVirtuals ? 'AND NOT EXISTS (SELECT 1 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)' : '').
' GROUP BY p.id_product';
@@ -5022,7 +5022,7 @@ public function updatePackItems($product)
$item_id_attribute = 0;
count($array = explode('x', $line)) == 3 ? list($qty, $item_id, $item_id_attribute) = $array : list($qty, $item_id) = $array;
if ($qty > 0 && isset($item_id)) {
if (Pack::isPack((int)$item_id)) {
if (Pack::isPack((int)$item_id || $product->id == (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, (int)$item_id_attribute)) {
$this->errors[] = Tools::displayError('An error occurred while attempting to add products to the pack.');
@@ -1244,7 +1244,8 @@ product_tabs['Pack'] = new function() {
dataType: 'json',
data: function (term) {
return {
q: term
q: term,
packItself: $('input[name=\'id_product\']').val()
};
},
results: function (data) {

0 comments on commit 18f57b6

Please sign in to comment.
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.