Skip to content

Commit a947adb

Browse files
Merge pull request #8 from magmodules/release/1.5.0
Release/1.5.0
2 parents 17df21e + f837b46 commit a947adb

File tree

9 files changed

+87
-10
lines changed

9 files changed

+87
-10
lines changed

Api/Config/RepositoryInterface.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ interface RepositoryInterface
2626
public const XML_PATH_EAN = '%s/attributes/ean';
2727
public const XML_PATH_NAME = '%s/attributes/name';
2828
public const XML_PATH_SKU = '%s/attributes/sku';
29+
public const XML_PATH_BRAND = '%s/attributes/brand';
2930

3031
/**
3132
* Get extension version
@@ -93,6 +94,15 @@ public function getName(int $storeId = null): string;
9394
*/
9495
public function getSku(int $storeId = null): string;
9596

97+
/**
98+
* Get brand attribute
99+
*
100+
* @param int|null $storeId
101+
*
102+
* @return string
103+
*/
104+
public function getBrand(int $storeId = null): string;
105+
96106
/**
97107
* Get current store
98108
*

Model/Config/Repository.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,4 +220,17 @@ public function getSku(int $storeId = null): string
220220
$scope
221221
);
222222
}
223+
224+
/**
225+
* @inheritDoc
226+
*/
227+
public function getBrand(int $storeId = null): string
228+
{
229+
$scope = $scope ?? ScopeInterface::SCOPE_STORE;
230+
return (string)$this->getStoreValue(
231+
self::XML_PATH_BRAND,
232+
$storeId,
233+
$scope
234+
);
235+
}
223236
}

