Skip to content

Commit f506905

Browse files
Merge pull request #30 from magmodules/release/1.10.2
Release/1.10.2
2 parents c3ef702 + 044d33a commit f506905

File tree

3 files changed

+30
-13
lines changed

3 files changed

+30
-13
lines changed

Service/WebApi/Product.php

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
use Magento\Catalog\Model\Product as ProductModel;
1111
use Magento\Catalog\Model\ResourceModel\Product\Collection;
1212
use Magento\Catalog\Model\ResourceModel\Product\CollectionFactory as ProductCollectionFactory;
13+
use Magento\Catalog\Api\Data\ProductAttributeInterface;
14+
use Magento\Eav\Api\AttributeRepositoryInterface;
1315
use Magento\Framework\Api\SearchCriteria\CollectionProcessorInterface;
1416
use Magento\Framework\Api\SearchCriteriaInterface;
1517
use Magento\Framework\UrlInterface;
@@ -19,7 +21,6 @@
1921
use Magmodules\Reloadify\Model\RequestLog\CollectionFactory as RequestLogCollectionFactory;
2022
use Magento\Catalog\Model\Product\Visibility;
2123
use Magento\Store\Model\StoreManagerInterface;
22-
use Magento\Catalog\Model\Product\Type;
2324

2425
/**
2526
* Product web API service class
@@ -69,6 +70,10 @@ class Product
6970
* @var StoreManagerInterface
7071
*/
7172
private $storeManager;
73+
/**
74+
* @var AttributeRepositoryInterface
75+
*/
76+
private $attributeRepository;
7277

7378
private $mediaPath = '';
7479

@@ -90,7 +95,8 @@ public function __construct(
9095
ConfigRepository $configRepository,
9196
CollectionProcessorInterface $collectionProcessor,
9297
Visibility $productVisibility,
93-
StoreManagerInterface $storeManager
98+
StoreManagerInterface $storeManager,
99+
AttributeRepositoryInterface $attributeRepository
94100
) {
95101
$this->productsCollectionFactory = $productsCollectionFactory;
96102
$this->reviewCollectionFactory = $reviewCollectionFactory;
@@ -99,6 +105,7 @@ public function __construct(
99105
$this->collectionProcessor = $collectionProcessor;
100106
$this->productVisibility = $productVisibility;
101107
$this->storeManager = $storeManager;
108+
$this->attributeRepository = $attributeRepository;
102109
}
103110

104111
/**
@@ -113,23 +120,33 @@ public function execute(int $storeId, array $extra = [], SearchCriteriaInterface
113120
$data = [];
114121
$collection = $this->getCollection($storeId, $extra, $searchCriteria);
115122
$ean = $this->configRepository->getEan($storeId);
123+
$eanType = $this->attributeRepository->get(ProductAttributeInterface::ENTITY_TYPE_CODE, $ean)
124+
->getFrontendInput();
116125
$name = $this->configRepository->getName($storeId);
126+
$nameType = $this->attributeRepository->get(ProductAttributeInterface::ENTITY_TYPE_CODE, $name)
127+
->getFrontendInput();
117128
$sku = $this->configRepository->getSku($storeId);
129+
$skuType = $this->attributeRepository->get(ProductAttributeInterface::ENTITY_TYPE_CODE, $sku)
130+
->getFrontendInput();
118131
$brand = $this->configRepository->getBrand($storeId);
132+
$brandType = $this->attributeRepository->get(ProductAttributeInterface::ENTITY_TYPE_CODE, $brand)
133+
->getFrontendInput();
119134
$description = $this->configRepository->getDescription($storeId);
135+
$descriptionType = $this->attributeRepository
136+
->get(ProductAttributeInterface::ENTITY_TYPE_CODE, $description)->getFrontendInput();
120137

121138
foreach ($collection as $product) {
122139
$data[] = [
123140
"id" => $product->getId(),
124-
"name" => $this->getAttributeValue($product, $name),
141+
"name" => $this->getAttributeValue($product, $name, $nameType),
125142
'product_type' => $product->getTypeId(),
126-
"ean" => $this->getAttributeValue($product, $ean),
143+
"ean" => $this->getAttributeValue($product, $ean, $eanType),
127144
"short_description" => $product->getShortDescription(),
128-
"description" => $this->getAttributeValue($product, $description),
145+
"description" => $this->getAttributeValue($product, $description, $descriptionType),
129146
"price" => $product->getPrice(),
130147
"url" => $product->getProductUrl(),
131-
"sku" => $this->getAttributeValue($product, $sku),
132-
"brand" => $this->getAttributeValue($product, $brand),
148+
"sku" => $this->getAttributeValue($product, $sku, $skuType),
149+
"brand" => $this->getAttributeValue($product, $brand, $brandType),
133150
"main_image" => $this->getMainImage($product),
134151
"visible" => (bool)((int)$product->getVisibility() - 1),
135152
"variant_ids" => $this->getVariants($product),
@@ -149,12 +166,12 @@ public function execute(int $storeId, array $extra = [], SearchCriteriaInterface
149166
* @param $attribute
150167
* @return mixed|string
151168
*/
152-
private function getAttributeValue($product, $attribute)
169+
private function getAttributeValue($product, $attribute, $type)
153170
{
154171
$value = '';
155-
if ($attribute) {
156-
if ($dropdownValue = $product->getAttributeText($attribute)) {
157-
$value = $dropdownValue;
172+
if ($attribute && $type) {
173+
if (($type == 'select') || ($type == 'multiselect')) {
174+
$value = $product->getAttributeText($attribute);
158175
} else {
159176
$value = $product->getData($attribute);
160177
}

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "magmodules/magento2-reloadify",
33
"description": "Reloadify extension for Magento 2",
44
"type": "magento2-module",
5-
"version": "1.10.1",
5+
"version": "1.10.2",
66
"license": [
77
"BSD-2-Clause"
88
],

etc/config.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
<default>
1111
<magmodules_reloadify>
1212
<general>
13-
<version>v1.10.1</version>
13+
<version>v1.10.2</version>
1414
<enable>0</enable>
1515
<debug>0</debug>
1616
</general>

0 commit comments

Comments
 (0)