Skip to content

Commit 24acd8f

Browse files
Merge pull request #28 from magmodules/release/1.10.0
Release/1.10.0
2 parents 94c689b + 70b67aa commit 24acd8f

File tree

7 files changed

+84
-10
lines changed

7 files changed

+84
-10
lines changed

Service/WebApi/Cart.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
namespace Magmodules\Reloadify\Service\WebApi;
99

10+
use Magento\Catalog\Model\Product\Type;
1011
use Magento\Framework\Api\SearchCriteria\CollectionProcessorInterface;
1112
use Magento\Framework\Api\SearchCriteriaInterface;
1213
use Magento\Framework\Encryption\EncryptorInterface;
@@ -217,6 +218,7 @@ private function getProducts(Quote $quote)
217218

218219
$quoteProduct = [
219220
'id' => $item->getProductId(),
221+
'product_type' => $item->getProductType(),
220222
'quantity' => $item->getQty()
221223
];
222224

@@ -228,6 +230,14 @@ private function getProducts(Quote $quote)
228230
$quoteProduct['variant_id'] = $child->getProductId();
229231
}
230232
}
233+
234+
// If it is a simple product associated with a bundle, get the parent bundle product ID
235+
if ($item->getProductType() == Type::TYPE_SIMPLE &&
236+
$item->getParentItem() &&
237+
$item->getParentItem()->getProductType() == Type::TYPE_BUNDLE) {
238+
$quoteProduct['parent_id'] = $item->getParentItem()->getProductId();
239+
}
240+
231241
$quoteProducts[] = $quoteProduct;
232242
}
233243
return $quoteProducts;

Service/WebApi/Order.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
namespace Magmodules\Reloadify\Service\WebApi;
99

10+
use Magento\Catalog\Model\Product\Type;
1011
use Magento\Customer\Api\CustomerRepositoryInterface as CustomerRepository;
1112
use Magento\Framework\Api\SearchCriteria\CollectionProcessorInterface;
1213
use Magento\Framework\Api\SearchCriteriaInterface;
@@ -163,15 +164,24 @@ private function getProducts(OrderModel $order): array
163164

164165
$orderedProduct = [
165166
'id' => $item->getProductId(),
167+
'product_type' => $item->getProductType(),
166168
'quantity' => $item->getQtyOrdered(),
167169
];
170+
168171
if ($item->getProductType() == 'configurable') {
169172
$child = $item->getChildrenItems();
170173
if (count($child) != 0) {
171174
$child = reset($child);
172175
$orderedProduct['variant_id'] = $child->getProductId();
173176
}
174177
}
178+
179+
// If it is a simple product associated with a bundle, get the parent bundle product ID
180+
if ($item->getProductType() == Type::TYPE_SIMPLE &&
181+
$item->getParentItem() &&
182+
$item->getParentItem()->getProductType() == Type::TYPE_BUNDLE) {
183+
$orderedProduct['parent_id'] = $item->getParentItem()->getProductId();
184+
}
175185
$orderedProducts[] = $orderedProduct;
176186
}
177187

Service/WebApi/Product.php

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
use Magmodules\Reloadify\Model\RequestLog\CollectionFactory as RequestLogCollectionFactory;
2020
use Magento\Catalog\Model\Product\Visibility;
2121
use Magento\Store\Model\StoreManagerInterface;
22+
use Magento\Catalog\Model\Product\Type;
2223

