[-] BO : #PSTEST-53 : fixed added quantities maximal for a pack
This commit is contained in:
+1
-1
@@ -96,7 +96,7 @@ class PackCore extends Product
|
||||
foreach ($items as $item)
|
||||
{
|
||||
// Updated for 1.5.0
|
||||
if (Product::getQuantity($item->id) < $item->pack_quantity || !$item->isAvailableWhenOutOfStock((int)$item->out_of_stock))
|
||||
if (Product::getQuantity($item->id) < $item->pack_quantity || (Product::getQuantity($item->id) < $item->pack_quantity && !$item->isAvailableWhenOutOfStock((int)$item->out_of_stock)))
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
||||
+5
-3
@@ -2599,9 +2599,11 @@ class ProductCore extends ObjectModel
|
||||
public static function getQuantity($id_product, $id_product_attribute = null, $cache_is_pack = null)
|
||||
{
|
||||
$lang = Configuration::get('PS_LANG_DEFAULT');
|
||||
if (((int)$cache_is_pack || ($cache_is_pack === null && Pack::isPack((int)$id_product, (int)$lang)))
|
||||
&& !Pack::isInStock((int)$id_product, (int)$lang))
|
||||
return 0;
|
||||
if ((int)$cache_is_pack || ($cache_is_pack === null && Pack::isPack((int)$id_product)))
|
||||
{
|
||||
if (!Pack::isInStock((int)$id_product))
|
||||
return 0;
|
||||
}
|
||||
|
||||
// @since 1.5.0
|
||||
return (StockAvailable::getQuantityAvailableByProduct($id_product, $id_product_attribute));
|
||||
|
||||
@@ -90,7 +90,6 @@ class StockAvailableCore extends ObjectModel
|
||||
$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);
|
||||
}
|
||||
|
||||
@@ -259,19 +258,44 @@ class StockAvailableCore extends ObjectModel
|
||||
if (is_null($id_product_attribute))
|
||||
$id_product_attribute = 0;
|
||||
|
||||
$query = new DbQuery();
|
||||
$query->select('SUM(quantity)');
|
||||
$query->from('stock_available');
|
||||
// if product is a pack
|
||||
if (Pack::isPack($id_product))
|
||||
{
|
||||
$items = Pack::getItems((int)$id_product, Configuration::get('PS_LANG_DEFAULT'));
|
||||
|
||||
// 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);
|
||||
// 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);
|
||||
|
||||
// gets the minimum
|
||||
$quantity = $quantities[0];
|
||||
foreach ($quantities as $value)
|
||||
{
|
||||
if ($quantity > $value)
|
||||
$quantity = $value;
|
||||
}
|
||||
|
||||
// returns the number of pack available
|
||||
return $quantity;
|
||||
}
|
||||
else // else
|
||||
{
|
||||
$query = new DbQuery();
|
||||
$query->select('SUM(quantity)');
|
||||
$query->from('stock_available');
|
||||
|
||||
// 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);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user