Skip to content

Commit af7c81d

Browse files
Merge pull request #26 from magmodules/release/1.8.0
Release/1.8.0
2 parents 3e8c265 + 19e8d43 commit af7c81d

File tree

9 files changed

+106
-32
lines changed

9 files changed

+106
-32
lines changed

Api/Config/RepositoryInterface.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ interface RepositoryInterface
2727
public const XML_PATH_NAME = '%s/attributes/name';
2828
public const XML_PATH_SKU = '%s/attributes/sku';
2929
public const XML_PATH_BRAND = '%s/attributes/brand';
30+
public const XML_PATH_DESCRIPTION = '%s/attributes/description';
3031

3132
/**
3233
* Get extension version
@@ -103,6 +104,15 @@ public function getSku(int $storeId = null): string;
103104
*/
104105
public function getBrand(int $storeId = null): string;
105106

107+
/**
108+
* Get description attribute
109+
*
110+
* @param int|null $storeId
111+
*
112+
* @return string
113+
*/
114+
public function getDescription(int $storeId = null): string;
115+
106116
/**
107117
* Get current store
108118
*

Model/Config/Repository.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,4 +219,16 @@ public function getBrand(int $storeId = null): string
219219
ScopeInterface::SCOPE_STORE
220220
);
221221
}
222+
223+
/**
224+
* @inheritDoc
225+
*/
226+
public function getDescription(int $storeId = null): string
227+
{
228+
return (string)$this->getStoreValue(
229+
self::XML_PATH_DESCRIPTION,
230+
$storeId,
231+
ScopeInterface::SCOPE_STORE
232+
);
233+
}
222234
}

Service/WebApi/Cart.php

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,10 +210,25 @@ private function getProducts(Quote $quote)
210210
$quoteProducts = [];
211211
/* @var Item $item */
212212
foreach ($quote->getAllItems() as $item) {
213-
$quoteProducts[] = [
213+
//skip variants
214+
if ($item->getParentItem() && $item->getParentItem()->getProductType() == 'configurable') {
215+
continue;
216+
}
217+
218+
$quoteProduct = [
214219
'id' => $item->getProductId(),
215220
'quantity' => $item->getQty()
216221
];
222+
223+
//add variant to parent data
224+
if ($item->getProductType() == 'configurable') {
225+
$child = $item->getChildren();
226+
if (count($child) != 0) {
227+
$child = reset($child);
228+
$quoteProduct['variant_id'] = $child->getProductId();
229+
}
230+
}
231+
$quoteProducts[] = $quoteProduct;
217232
}
218233
return $quoteProducts;
219234
}

