From 5b058e672369874d5fc7a89209d5a2da911c0898 Mon Sep 17 00:00:00 2001 From: Arnaud Lemercier Date: Fri, 29 Mar 2013 10:26:44 +0100 Subject: [PATCH 1/2] Allow webservice to set the tags list of product when creating or updating a product --- classes/Product.php | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/classes/Product.php b/classes/Product.php index bbe6fd920..b1669b31a 100644 --- a/classes/Product.php +++ b/classes/Product.php @@ -4663,6 +4663,34 @@ class ProductCore extends ObjectModel FROM `'._DB_PREFIX_.'product_tag` WHERE `id_product` = '.(int)$this->id); } + + /** + * Webservice setter : set tag ids of current product for association + * + * @param $tag_ids tag ids + */ + public function setWsTags($tag_ids) + { + $ids = array(); + foreach ($tag_ids as $value) + $ids[] = $value['id']; + if ($this->deleteTags()) + { + if ($ids) + { + $sql_values = ''; + $ids = array_map('intval', $ids); + foreach ($ids as $position => $id) + $sql_values[] = '('.(int)$this->id.', '.(int)$id.')'; + $result = Db::getInstance()->execute(' + INSERT INTO `'._DB_PREFIX_.'product_tag` (`id_product`, `id_tag`) + VALUES '.implode(',', $sql_values) + ); + return $result; + } + } + return true; + } public function getWsManufacturerName() From 07979774f69630a42e5058f11044097755cc6fd4 Mon Sep 17 00:00:00 2001 From: Arnaud Lemercier Date: Tue, 2 Apr 2013 18:44:12 +0200 Subject: [PATCH 2/2] Delete products tags entries without delete tags for webservice usage --- classes/Product.php | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/classes/Product.php b/classes/Product.php index b1669b31a..c027d691d 100644 --- a/classes/Product.php +++ b/classes/Product.php @@ -4674,7 +4674,7 @@ class ProductCore extends ObjectModel $ids = array(); foreach ($tag_ids as $value) $ids[] = $value['id']; - if ($this->deleteTags()) + if ($this->deleteWsTags()) { if ($ids) { @@ -4690,7 +4690,17 @@ class ProductCore extends ObjectModel } } return true; - } + } + + /** + * Delete products tags entries without delete tags for webservice usage + * + * @return array Deletion result + */ + public function deleteWsTags() + { + return Db::getInstance()->delete('product_tag', 'id_product = '.(int)$this->id); + } public function getWsManufacturerName()