Skip to content

Commit

Permalink
[-] BO : Fix #PSCFV-10424 deletion of attire with stock advanced
Browse files Browse the repository at this point in the history
  • Loading branch information
Sacha Froment committed Oct 29, 2014
1 parent 8421397 commit 796584b
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 17 deletions.
5 changes: 2 additions & 3 deletions classes/db/Db.php
Expand Up @@ -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();

/**
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -728,7 +728,6 @@ public static function ps($sql, $use_cache = 1)
{
Tools::displayAsDeprecated();
$ret = Db::s($sql, $use_cache);
p($ret);
return $ret;
}

Expand Down
8 changes: 8 additions & 0 deletions classes/stock/Stock.php
Expand Up @@ -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);
}
}
41 changes: 28 additions & 13 deletions controllers/admin/AdminProductsController.php
Expand Up @@ -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(
Expand Down
1 change: 0 additions & 1 deletion js/admin-products.js
Expand Up @@ -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);
Expand Down

0 comments on commit 796584b

Please sign in to comment.