From 6a6cc86c11180434ddfabe0860dec874e6cb4e9c Mon Sep 17 00:00:00 2001 From: rGaillard Date: Tue, 25 Sep 2012 10:11:51 +0000 Subject: [PATCH] [*] WS: management of stockavailables --- classes/Product.php | 15 +++++++++++++++ classes/stock/StockAvailable.php | 14 +++++++++++++- classes/webservice/WebserviceRequest.php | 4 ++-- 3 files changed, 30 insertions(+), 3 deletions(-) diff --git a/classes/Product.php b/classes/Product.php index 2958d0ec8..e5ba48b79 100644 --- a/classes/Product.php +++ b/classes/Product.php @@ -301,6 +301,7 @@ class ProductCore extends ObjectModel 'default_category' => array('type' => self::HAS_ONE, 'field' => 'id_category_default', 'object' => 'Category'), 'tax_rules_group' => array('type' => self::HAS_ONE), '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( '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`'); } + 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() { return Db::getInstance()->executeS(' diff --git a/classes/stock/StockAvailable.php b/classes/stock/StockAvailable.php index 88c9a4c3c..0db8a5c79 100644 --- a/classes/stock/StockAvailable.php +++ b/classes/stock/StockAvailable.php @@ -83,6 +83,10 @@ class StockAvailableCore extends ObjectModel ), 'hidden_fields' => array( ), + 'objectMethods' => array( + 'add' => 'addWs', + 'update' => 'updateWs', + ), ); /** @@ -93,6 +97,14 @@ class StockAvailableCore extends ObjectModel * @param int $id_shop Optional * @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) { if (!Validate::isUnsignedId($id_product)) @@ -361,7 +373,7 @@ class StockAvailableCore extends ObjectModel { if (!parent::update($null_values)) return false; - $this->postSave(); + return $this->postSave(); } /** diff --git a/classes/webservice/WebserviceRequest.php b/classes/webservice/WebserviceRequest.php index 0f0704055..c07429242 100644 --- a/classes/webservice/WebserviceRequest.php +++ b/classes/webservice/WebserviceRequest.php @@ -269,7 +269,7 @@ class WebserviceRequestCore 'stock_movement_reasons' => array('description' => 'Stock movement reason', 'class' => 'StockMvtReason'), 'warehouses' => array('description' => 'Warehouses', 'class' => 'Warehouse', 'forbidden_method' => array('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')), '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')), @@ -1537,7 +1537,7 @@ class WebserviceRequestCore } } $assoc = Shop::getAssoTable($this->resourceConfiguration['retrieveData']['table']); - if ($assoc !== false) + if ($assoc !== false && $assoc['type'] != 'fk_shop') { // 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 ';