[-] BO : #PSTEST-53 : fixed added quantities maximal for a pack

This commit is contained in:
lLefevre
2011-12-19 16:13:52 +00:00
parent fd0dac461e
commit 8ffb0864a3
4 changed files with 50 additions and 19 deletions
@@ -42,7 +42,8 @@
<div class="separation"></div>
<div class="hint" style="display:block; position:'auto';">
<p>{l s='This interface allows you to manage the available quantities for sale of the current product and its combinations on the current shop.'}</p>
<p>{l s='You can manually specify the quantities for the product / each product combinations, or choose to automatically determine these quantities based on your stock.'}</p>
<p>{l s='You can choose to use the advanced stock management system for this product or not.'}</p>
<p>{l s='You can manually specify the quantities for the product / each product combinations, or choose to automatically determine these quantities based on your stock (if advanced stock management is activated).'}</p>
<p>{l s='In this case, the quantities correspond to the quantitites of the real stock in the warehouses associated to the current shop or current group of shops.'}</p>
</div>
<br />
@@ -50,7 +51,7 @@
<div class="separation"></div>
{if $show_quantities == true}
{if $show_quantities == true && !$product->cache_is_pack}
<div class="warn" id="available_quantity_ajax_msg" style="display: none;"></div>
<div class="error" id="available_quantity_ajax_error_msg" style="display: none;"></div>
<div class="conf" id="available_quantity_ajax_success_msg" style="display: none;"></div>
@@ -137,6 +138,10 @@
</tr>
</tbody>
</table>
{elseif $product->cache_is_pack}
<div class="warn">
<p>{l s='It is not possible to manage quantities when you are managing a pack.'}</p>
</div>
{else}
<div class="warn">
<p>{l s='It is not possible to manage quantities when : '}</p>
+1 -1
View File
@@ -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
View File
@@ -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));
+37 -13
View File
@@ -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);
}
}
/**