Service/WebApi/Product.php

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,15 +98,21 @@ public function execute(int $storeId, array $extra = [], SearchCriteriaInterface
9898
{
9999
$data = [];
100100
$collection = $this->getCollection($storeId, $extra, $searchCriteria);
101+
$ean = $this->configRepository->getEan($storeId);
101102
$name = $this->configRepository->getName($storeId);
103+
$sku = $this->configRepository->getSku($storeId);
104+
$brand = $this->configRepository->getBrand($storeId);
102105

103106
foreach ($collection as $product) {
104107
$data[] = [
105108
"id" => $product->getId(),
106-
"name" => ($name) ? $product->getData($name) : '',
109+
"name" => $this->getAttributeValue($product, $name),
110+
"ean" => $this->getAttributeValue($product, $ean),
107111
"short_description" => $product->getShortDescription(),
108112
"price" => $product->getPrice(),
109113
"url" => $product->getProductUrl(),
114+
"sku" => $this->getAttributeValue($product, $sku),
115+
"brand" => $this->getAttributeValue($product, $brand),
110116
"main_image" => $this->getMainImage($product),
111117
"visible" => (bool)((int)$product->getVisibility() - 1),
112118
"variant_ids" => $this->getVariants($product),
@@ -121,6 +127,24 @@ public function execute(int $storeId, array $extra = [], SearchCriteriaInterface
121127
return $data;
122128
}
123129

130+
/**
131+
* @param $product
132+
* @param $attribute
133+
* @return mixed|string
134+
*/
135+
private function getAttributeValue($product, $attribute)
136+
{
137+
$value = '';
138+
if ($attribute) {
139+
if ($dropdownValue = $product->getAttributeText($attribute)) {
140+
$value = $dropdownValue;
141+
} else {
142+
$value = $product->getData($attribute);
143+
}
144+
}
145+
return $value;
146+
}
147+
124148
/**
125149
* @param int $storeId
126150
* @param array $extra

Service/WebApi/Review.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@ class Review
2929
"name" => 'title',
3030
"product_id" => 'entity_pk_value',
3131
"profile_id" => 'customer_id',
32-
"created_at" => 'created_at',
33-
"updated_at" => 'created_at'
32+
"created_at" => 'created_at'
3433
];
3534

3635
/**
@@ -88,8 +87,7 @@ public function execute(int $storeId, array $extra = [], SearchCriteriaInterface
8887
"visible" => $review->getStatusId() == 1,
8988
"product_id" => $review->getEntityPkValue(),
9089
"profile" => $this->getProfileData($review),
91-
"created_at" => $review->getCreatedAt(),
92-
"updated_at" => $review->getCreatedAt()
90+
"created_at" => $review->getCreatedAt()
9391
];
9492
}
9593

Service/WebApi/Variants.php

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ public function execute(int $storeId, array $extra = [], SearchCriteriaInterface
101101
$ean = $this->configRepository->getEan($storeId);
102102
$name = $this->configRepository->getName($storeId);
103103
$sku = $this->configRepository->getSku($storeId);
104+
$brand = $this->configRepository->getBrand($storeId);
104105

105106
$data = [];
106107
$collection = $this->getCollection($storeId, $extra, $searchCriteria);
@@ -112,15 +113,16 @@ public function execute(int $storeId, array $extra = [], SearchCriteriaInterface
112113
}
113114
$data[] = [
114115
"id" => $product->getId(),
115-
"title" => ($name) ? $product->getData($name) : '',
116+
"title" => $this->getAttributeValue($product, $name),
116117
"article_code" => $product->getSku(),
117-
"ean" => ($ean) ? $product->getData($ean) : '',
118+
"ean" => $this->getAttributeValue($product, $ean),
118119
"main_image" => $this->getMainImage($product),
119120
"price_cost" => $product->getCost(),
120121
"price_excl" => $product->getPrice(),
121122
"price_incl" => $product->getPrice(),
122123
"unit_price" => $product->getPrice(),
123-
"sku" => ($sku) ? $product->getData($sku) : '',
124+
"sku" => $this->getAttributeValue($product, $sku),
125+
"brand" => $this->getAttributeValue($product, $brand),
124126
"stock_level" => $this->getStockLevel($product, $stockData, $websiteId),
125127
"product_id" => $productIds[$product->getId()],
126128
"created_at" => $product->getCreatedAt(),
@@ -130,6 +132,24 @@ public function execute(int $storeId, array $extra = [], SearchCriteriaInterface
130132
return $data;
131133
}
132134

135+
/**
136+
* @param $product
137+
* @param $attribute
138+
* @return mixed|string
139+
*/
140+
private function getAttributeValue($product, $attribute)
141+
{
142+
$value = '';
143+
if ($attribute) {
144+
if ($dropdownValue = $product->getAttributeText($attribute)) {
145+
$value = $dropdownValue;
146+
} else {
147+
$value = $product->getData($attribute);
148+
}
149+
}
150+
return $value;
151+
}
152+
133153
/**
134154
* @param int|null $entityId
135155
*

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.4.0",
5+
"version": "1.5.0",
66
"license": [
77
"BSD-2-Clause"
88
],

etc/adminhtml/system/attributes.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,12 @@
3131
<config_path>magmodules_reloadify/attributes/sku</config_path>
3232
<comment>Select the attribute associate with the product SKU. Suggested field: SKU</comment>
3333
</field>
34+
<field id="brand" translate="label comment" type="select" sortOrder="70" showInDefault="1"
35+
showInWebsite="1" showInStore="1">
36+
<label>Brand</label>
37+
<source_model>Magmodules\Reloadify\Model\Config\Source\Attributes</source_model>
38+
<config_path>magmodules_reloadify/attributes/brand</config_path>
39+
<comment>Select the attribute associate with the product brand. Suggested field: Manufacturer</comment>
40+
</field>
3441
</group>
3542
</include>

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.4.0</version>
13+
<version>v1.5.0</version>
1414
<enable>0</enable>
1515
<debug>0</debug>
1616
<ean>sku</ean>

etc/di.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,4 +70,9 @@
7070
</type>
7171
<!-- Command line block end -->
7272

73+
<type name="Magmodules\Reloadify\Service\WebApi\Product">
74+
<arguments>
75+
<argument name="collectionProcessor" xsi:type="object">Magento\Catalog\Model\Api\SearchCriteria\ProductCollectionProcessor</argument>
76+
</arguments>
77+
</type>
7378
</config>

0 commit comments

Comments
 (0)