Skip to content

Commit 879af75

Browse files
committed
update API
1 parent ff563e9 commit 879af75

File tree

6 files changed

+21
-57
lines changed

6 files changed

+21
-57
lines changed

Api/Data/TagInterface.php

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -94,29 +94,16 @@ public function setStoreId($storeId);
9494
/**
9595
* Set products
9696
*
97-
* @return string[]
97+
* @return string[]|null
9898
*/
9999
public function getProducts();
100100
/**
101101
* Set products
102102
*
103-
* @param string[]
103+
* @param string[]|null
104104
* @return $this
105105
*/
106106
public function setProducts($products);
107107

108-
/**
109-
* Retrieve existing extension attributes object or create a new one.
110-
* @return \Lof\ProductTags\Api\Data\TagExtensionInterface|null
111-
*/
112-
// public function getExtensionAttributes();
113-
114-
// /**
115-
// * Set an extension attributes object.
116-
// * @param \Lof\ProductTags\Api\Data\TagExtensionInterface $extensionAttributes
117-
// * @return $this
118-
// */
119-
// public function setExtensionAttributes(
120-
// \Lof\ProductTags\Api\Data\TagExtensionInterface $extensionAttributes
121-
// );
108+
122109
}

Api/TagRepositoryInterface.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,11 @@ public function getList(
5656

5757
/**
5858
* Delete Tag
59-
* @param \Lof\ProductTags\Api\Data\TagInterface $tag
59+
* @param bool $tagId
6060
* @return bool true on success
6161
* @throws \Magento\Framework\Exception\LocalizedException
6262
*/
63-
public function delete(
64-
\Lof\ProductTags\Api\Data\TagInterface $tag
65-
);
63+
public function delete($tagId);
6664

6765
/**
6866
* Delete Tag by ID

Model/Data/Tag.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,15 +141,15 @@ public function setStoreId($storeId){
141141
/**
142142
* Set products
143143
*
144-
* @return array|null
144+
* @return string[]|null
145145
*/
146146
public function getProducts(){
147147
return $this->_get("products");
148148
}
149149
/**
150150
* Set products
151151
*
152-
* @param array|null
152+
* @param string[]|null
153153
* @return $this
154154
*/
155155
public function setProducts($products){

Model/ResourceModel/Tag.php

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ protected function _afterSave(AbstractModel $object)
2626
{
2727
$this->_saveTagProducts($object);
2828
$this->_saveTagStores($object);
29-
$this->_saveTagStores($object);
3029
return parent::_afterSave($object);
3130
}
3231

@@ -151,31 +150,7 @@ protected function _saveTagStores($tag)
151150
}
152151
return $this;
153152
}
154-
// protected function _saveTagTag($tag)
155-
// {
156-
// $oldTag = $this->lookupTagIds($object->getId());
157-
// $newTag = (array)$object->getTag();
158-
// if (empty($newTag)) {
159-
// $newTag = (array)$object->getTagId();
160-
// }
161-
// $table = $this->getTable('lof_producttags_tag');
162-
// $insert = array_diff($newTag, $oldTag);
163-
// $delete = array_diff($oldTag, $newTag);
164-
// if ($delete) {
165-
// $where = ['tag_id = ?' => (int)$object->getId(), 'store_id IN (?)' => $delete];
166-
// $this->getConnection()->delete($table, $where);
167-
// }
168-
// if ($insert) {
169-
// $data = [];
170-
// foreach ($insert as $tagId) {
171-
// $data[] = ['tag_id' => (int)$tagId, 'tag_title' => (int)$object->getTagTitle(), 'status' => (bool)$object->getStatus(),
172-
// 'identifier' => (string)$object->getIdentifier(), 'tag_title' => (int)$object->getTagTitle(),
173-
// 'tag_description' => (string)$object->getTagDescription()];
174-
// }
175-
// $this->getConnection()->insertMultiple($table, $data);
176-
// }
177-
// return $this;
178-
// }
153+
179154

180155

181156
/**

Model/TagRepository.php

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -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
/**

etc/di.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
<preference for="Lof\ProductTags\Api\TagsManagementInterface" type="Lof\ProductTags\Model\TagsManagement"/>
44
<preference for="Lof\ProductTags\Api\ProductsManagementInterface" type="Lof\ProductTags\Model\ProductsManagement"/>
55
<preference for="Lof\ProductTags\Api\TagRepositoryInterface" type="Lof\ProductTags\Model\TagRepository"/>
6+
<preference for="Lof\ProductTags\Api\Data\TagInterface" type="Lof\ProductTags\Model\TagRepository"/>
67
<preference for="Lof\ProductTags\Api\Data\TagInterface" type="Lof\ProductTags\Model\Tag"/>
78
<preference for="Lof\ProductTags\Api\Data\TagSearchResultsInterface" type="Magento\Framework\Api\SearchResults"/>
89
<virtualType name="Lof\ProductTags\Model\ResourceModel\Tag\Grid\Collection" type="Magento\Framework\View\Element\UiComponent\DataProvider\SearchResult">

0 commit comments

Comments
 (0)