diff --git a/classes/db/Db.php b/classes/db/Db.php index 485cecd1fc6e7..4319cf204b706 100755 --- a/classes/db/Db.php +++ b/classes/db/Db.php @@ -164,7 +164,7 @@ abstract public function getNumberError(); /* do not remove, useful for some modules */ abstract public function set_db($db_name); - + abstract public function getBestEngine(); /** @@ -549,7 +549,7 @@ public function getRow($sql, $use_cache = true) $result = false; else $result = $this->nextRow($this->result); - $this->last_cached = false; + $this->last_cached = false; if (is_null($result)) $result = false; if ($use_cache && $this->is_cache_enabled) @@ -728,7 +728,6 @@ public static function ps($sql, $use_cache = 1) { Tools::displayAsDeprecated(); $ret = Db::s($sql, $use_cache); - p($ret); return $ret; } diff --git a/classes/stock/Stock.php b/classes/stock/Stock.php index da41f16b00065..8586be5b2476d 100644 --- a/classes/stock/Stock.php +++ b/classes/stock/Stock.php @@ -158,4 +158,12 @@ public function getWsRealQuantity() $quantity = $manager->getProductRealQuantities($this->id_product, $this->id_product_attribute, $this->id_warehouse, true); return $quantity; } + + public static function deleteStockByIds($id_product = null, $id_product_attribute = null) + { + if (!$id_product || !$id_product_attribute) + return false; + + return Db::getInstance()->execute('DELETE FROM '._DB_PREFIX_.'stock WHERE `id_product` = '.(int)$id_product.' AND `id_product_attribute` = '.(int)$id_product_attribute); + } } \ No newline at end of file diff --git a/controllers/admin/AdminProductsController.php b/controllers/admin/AdminProductsController.php index e279e10725411..12e364beedde3 100644 --- a/controllers/admin/AdminProductsController.php +++ b/controllers/admin/AdminProductsController.php @@ -1409,23 +1409,38 @@ public function ajaxProcessDeleteProductAttribute() { $id_product = (int)Tools::getValue('id_product'); $id_product_attribute = (int)Tools::getValue('id_product_attribute'); + if ($id_product && Validate::isUnsignedId($id_product) && Validate::isLoadedObject($product = new Product($id_product))) { - $product->deleteAttributeCombination((int)$id_product_attribute); - $product->checkDefaultAttributes(); - if (!$product->hasAttributes()) - { - $product->cache_default_attribute = 0; - $product->update(); - } + if (($depends_on_stock = StockAvailable::dependsOnStock($id_product)) && StockAvailable::getQuantityAvailableByProduct($id_product, $id_product_attribute)) + $json = array( + 'status' => 'error', + 'message'=> $this->l('When product depend of StockAvaible you need to delete the quantity associate to the combination before delete combination') + ); else - Product::updateDefaultAttribute($id_product); + { + $product->deleteAttributeCombination((int)$id_product_attribute); + $product->checkDefaultAttributes(); + if (!$product->hasAttributes()) + { + $product->cache_default_attribute = 0; + $product->update(); + } + else + Product::updateDefaultAttribute($id_product); - $json = array( - 'status' => 'ok', - 'message'=> $this->_conf[1], - 'id_product_attribute' => (int)$id_product_attribute - ); + if ($depends_on_stock && !Stock::deleteStockByIds($id_product, $id_product_attribute)) + $json = array( + 'status' => 'error', + 'message'=> $this->l('Error while delete the stock') + ); + else + $json = array( + 'status' => 'ok', + 'message'=> $this->_conf[1], + 'id_product_attribute' => (int)$id_product_attribute + ); + } } else $json = array( diff --git a/js/admin-products.js b/js/admin-products.js index 7e117ccb77541..09899cc2ac38a 100644 --- a/js/admin-products.js +++ b/js/admin-products.js @@ -374,7 +374,6 @@ product_tabs['Combinations'] = new function(){ if (data.attribute) { var td = $('#qty_' + data.id_product_attribute); - console.log(td); td.attr('id', 'qty_0'); td.children('input').val('0').attr('name', 'qty_0'); td.next('td').text(data.attribute[0].name);