Skip to content

Commit 6601ff0

Browse files
authored
Merge pull request #26 from landofcoder/feature8
Feature8
2 parents 3c0e437 + 14cb8b5 commit 6601ff0

File tree

4 files changed

+12
-26
lines changed

4 files changed

+12
-26
lines changed

Api/Data/TagInterface.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,5 +105,6 @@ public function getProducts();
105105
*/
106106
public function setProducts($products);
107107

108+
108109

109110
}

Model/Data/Tag.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,4 +156,5 @@ public function setProducts($products){
156156
return $this->setData("products", $products);
157157
}
158158

159+
159160
}

Model/TagRepository.php

Lines changed: 8 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ class TagRepository implements TagRepositoryInterface
3939

4040
private $collectionProcessor;
4141

42-
protected $extensibleDataObjectConverter;
4342

4443
/**
4544
* @param ResourceTag $resource
@@ -51,8 +50,6 @@ class TagRepository implements TagRepositoryInterface
5150
* @param DataObjectProcessor $dataObjectProcessor
5251
* @param StoreManagerInterface $storeManager
5352
* @param CollectionProcessorInterface $collectionProcessor
54-
* @param JoinProcessorInterface $extensionAttributesJoinProcessor
55-
* @param ExtensibleDataObjectConverter $extensibleDataObjectConverter
5653
*/
5754
public function __construct(
5855
ResourceTag $resource,
@@ -63,9 +60,7 @@ public function __construct(
6360
DataObjectHelper $dataObjectHelper,
6461
DataObjectProcessor $dataObjectProcessor,
6562
StoreManagerInterface $storeManager,
66-
CollectionProcessorInterface $collectionProcessor,
67-
JoinProcessorInterface $extensionAttributesJoinProcessor,
68-
ExtensibleDataObjectConverter $extensibleDataObjectConverter
63+
CollectionProcessorInterface $collectionProcessor
6964
) {
7065
$this->resource = $resource;
7166
$this->tagFactory = $tagFactory;
@@ -76,8 +71,6 @@ public function __construct(
7671
$this->dataObjectProcessor = $dataObjectProcessor;
7772
$this->storeManager = $storeManager;
7873
$this->collectionProcessor = $collectionProcessor;
79-
$this->extensionAttributesJoinProcessor = $extensionAttributesJoinProcessor;
80-
$this->extensibleDataObjectConverter = $extensibleDataObjectConverter;
8174
}
8275

8376
/**
@@ -93,14 +86,14 @@ public function save($tagData){
9386
if($tagData->getTagId()){
9487
$tagModel->load((int)$tagData->getTagId());
9588
}
96-
$this->resource->save($tagData);
89+
$tagModel->setData((array)$tagData);
9790

9891
if ($products = $tagData->getProducts()) {
9992
$tagModel->setPostedProducts($products);
10093
}
10194

10295
try {
103-
$this->resource->save($tagData);
96+
$tagModel->setData((array)$tagData);
10497
} catch (\Exception $exception) {
10598
throw new CouldNotSaveException(__(
10699
'Could not save the tag: %1',
@@ -130,23 +123,14 @@ public function getList(
130123
\Magento\Framework\Api\SearchCriteriaInterface $criteria
131124
) {
132125
$collection = $this->tagCollectionFactory->create();
133-
134-
$this->extensionAttributesJoinProcessor->process(
135-
$collection,
136-
\Lof\ProductTags\Api\Data\TagInterface::class
137-
);
138-
126+
139127
$this->collectionProcessor->process($criteria, $collection);
140-
128+
//$collection->load();
129+
141130
$searchResults = $this->searchResultsFactory->create();
142131
$searchResults->setSearchCriteria($criteria);
143132

144-
$items = [];
145-
foreach ($collection as $model) {
146-
$items[] = $model->getDataModel();
147-
}
148-
149-
$searchResults->setItems($items);
133+
$searchResults->setItems($collection->getItems());
150134
$searchResults->setTotalCount($collection->getSize());
151135
return $searchResults;
152136
}
@@ -157,7 +141,7 @@ public function getList(
157141
public function delete($tagId) {
158142
try {
159143
$tagModel = $this->tagFactory->create();
160-
// secelt * from table where `tag_id` = $tagId
144+
// select * from table where `tag_id` = $tagId
161145
$tagModel->load($tagId);
162146
// $tagModel->getCollection()->addFieldToFilter('tag_id',$tagId);
163147
$tagModel->delete();

etc/webapi.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" ?>
22
<routes xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Webapi:etc/webapi.xsd">
3-
<route method="GET" url="/V1/lof-producttags/tags">
3+
<route method="POST" url="/V1/lof-producttags/tags">
44
<service class="Lof\ProductTags\Api\TagsManagementInterface" method="getTags"/>
55
<resources>
66
<resource ref="anonymous"/>
@@ -18,7 +18,7 @@
1818
<resource ref="Lof_ProductTags::Tag_add"/>
1919
</resources>
2020
</route>
21-
<route method="POST" url="/V1/lof-producttags/tag/search">
21+
<route method="GET" url="/V1/lof-producttags/tags">
2222
<service class="Lof\ProductTags\Api\TagRepositoryInterface" method="getList"/>
2323
<resources>
2424
<resource ref="Lof_ProductTags::Tag_view"/>

0 commit comments

Comments
 (0)