From aaaa5cb08625832df4a070b2059829ac4605edc1 Mon Sep 17 00:00:00 2001 From: gRoussac Date: Wed, 24 Jul 2013 18:22:04 +0200 Subject: [PATCH] [-] WS: Enable feature request #PSCFV-5581, thanks @codl for pull request #593 --- classes/Product.php | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/classes/Product.php b/classes/Product.php index e8de1bc3e..9b73d0dec 100644 --- a/classes/Product.php +++ b/classes/Product.php @@ -364,7 +364,7 @@ class ProductCore extends ObjectModel ), 'type' => array( 'getter' => 'getWsType', - 'setter' => false, + 'setter' => 'setWsType', ), ), 'associations' => array( @@ -5346,4 +5346,38 @@ class ProductCore extends ObjectModel { return Db::getInstance()->executeS('SELECT id_product_item as id, quantity FROM '._DB_PREFIX_.'pack WHERE id_product_pack = '.(int)$this->id); } + + public function setWsType($type_str) + { + $reverse_type_information = array( + 'simple' => Product::PTYPE_SIMPLE, + 'pack' => Product::PTYPE_PACK, + 'virtual' => Product::PTYPE_VIRTUAL, + ); + + if (!isset($reverse_type_information[$type_str])) + return false; + + $type = $reverse_type_information[$type_str]; + + if (Pack::isPack((int)$this->id) && $type != Product::PTYPE_PACK) + Pack::deleteItems($this->id); + + $this->cache_is_pack = ($type == Product::PTYPE_PACK); + $this->is_virtual = ($type == Product::PTYPE_VIRTUAL); + + return true; + } + + public function setWsProductBundle($items) + { + if($this->is_virtual) + return false; + + Pack::deleteItems($this->id); + + foreach ($items as $item) + Pack::addItem($this->id, (int)$item['id'], (int)$item['quantity']); + return true; + } } \ No newline at end of file