// Decrement stock available on order

git-svn-id: http://dev.prestashop.com/svn/v1/branches/1.5.x@9430 b9a71923-0436-4b27-9f14-aed3839534dd
This commit is contained in:
mDeflotte committed 2011-10-18 15:43:28 +00:00
1 parent 243387c4e0
commit 886fcda18e
3 files changed
+20 -14

No files matched your search

+1 -1
View File
@@ -193,7 +193,7 @@ abstract class PaymentModuleCore extends Module
$quantityInStock = ($productQuantity - (int)($product['cart_quantity']) < 0) ? $productQuantity : (int)($product['cart_quantity']); $quantityInStock = ($productQuantity - (int)($product['cart_quantity']) < 0) ? $productQuantity : (int)($product['cart_quantity']);
if ($id_order_state != Configuration::get('PS_OS_CANCELED') AND $id_order_state != Configuration::get('PS_OS_ERROR')) if ($id_order_state != Configuration::get('PS_OS_CANCELED') AND $id_order_state != Configuration::get('PS_OS_ERROR'))
{ {
if (Product::updateQuantity($product, (int)$order->id)) if (StockAvailable::updateQuantity($product['id_product'], $product['id_product_attribute'], -(int)$product['cart_quantity']))
$product['stock_quantity'] -= $product['cart_quantity']; $product['stock_quantity'] -= $product['cart_quantity'];
if ($product['stock_quantity'] < 0 && Configuration::get('PS_STOCK_MANAGEMENT')) if ($product['stock_quantity'] < 0 && Configuration::get('PS_STOCK_MANAGEMENT'))
$outOfStock = true; $outOfStock = true;
+4 -13
View File
@@ -906,7 +906,7 @@ class ProductCore extends ObjectModel
* @param boolean $default Is default attribute for product * @param boolean $default Is default attribute for product
* @return mixed $id_product_attribute or false * @return mixed $id_product_attribute or false
*/ */
public function addProductAttribute($price, $weight, $unit_impact, $ecotax, $quantity, $id_images, $reference, $supplier_reference, $ean13, $default, $location = null, $upc = null) public function addProductAttribute($price, $weight, $unit_impact, $ecotax, $id_images, $reference, $supplier_reference, $ean13, $default, $location = null, $upc = null)
{ {
if (!$this->id) if (!$this->id)
return; return;
@@ -931,13 +931,10 @@ class ProductCore extends ObjectModel
$id_product_attribute = Db::getInstance()->Insert_ID(); $id_product_attribute = Db::getInstance()->Insert_ID();
$this->setStock($quantity, $id_product_attribute);
Product::updateDefaultAttribute($this->id); Product::updateDefaultAttribute($this->id);
if (!$id_product_attribute) if (!$id_product_attribute)
return false; return false;
$this->addStockMvt((int)$quantity, 1, $id_product_attribute);
if (empty($id_images)) if (empty($id_images))
return (int)($id_product_attribute); return (int)($id_product_attribute);
$query = 'INSERT INTO `'._DB_PREFIX_.'product_attribute_image` (`id_product_attribute`, `id_image`) VALUES '; $query = 'INSERT INTO `'._DB_PREFIX_.'product_attribute_image` (`id_product_attribute`, `id_image`) VALUES ';
@@ -949,9 +946,9 @@ class ProductCore extends ObjectModel
return (int)($id_product_attribute); return (int)($id_product_attribute);
} }
public function addCombinationEntity($wholesale_price, $price, $weight, $unit_impact, $ecotax, $quantity, $id_images, $reference, $supplier_reference, $ean13, $default, $location = null, $upc = null) public function addCombinationEntity($wholesale_price, $price, $weight, $unit_impact, $ecotax, $id_images, $reference, $supplier_reference, $ean13, $default, $location = null, $upc = null)
{ {
$id_product_attribute = $this->addProductAttribute($price, $weight, $unit_impact, $ecotax, $quantity, $id_images, $reference, $supplier_reference, $ean13, $default, $location, $upc); $id_product_attribute = $this->addProductAttribute($price, $weight, $unit_impact, $ecotax, $id_images, $reference, $supplier_reference, $ean13, $default, $location, $upc);
$result = Db::getInstance()->execute('UPDATE `'._DB_PREFIX_.'product_attribute` SET `wholesale_price` = '.(float)$wholesale_price.' WHERE `id_product_attribute` = '.(int)$id_product_attribute); $result = Db::getInstance()->execute('UPDATE `'._DB_PREFIX_.'product_attribute` SET `wholesale_price` = '.(float)$wholesale_price.' WHERE `id_product_attribute` = '.(int)$id_product_attribute);
if (!$id_product_attribute OR !$result) if (!$id_product_attribute OR !$result)
return false; return false;
@@ -1037,7 +1034,7 @@ class ProductCore extends ObjectModel
* @param string $minimal_quantity Minimal quantity * @param string $minimal_quantity Minimal quantity
* @return array Update result * @return array Update result
*/ */
public function updateProductAttribute($id_product_attribute, $wholesale_price, $price, $weight, $unit, $ecotax, $quantity, $id_images, $reference, $supplier_reference, $ean13, $default, $location = null, $upc = null, $minimal_quantity, $available_date) public function updateProductAttribute($id_product_attribute, $wholesale_price, $price, $weight, $unit, $ecotax, $id_images, $reference, $supplier_reference, $ean13, $default, $location = null, $upc = null, $minimal_quantity, $available_date)
{ {
Db::getInstance()->execute(' Db::getInstance()->execute('
DELETE FROM `'._DB_PREFIX_.'product_attribute_combination` DELETE FROM `'._DB_PREFIX_.'product_attribute_combination`
@@ -1061,12 +1058,6 @@ class ProductCore extends ObjectModel
'available_date' => pSQL($available_date) 'available_date' => pSQL($available_date)
); );
if ($quantity)
{
$data['quantity'] = (int)$quantity;
$this->setStock($data['quantity'], $id_product_attribute);
}
if (!Db::getInstance()->AutoExecute(_DB_PREFIX_.'product_attribute', $data, 'UPDATE', '`id_product_attribute` = '.(int)($id_product_attribute)) OR !Db::getInstance()->execute('DELETE FROM `'._DB_PREFIX_.'product_attribute_image` WHERE `id_product_attribute` = '.(int)($id_product_attribute))) if (!Db::getInstance()->AutoExecute(_DB_PREFIX_.'product_attribute', $data, 'UPDATE', '`id_product_attribute` = '.(int)($id_product_attribute)) OR !Db::getInstance()->execute('DELETE FROM `'._DB_PREFIX_.'product_attribute_image` WHERE `id_product_attribute` = '.(int)($id_product_attribute)))
return false; return false;
if ($quantity) if ($quantity)
+15
View File
@@ -263,4 +263,19 @@ class StockAvailableCore extends ObjectModel
WHERE id_stock_available = '.(int)$id_stock_available); WHERE id_stock_available = '.(int)$id_stock_available);
} }
} }
/**
* For a given id_product and id_product_attribute update quantity the quantity available
*/
public static function updateQuantity($id_product, $id_product_attribute, $delta_quantity, $id_shop = null)
{
$id_stock = self::getIdStockAvailable($id_product, $id_product_attribute, $id_shop);
if (!$id_stock)
return false;
$stock_available = new StockAvailable($id_stock);
$stock_available->quantity = $stock_available->quantity + $delta_quantity;
$stock_available->save();
}
} }