// updated stock for Pack

git-svn-id: http://dev.prestashop.com/svn/v1/branches/1.5.x@12292 b9a71923-0436-4b27-9f14-aed3839534dd
This commit is contained in:
bMancone
2012-01-09 18:23:01 +00:00
parent 1739b144c0
commit 4af34a28b3
5 changed files with 71 additions and 65 deletions
+10 -10
View File
@@ -365,8 +365,8 @@ class ProductCore extends ObjectModel
const CUSTOMIZE_FILE = 0;
const CUSTOMIZE_TEXTFIELD = 1;
// Note: prefix is "PTYPE" because TYPE_ is used in ObjectModel (definition)
const PTYPE_SIMPLE = 0;
const PTYPE_PACK = 1;
@@ -1034,7 +1034,7 @@ class ProductCore extends ObjectModel
$price = str_replace(',', '.', $price);
$weight = str_replace(',', '.', $weight);
$combination = new Combination();
$combination->id_product = (int)$this->id;
$combination->price = (float)$price;
@@ -1052,9 +1052,9 @@ class ProductCore extends ObjectModel
if (!$combination->id)
return false;
Product::updateDefaultAttribute($this->id);
if (!empty($id_images))
$combination->setImages($id_images);
@@ -1071,9 +1071,9 @@ class ProductCore extends ObjectModel
$id_product_attribute = $this->addAttribute(
$price, $weight, $unit_impact, $ecotax, 0, $id_images,
$reference, $ean13, $default, $location, $upc, $minimal_quantity);
$this->addSupplierReference($supplier_reference, $id_product_attribute);
$result = Db::getInstance()->execute(
'UPDATE `'._DB_PREFIX_.'product_attribute`
SET `wholesale_price` = '.(float)$wholesale_price.'
@@ -1179,7 +1179,7 @@ class ProductCore extends ObjectModel
$this->addSupplierReference($supplier_reference, $id_product_attribute);
return $return;
}
public function addSupplierReference($supplier_reference, $id_product_attribute = null, $id_currency = null)
{
//Try to set the default supplier reference
@@ -1245,10 +1245,10 @@ class ProductCore extends ObjectModel
$combination->minimal_quantity = (int)$minimal_quantity;
$combination->available_date = pSQL($available_date);
$combination->save();
if (!empty($id_images))
$combination->setImages($id_images);
Hook::exec('actionProductAttributeUpdate', array('id_product_attribute' => $id_product_attribute));
Product::updateDefaultAttribute($this->id);
+2
View File
@@ -95,6 +95,8 @@ class OrderHistoryCore extends ObjectModel
&& $oldOrderStatus->logable))
{
ProductSale::addProductSale($product['product_id'], $product['product_quantity']);
if ($oldOrderStatus->id == Configuration::get('PS_OS_ERROR') || $oldOrderStatus->id == Configuration::get('PS_OS_CANCELED'))
StockAvailable::updateQuantity($product['product_id'], $product['product_attribute_id'], -(int)$product['product_quantity'], $order->id_shop);
}
/* If becoming unlogable => removing sale */
else if (!$newOS->logable
+11 -36
View File
@@ -279,44 +279,19 @@ class StockAvailableCore extends ObjectModel
if (is_null($id_product_attribute))
$id_product_attribute = 0;
// if product is a pack
if (Pack::isPack($id_product))
{
$items = Pack::getItems((int)$id_product, Configuration::get('PS_LANG_DEFAULT'));
$query = new DbQuery();
$query->select('SUM(quantity)');
$query->from('stock_available');
// gets an array of quantities (quantity for the product / quantity in pack)
$quantities = array();
foreach ($items as $item)
if (!$item->isAvailableWhenOutOfStock((int)$item->out_of_stock))
$quantities[] = Product::getQuantity($item->id) / ($item->pack_quantity !== 0 ? $item->pack_quantity : 1);
// if null, it's a product without attributes
if (!is_null($id_product))
$query->where('id_product = '.(int)$id_product);
// gets the minimum
$quantity = $quantities[0];
foreach ($quantities as $value)
{
if ($quantity > $value)
$quantity = $value;
}
$query->where('id_product_attribute = '.(int)$id_product_attribute);
// returns the number of pack available
return $quantity;
}
else // else
{
$query = new DbQuery();
$query->select('SUM(quantity)');
$query->from('stock_available');
$query = StockAvailable::addSqlShopRestriction($query, $id_shop);
// if null, it's a product without attributes
if (!is_null($id_product))
$query->where('id_product = '.(int)$id_product);
$query->where('id_product_attribute = '.(int)$id_product_attribute);
$query = StockAvailable::addSqlShopRestriction($query, $id_shop);
return (int)Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue($query);
}
return (int)Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue($query);
}
/**
@@ -382,10 +357,10 @@ class StockAvailableCore extends ObjectModel
// Update quantity of the pack products
if (Pack::isPack($id_product))
{
$products_pack = Pack::getItems((int)$product['id_product'], (int)Configuration::get('PS_LANG_DEFAULT'));
$products_pack = Pack::getItems($id_product, (int)Configuration::get('PS_LANG_DEFAULT'));
foreach ($products_pack as $product_pack)
{
$pack_id_product_attribute = Product::getDefaultAttribute($tab_product_pack['id_product'], 1);
$pack_id_product_attribute = Product::getDefaultAttribute($product_pack->id, 1);
StockAvailable::updateQuantity($product_pack->id, $pack_id_product_attribute, $product_pack->pack_quantity * $delta_quantity, $id_shop);
}
}