Service/WebApi/Order.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,11 @@ private function getProducts(OrderModel $order): array
153153
{
154154
$orderedProducts = [];
155155
foreach ($order->getAllItems() as $item) {
156+
//skip variants
157+
if ($item->getParentItem() && $item->getParentItem()->getProductType() == 'configurable') {
158+
continue;
159+
}
160+
156161
$orderedProduct = [
157162
'id' => $item->getProductId(),
158163
'quantity' => $item->getQtyOrdered(),

Service/WebApi/Product.php

Lines changed: 35 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,18 @@
77

88
namespace Magmodules\Reloadify\Service\WebApi;
99

10-
use Magento\Catalog\Helper\Image;
1110
use Magento\Catalog\Model\Product as ProductModel;
1211
use Magento\Catalog\Model\ResourceModel\Product\Collection;
1312
use Magento\Catalog\Model\ResourceModel\Product\CollectionFactory as ProductCollectionFactory;
1413
use Magento\Framework\Api\SearchCriteria\CollectionProcessorInterface;
1514
use Magento\Framework\Api\SearchCriteriaInterface;
15+
use Magento\Framework\UrlInterface;
1616
use Magento\Review\Model\ResourceModel\Review\CollectionFactory;
1717
use Magmodules\Reloadify\Api\Config\RepositoryInterface as ConfigRepository;
1818
use Magmodules\Reloadify\Model\RequestLog\Collection as RequestLogCollection;
1919
use Magmodules\Reloadify\Model\RequestLog\CollectionFactory as RequestLogCollectionFactory;
20+
use Magento\Catalog\Model\Product\Visibility;
21+
use Magento\Store\Model\StoreManagerInterface;
2022

2123
/**
2224
* Product web API service class
@@ -42,10 +44,6 @@ class Product
4244
* @var ProductCollectionFactory
4345
*/
4446
private $productsCollectionFactory;
45-
/**
46-
* @var Image
47-
*/
48-
private $image;
4947
/**
5048
* @var CollectionFactory
5149
*/
@@ -62,29 +60,44 @@ class Product
6260
* @var CollectionProcessorInterface
6361
*/
6462
private $collectionProcessor;
63+
/**
64+
* @var Visibility
65+
*/
66+
private $productVisibility;
67+
/**
68+
* @var StoreManagerInterface
69+
*/
70+
private $storeManager;
71+
72+
private $mediaPath = '';
6573

6674
/**
67-
* @param ProductCollectionFactory $productsCollectionFactory
68-
* @param Image $image
69-
* @param CollectionFactory $reviewCollectionFactory
70-
* @param RequestLogCollectionFactory $requestLogCollectionFactory
71-
* @param ConfigRepository $configRepository
75+
* Product constructor.
76+
*
77+
* @param ProductCollectionFactory $productsCollectionFactory
78+
* @param CollectionFactory $reviewCollectionFactory
79+
* @param RequestLogCollectionFactory $requestLogCollectionFactory
80+
* @param ConfigRepository $configRepository
7281
* @param CollectionProcessorInterface $collectionProcessor
82+
* @param Visibility $productVisibility
83+
* @param StoreManagerInterface $storeManager
7384
*/
7485
public function __construct(
7586
ProductCollectionFactory $productsCollectionFactory,
76-
Image $image,
7787
CollectionFactory $reviewCollectionFactory,
7888
RequestLogCollectionFactory $requestLogCollectionFactory,
7989
ConfigRepository $configRepository,
80-
CollectionProcessorInterface $collectionProcessor
90+
CollectionProcessorInterface $collectionProcessor,
91+
Visibility $productVisibility,
92+
StoreManagerInterface $storeManager
8193
) {
8294
$this->productsCollectionFactory = $productsCollectionFactory;
8395
$this->reviewCollectionFactory = $reviewCollectionFactory;
84-
$this->image = $image;
8596
$this->requestLogCollection = $requestLogCollectionFactory->create();
8697
$this->configRepository = $configRepository;
8798
$this->collectionProcessor = $collectionProcessor;
99+
$this->productVisibility = $productVisibility;
100+
$this->storeManager = $storeManager;
88101
}
89102

90103
/**
@@ -102,13 +115,15 @@ public function execute(int $storeId, array $extra = [], SearchCriteriaInterface
102115
$name = $this->configRepository->getName($storeId);
103116
$sku = $this->configRepository->getSku($storeId);
104117
$brand = $this->configRepository->getBrand($storeId);
118+
$description = $this->configRepository->getDescription($storeId);
105119

106120
foreach ($collection as $product) {
107121
$data[] = [
108122
"id" => $product->getId(),
109123
"name" => $this->getAttributeValue($product, $name),
110124
"ean" => $this->getAttributeValue($product, $ean),
111125
"short_description" => $product->getShortDescription(),
126+
"description" => $this->getAttributeValue($product, $description),
112127
"price" => $product->getPrice(),
113128
"url" => $product->getProductUrl(),
114129
"sku" => $this->getAttributeValue($product, $sku),
@@ -159,7 +174,8 @@ private function getCollection(
159174
): Collection {
160175
$collection = $this->productsCollectionFactory->create()
161176
->addAttributeToSelect('*')
162-
->setStore($storeId);
177+
->setStore($storeId)
178+
->setVisibility($this->productVisibility->getVisibleInSiteIds());
163179
if ($extra['entity_id']) {
164180
$collection->addFieldToFilter('entity_id', $extra['entity_id']);
165181
} else {
@@ -210,9 +226,11 @@ private function applyFilter(Collection $products, array $filters, int $storeId
210226
*/
211227
private function getMainImage($product)
212228
{
213-
return $this->image->init($product, 'image')
214-
->setImageFile($product->getImage())
215-
->getUrl();
229+
if (!$this->mediaPath) {
230+
$this->mediaPath = $this->storeManager->getStore($product->getStoreId())
231+
->getBaseUrl(UrlInterface::URL_TYPE_MEDIA);
232+
}
233+
return $this->mediaPath . 'catalog/product' . $product->getImage();
216234
}
217235

218236
/**

Service/WebApi/Variants.php

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,15 @@
77

88
namespace Magmodules\Reloadify\Service\WebApi;
99

10-
use Magento\Catalog\Helper\Image;
1110
use Magento\Catalog\Model\ResourceModel\Product\Collection;
1211
use Magento\Catalog\Model\ResourceModel\Product\CollectionFactory as ProductCollectionFactory;
1312
use Magento\Framework\Api\SearchCriteria\CollectionProcessorInterface;
1413
use Magento\Framework\Api\SearchCriteriaInterface;
1514
use Magento\Framework\App\ResourceConnection;
1615
use Magmodules\Reloadify\Api\Config\RepositoryInterface as ConfigRepository;
1716
use Magmodules\Reloadify\Service\ProductData\Stock;
17+
use Magento\Store\Model\StoreManagerInterface;
18+
use Magento\Framework\UrlInterface;
1819

1920
/**
2021
* Variants web API service class
@@ -42,10 +43,6 @@ class Variants
4243
* @var ProductCollectionFactory
4344
*/
4445
private $productsCollectionFactory;
45-
/**
46-
* @var Image
47-
*/
48-
private $image;
4946
/**
5047
* @var ResourceConnection
5148
*/
@@ -62,30 +59,35 @@ class Variants
6259
* @var CollectionProcessorInterface
6360
*/
6461
private $collectionProcessor;
62+
/**
63+
* @var StoreManagerInterface
64+
*/
65+
private $storeManager;
66+
67+
private $mediaPath = '';
6568

6669
/**
6770
* Variants constructor.
6871
*
6972
* @param ProductCollectionFactory $productsCollectionFactory
70-
* @param Image $image
7173
* @param ResourceConnection $resourceConnection
7274
* @param ConfigRepository $configRepository
7375
* @param Stock $stock
7476
*/
7577
public function __construct(
7678
ProductCollectionFactory $productsCollectionFactory,
77-
Image $image,
7879
ResourceConnection $resourceConnection,
7980
ConfigRepository $configRepository,
8081
Stock $stock,
81-
CollectionProcessorInterface $collectionProcessor
82+
CollectionProcessorInterface $collectionProcessor,
83+
StoreManagerInterface $storeManager
8284
) {
8385
$this->productsCollectionFactory = $productsCollectionFactory;
84-
$this->image = $image;
8586
$this->resourceConnection = $resourceConnection;
8687
$this->configRepository = $configRepository;
8788
$this->stock = $stock;
8889
$this->collectionProcessor = $collectionProcessor;
90+
$this->storeManager = $storeManager;
8991
}
9092

9193
/**
@@ -102,6 +104,7 @@ public function execute(int $storeId, array $extra = [], SearchCriteriaInterface
102104
$name = $this->configRepository->getName($storeId);
103105
$sku = $this->configRepository->getSku($storeId);
104106
$brand = $this->configRepository->getBrand($storeId);
107+
$description = $this->configRepository->getDescription($storeId);
105108

106109
$data = [];
107110
$collection = $this->getCollection($storeId, $extra, $searchCriteria);
@@ -114,6 +117,7 @@ public function execute(int $storeId, array $extra = [], SearchCriteriaInterface
114117
$data[] = [
115118
"id" => $product->getId(),
116119
"title" => $this->getAttributeValue($product, $name),
120+
"description" => $this->getAttributeValue($product, $description),
117121
"article_code" => $product->getSku(),
118122
"ean" => $this->getAttributeValue($product, $ean),
119123
"main_image" => $this->getMainImage($product),
@@ -217,9 +221,11 @@ private function applyFilter(Collection $products, array $filters)
217221
*/
218222
private function getMainImage($product)
219223
{
220-
return $this->image->init($product, 'image')
221-
->setImageFile($product->getImage())
222-
->getUrl();
224+
if (!$this->mediaPath) {
225+
$this->mediaPath = $this->storeManager->getStore($product->getStoreId())
226+
->getBaseUrl(UrlInterface::URL_TYPE_MEDIA);
227+
}
228+
return $this->mediaPath . 'catalog/product' . $product->getImage();
223229
}
224230

225231
/**

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.7.1",
5+
"version": "1.8.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
@@ -38,5 +38,12 @@
3838
<config_path>magmodules_reloadify/attributes/brand</config_path>
3939
<comment>Select the attribute associate with the product brand. Suggested field: Manufacturer</comment>
4040
</field>
41+
<field id="description" translate="label comment" type="select" sortOrder="80" showInDefault="1"
42+
showInWebsite="1" showInStore="1" canRestore="1">
43+
<label>Description</label>
44+
<source_model>Magmodules\Reloadify\Model\Config\Source\Attributes</source_model>
45+
<config_path>magmodules_reloadify/attributes/description</config_path>
46+
<comment>Select the attribute associate with the product description. Suggested field: Description</comment>
47+
</field>
4148
</group>
4249
</include>

etc/config.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
<default>
1111
<magmodules_reloadify>
1212
<general>
13-
<version>v1.7.1</version>
13+
<version>v1.8.0</version>
1414
<enable>0</enable>
1515
<debug>0</debug>
1616
</general>
@@ -19,6 +19,7 @@
1919
<name>name</name>
2020
<sku>sku</sku>
2121
<brand>manufacturer</brand>
22+
<description>description</description>
2223
</attributes>
2324
</magmodules_reloadify>
2425
</default>

0 commit comments

Comments
 (0)