[*] WS: management of stockavailables
This commit is contained in:
@@ -301,6 +301,7 @@ class ProductCore extends ObjectModel
|
|||||||
'default_category' => array('type' => self::HAS_ONE, 'field' => 'id_category_default', 'object' => 'Category'),
|
'default_category' => array('type' => self::HAS_ONE, 'field' => 'id_category_default', 'object' => 'Category'),
|
||||||
'tax_rules_group' => array('type' => self::HAS_ONE),
|
'tax_rules_group' => array('type' => self::HAS_ONE),
|
||||||
'categories' => array('type' => self::HAS_MANY, 'field' => 'id_category', 'object' => 'Category', 'association' => 'category_product'),
|
'categories' => array('type' => self::HAS_MANY, 'field' => 'id_category', 'object' => 'Category', 'association' => 'category_product'),
|
||||||
|
'stock_availables' => array('type' => self::HAS_MANY, 'field' => 'id_stock_available', 'object' => 'StockAvailable', 'association' => 'stock_availables'),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -392,6 +393,13 @@ class ProductCore extends ObjectModel
|
|||||||
'fields' => array(
|
'fields' => array(
|
||||||
'id' => array('required' => true),
|
'id' => array('required' => true),
|
||||||
)),
|
)),
|
||||||
|
'stock_availables' => array('resource' => 'stock_available',
|
||||||
|
'fields' => array(
|
||||||
|
'id' => array('required' => true),
|
||||||
|
'id_product_attribute' => array('required' => true),
|
||||||
|
),
|
||||||
|
'setter' => false
|
||||||
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -4460,6 +4468,13 @@ class ProductCore extends ObjectModel
|
|||||||
ORDER BY i.`position`');
|
ORDER BY i.`position`');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getWsStockAvailables()
|
||||||
|
{
|
||||||
|
return Db::getInstance()->executeS('SELECT `id_stock_available` id, `id_product_attribute`
|
||||||
|
FROM `'._DB_PREFIX_.'stock_available`
|
||||||
|
WHERE `id_product`='.($this->id).StockAvailable::addSqlShopRestriction());
|
||||||
|
}
|
||||||
|
|
||||||
public function getWsTags()
|
public function getWsTags()
|
||||||
{
|
{
|
||||||
return Db::getInstance()->executeS('
|
return Db::getInstance()->executeS('
|
||||||
|
|||||||
@@ -83,6 +83,10 @@ class StockAvailableCore extends ObjectModel
|
|||||||
),
|
),
|
||||||
'hidden_fields' => array(
|
'hidden_fields' => array(
|
||||||
),
|
),
|
||||||
|
'objectMethods' => array(
|
||||||
|
'add' => 'addWs',
|
||||||
|
'update' => 'updateWs',
|
||||||
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -93,6 +97,14 @@ class StockAvailableCore extends ObjectModel
|
|||||||
* @param int $id_shop Optional
|
* @param int $id_shop Optional
|
||||||
* @return int
|
* @return int
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
public function updateWs()
|
||||||
|
{
|
||||||
|
if ($this->depends_on_stock)
|
||||||
|
return WebserviceRequest::getInstance()->setError(500, Tools::displayError('You can\'t update stock available when it\'s depend on stock'));
|
||||||
|
return $this->update();
|
||||||
|
}
|
||||||
|
|
||||||
public static function getStockAvailableIdByProductId($id_product, $id_product_attribute = null, $id_shop = null)
|
public static function getStockAvailableIdByProductId($id_product, $id_product_attribute = null, $id_shop = null)
|
||||||
{
|
{
|
||||||
if (!Validate::isUnsignedId($id_product))
|
if (!Validate::isUnsignedId($id_product))
|
||||||
@@ -361,7 +373,7 @@ class StockAvailableCore extends ObjectModel
|
|||||||
{
|
{
|
||||||
if (!parent::update($null_values))
|
if (!parent::update($null_values))
|
||||||
return false;
|
return false;
|
||||||
$this->postSave();
|
return $this->postSave();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -269,7 +269,7 @@ class WebserviceRequestCore
|
|||||||
'stock_movement_reasons' => array('description' => 'Stock movement reason', 'class' => 'StockMvtReason'),
|
'stock_movement_reasons' => array('description' => 'Stock movement reason', 'class' => 'StockMvtReason'),
|
||||||
'warehouses' => array('description' => 'Warehouses', 'class' => 'Warehouse', 'forbidden_method' => array('DELETE')),
|
'warehouses' => array('description' => 'Warehouses', 'class' => 'Warehouse', 'forbidden_method' => array('DELETE')),
|
||||||
'stocks' => array('description' => 'Stocks', 'class' => 'Stock', 'forbidden_method' => array('PUT', 'POST', 'DELETE')),
|
'stocks' => array('description' => 'Stocks', 'class' => 'Stock', 'forbidden_method' => array('PUT', 'POST', 'DELETE')),
|
||||||
'stock_availables' => array('description' => 'Available quantities', 'class' => 'StockAvailable', 'forbidden_method' => array('PUT', 'POST', 'DELETE')),
|
'stock_availables' => array('description' => 'Available quantities', 'class' => 'StockAvailable', 'forbidden_method' => array('POST', 'DELETE')),
|
||||||
'warehouse_product_locations' => array('description' => 'Location of products in warehouses', 'class' => 'WarehouseProductLocation', 'forbidden_method' => array('PUT', 'POST', 'DELETE')),
|
'warehouse_product_locations' => array('description' => 'Location of products in warehouses', 'class' => 'WarehouseProductLocation', 'forbidden_method' => array('PUT', 'POST', 'DELETE')),
|
||||||
'supply_orders' => array('description' => 'Supply Orders', 'class' => 'SupplyOrder', 'forbidden_method' => array('PUT', 'POST', 'DELETE')),
|
'supply_orders' => array('description' => 'Supply Orders', 'class' => 'SupplyOrder', 'forbidden_method' => array('PUT', 'POST', 'DELETE')),
|
||||||
'supply_order_details' => array('description' => 'Supply Order Details', 'class' => 'SupplyOrderDetail', 'forbidden_method' => array('PUT', 'POST', 'DELETE')),
|
'supply_order_details' => array('description' => 'Supply Order Details', 'class' => 'SupplyOrderDetail', 'forbidden_method' => array('PUT', 'POST', 'DELETE')),
|
||||||
@@ -1537,7 +1537,7 @@ class WebserviceRequestCore
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
$assoc = Shop::getAssoTable($this->resourceConfiguration['retrieveData']['table']);
|
$assoc = Shop::getAssoTable($this->resourceConfiguration['retrieveData']['table']);
|
||||||
if ($assoc !== false)
|
if ($assoc !== false && $assoc['type'] != 'fk_shop')
|
||||||
{
|
{
|
||||||
// PUT nor POST is destructive, no deletion
|
// PUT nor POST is destructive, no deletion
|
||||||
$sql = 'INSERT IGNORE INTO `'.bqSQL(_DB_PREFIX_.$this->resourceConfiguration['retrieveData']['table'].'_'.$assoc['type']).'` (id_shop, '.pSQL($this->resourceConfiguration['fields']['id']['sqlId']).') VALUES ';
|
$sql = 'INSERT IGNORE INTO `'.bqSQL(_DB_PREFIX_.$this->resourceConfiguration['retrieveData']['table'].'_'.$assoc['type']).'` (id_shop, '.pSQL($this->resourceConfiguration['fields']['id']['sqlId']).') VALUES ';
|
||||||
|
|||||||
Reference in New Issue
Block a user