2324
/**
2425
* Product web API service class
@@ -121,6 +122,7 @@ public function execute(int $storeId, array $extra = [], SearchCriteriaInterface
121122
$data[] = [
122123
"id" => $product->getId(),
123124
"name" => $this->getAttributeValue($product, $name),
125+
'product_type' => $product->getTypeId(),
124126
"ean" => $this->getAttributeValue($product, $ean),
125127
"short_description" => $product->getShortDescription(),
126128
"description" => $this->getAttributeValue($product, $description),
@@ -234,7 +236,7 @@ private function getMainImage($product)
234236
}
235237

236238
/**
237-
* Returns simple products array for configurable product type
239+
* Returns simple products array for parent product
238240
*
239241
* @param ProductModel $product
240242
*
@@ -243,13 +245,24 @@ private function getMainImage($product)
243245
private function getVariants(ProductModel $product)
244246
{
245247
$ids = [];
246-
if ($product->getTypeId() == 'configurable') {
247-
$products = $product->getTypeInstance()->getUsedProducts($product);
248-
$ids = [];
249-
foreach ($products as $product) {
250-
$ids[] = $product->getId();
248+
$childProducts = null;
249+
switch ($product->getTypeId()) {
250+
case 'configurable':
251+
$childProducts = $product->getTypeInstance()->getUsedProducts($product);
252+
break;
253+
case 'grouped':
254+
$childProducts = $product->getTypeInstance()->getAssociatedProducts($product);
255+
break;
256+
}
257+
258+
if ($childProducts) {
259+
foreach ($childProducts as $childProduct) {
260+
if ($childProduct->getTypeId() == 'simple') {
261+
$ids[] = $childProduct->getId();
262+
}
251263
}
252264
}
265+
253266
return $ids;
254267
}
255268

Service/WebApi/Variants.php

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ private function getAttributeValue($product, $attribute)
161161
*/
162162
private function getChildProducts(int $entityId = null)
163163
{
164+
//configurable children
164165
$connection = $this->resourceConnection->getConnection();
165166
$selectProducts = $connection->select()->from(
166167
$this->resourceConnection->getTableName('catalog_product_super_link'),
@@ -169,7 +170,35 @@ private function getChildProducts(int $entityId = null)
169170
if ($entityId) {
170171
$selectProducts->where('product_id = ?', $entityId);
171172
}
172-
return $connection->fetchPairs($selectProducts);
173+
$configurable = $connection->fetchPairs($selectProducts);
174+
175+
//grouped children
176+
$selectProducts = $connection->select()->from(
177+
$this->resourceConnection->getTableName('catalog_product_link'),
178+
['linked_product_id', 'product_id']
179+
)->where('link_type_id = 3');
180+
if ($entityId) {
181+
$selectProducts->where('linked_product_id = ?', $entityId);
182+
}
183+
$grouped = $connection->fetchPairs($selectProducts);
184+
185+
//bundle children
186+
$selectProducts = $connection->select()->from(
187+
['r' => $this->resourceConnection->getTableName('catalog_product_relation')],
188+
['child_id', 'parent_id']
189+
)->joinLeft(
190+
['e' => $this->resourceConnection->getTableName('catalog_product_entity')],
191+
'r.parent_id = e.entity_id',
192+
[]
193+
)->where(
194+
'e.type_id = "bundle"'
195+
);
196+
if ($entityId) {
197+
$selectProducts->where('r.child_id = ?', $entityId);
198+
}
199+
$bundle = $connection->fetchPairs($selectProducts);
200+
201+
return $configurable + $grouped + $bundle;
173202
}
174203

175204
/**
@@ -188,7 +217,6 @@ private function getCollection(
188217
$collection = $this->productsCollectionFactory->create()
189218
->addAttributeToSelect('*')
190219
->addFieldToFilter('entity_id', ['in' => array_keys($productIds)])
191-
->addPriceData()
192220
->setStore($storeId);
193221

194222
$collection = $this->applyFilter($collection, $extra['filter']);

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.9.0",
5+
"version": "1.10.0",
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.9.0</version>
13+
<version>v1.10.0</version>
1414
<enable>0</enable>
1515
<debug>0</debug>
1616
</general>

etc/db_schema_whitelist.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"reloadify_request_log": {
3+
"column": {
4+
"entity_id": true,
5+
"type": true,
6+
"store_id": true,
7+
"created_at": true
8+
},
9+
"constraint": {
10+
"PRIMARY": true
11+
}
12+
}
13+
}

0 commit comments

Comments
 (0)