// Webservice: Stock
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user