// Webservice: Stock

git-svn-id: http://dev.prestashop.com/svn/v1/branches/1.5.x@11390 b9a71923-0436-4b27-9f14-aed3839534dd
This commit is contained in:
bMancone
2011-12-19 18:34:31 +00:00
parent 5d7a120e50
commit 8af781e449
9 changed files with 469 additions and 17 deletions
+21 -7
View File
@@ -71,6 +71,20 @@ class StockAvailableCore extends ObjectModel
),
);
/**
* @see ObjectModel::$webserviceParameters
*/
protected $webserviceParameters = array(
'fields' => array(
'id_product' => array('xlink_resource' => 'products'),
'id_product_attribute' => array('xlink_resource' => 'combinations'),
'id_shop' => array('xlink_resource' => 'shops'),
'id_group_shop' => array('xlink_resource' => 'shop_groups'),
),
'hidden_fields' => array(
),
);
/**
* For a given {id_product, id_product_attribute and id_shop}, gets the stock available id associated
*
@@ -268,7 +282,7 @@ class StockAvailableCore extends ObjectModel
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)
@@ -276,24 +290,24 @@ class StockAvailableCore extends ObjectModel
if ($quantity > $value)
$quantity = $value;
}
// returns the number of pack available
return $quantity;
}
else // else
{
$query = new DbQuery();
$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);
}
}