From f1223a3289befc0720386e4e183bf395e1b19bda Mon Sep 17 00:00:00 2001 From: Marion Muszynski Date: Fri, 1 Apr 2016 11:51:58 +0200 Subject: [PATCH] update to add product in parent category --- modules/braderie/AdminBraderie.php | 4 ++-- modules/braderie/ajax.php | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/modules/braderie/AdminBraderie.php b/modules/braderie/AdminBraderie.php index 114a9d09..42132f3b 100644 --- a/modules/braderie/AdminBraderie.php +++ b/modules/braderie/AdminBraderie.php @@ -101,7 +101,6 @@ class AdminBraderie extends AdminTab dataType: \'json\', data: { ean: $(this).val() }, success: function(response) { - console.log(response); if (response.name == null) { $("#error").empty().append("'.$this->l('Aucun produit n\'a été trouvé. Vérifier le code EAN').'"); $("#ean_from_product").empty(); @@ -167,7 +166,8 @@ class AdminBraderie extends AdminTab type: \'POST\', url: \''._MODULE_DIR_.'braderie/ajax.php?action=addToSellout'.'\', dataType: \'json\', - data: { + data: { + parent_category: $("#sale").val(), category: $("#category").val(), storage: $("#input_storage").val(), product: $("#hidden_product_id").val(), diff --git a/modules/braderie/ajax.php b/modules/braderie/ajax.php index 92b80a24..040f81e8 100644 --- a/modules/braderie/ajax.php +++ b/modules/braderie/ajax.php @@ -103,6 +103,12 @@ function getProductId() function addToSellout() { + $parent_category = (int)Tools::getValue('parent_category', false); + if (!$parent_category || !is_int($parent_category)) { + http_response_code(500); + return Toold::displayError('La catégorie principale n\'est pas valide'); + } + $category = (int)Tools::getValue('category', false); if (!$category || !is_int($category)) { http_response_code(500); @@ -160,6 +166,14 @@ function addToSellout() '". (int)($max_position + 1 ) ."' )"); + $max_position_in_parent = Db::getInstance()->getValue("SELECT MAX(cp.`position`) AS max FROM `"._DB_PREFIX_."category_product` cp WHERE cp.`id_category`=" . (int)$parent_category); + $add_parent_category = Db::getInstance()->Execute("INSERT INTO `"._DB_PREFIX_."category_product` (`id_product`, `id_category`, `position`) + VALUES ( + '". $product->id ."', + '". (int)$parent_category ."', + '". (int)($max_position_in_parent + 1 ) ."' + )"); + if ($product->hasAttributes()) Product::updateDefaultAttribute($product->id);