Skip to content

Commit 82e3047

Browse files
committed
update API create new tag and update tag
1 parent ee7ff67 commit 82e3047

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

Model/ResourceModel/Tag.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ protected function _construct()
2222
* @return $this
2323
* @throws LocalizedException
2424
*/
25-
protected function _afterSave(AbstractModel $object)
25+
protected function _afterSave($tag)
2626
{
27-
$this->_saveTagProducts($object);
28-
$this->_saveTagStores($object);
29-
return parent::_afterSave($object);
27+
$this->_saveTagProducts($tag);
28+
$this->_saveTagStores($tag);
29+
return parent::_afterSave($tag);
3030
}
3131

3232
public function getTagProductTable()
@@ -129,10 +129,10 @@ protected function _saveTagProducts($tag)
129129
}
130130
protected function _saveTagStores($tag)
131131
{
132-
$oldStores = $this->lookupStoreIds($object->getId());
133-
$newStores = (array)$object->getStores();
132+
$oldStores = $this->lookupStoreIds($tag->getId());
133+
$newStores = (array)$tag->getStores();
134134
if (empty($newStores)) {
135-
$newStores = (array)$object->getStoreId();
135+
$newStores = (array)$tag->getStoreId();
136136
}
137137
$table = $this->getTable('lof_producttags_store');
138138
$insert = array_diff($newStores, $oldStores);
@@ -144,7 +144,7 @@ protected function _saveTagStores($tag)
144144
if ($insert) {
145145
$data = [];
146146
foreach ($insert as $storeId) {
147-
$data[] = ['tag_id' => (int)$object->getId(), 'store_id' => (int)$storeId];
147+
$data[] = ['tag_id' => (int)$tag->getId(), 'store_id' => (int)$storeId];
148148
}
149149
$this->getConnection()->insertMultiple($table, $data);
150150
}

Model/TagRepository.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,15 +85,15 @@ public function __construct(
8585
*/
8686
public function save($tagData){
8787

88-
if (empty($tagData->getStoreId())) {
88+
if (empty($tagData->getStoreId())) {
8989
$storeId = $this->storeManager->getStore()->getId();
9090
$tagData->setStoreId($storeId);
9191
}
9292
$tagModel = $this->tagFactory->create();
9393
if($tagData->getTagId()){
9494
$tagModel->load((int)$tagData->getTagId());
9595
}
96-
$tagModel->setData($tagData);
96+
$this->resource->save($tagData);
9797

9898
if ($products = $tagData->getProducts()) {
9999
$tagModel->setPostedProducts($products);

0 commit comments

Comments
 (0)