@@ -83,19 +83,22 @@ public function __construct(
8383 /**
8484 * {@inheritdoc}
8585 */
86- public function save (\Lof \ProductTags \Api \Data \TagInterface $ tagData ) {
86+ public function save ($ tagData ){
87+
8788 if (empty ($ tagData ->getStoreId ())) {
8889 $ storeId = $ this ->storeManager ->getStore ()->getId ();
8990 $ tagData ->setStoreId ($ storeId );
9091 }
9192 $ tagModel = $ this ->tagFactory ->create ();
92- $ tagModel ->setData ($ tagData );
9393 if ($ tagData ->getTagId ()){
9494 $ tagModel ->load ((int )$ tagData ->getTagId ());
9595 }
96+ $ tagModel ->setData ($ tagData );
97+
9698 if ($ products = $ tagData ->getProducts ()) {
9799 $ tagModel ->setPostedProducts ($ products );
98100 }
101+
99102 try {
100103 $ this ->resource ->save ($ tagModel );
101104 } catch (\Exception $ exception ) {
@@ -104,7 +107,7 @@ public function save(\Lof\ProductTags\Api\Data\TagInterface $tagData) {
104107 $ exception ->getMessage ()
105108 ));
106109 }
107- return $ tagModel -> getDataModel () ;
110+ return $ tagData ;
108111 }
109112
110113 /**
@@ -117,7 +120,7 @@ public function getById($tagId)
117120 if (!$ tagModel ->getId ()) {
118121 throw new NoSuchEntityException (__ ('Tag with id "%1" does not exist. ' , $ tagId ));
119122 }
120- return $ tagModel ->getDataModel ();
123+ return $ tagModel ->getData ();
121124 }
122125
123126 /**
@@ -151,12 +154,12 @@ public function getList(
151154 /**
152155 * {@inheritdoc}
153156 */
154- public function delete (
155- \Lof \ProductTags \Api \Data \TagInterface $ tag
156- ) {
157+ public function delete ($ tagId ) {
157158 try {
158159 $ tagModel = $ this ->tagFactory ->create ();
159- $ tagModel ->load ($ tag ->getTagId ());
160+ // secelt * from table where `tag_id` = $tagId
161+ $ tagModel ->load ($ tagId );
162+ // $tagModel->getCollection()->addFieldToFilter('tag_id',$tagId);
160163 $ tagModel ->delete ();
161164 } catch (\Exception $ exception ) {
162165 throw new CouldNotDeleteException (__ (
@@ -173,7 +176,7 @@ public function delete(
173176 public function deleteById ($ tagId )
174177 {
175178 $ tagData = $ this ->getById ($ tagId );
176- return $ this ->delete ($ tagData );
179+ return $ this ->delete ($ tagId );
177180 }
178181
179182 /**
0 commit comments