Skip to content

Commit

Permalink
Merge pull request #28 from magmodules/release/1.10.0
Browse files Browse the repository at this point in the history
Release/1.10.0
  • Loading branch information
Marvin-Magmodules authored May 22, 2024
2 parents 94c689b + 70b67aa commit 24acd8f
Show file tree
Hide file tree
Showing 7 changed files with 84 additions and 10 deletions.
10 changes: 10 additions & 0 deletions Service/WebApi/Cart.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

namespace Magmodules\Reloadify\Service\WebApi;

use Magento\Catalog\Model\Product\Type;
use Magento\Framework\Api\SearchCriteria\CollectionProcessorInterface;
use Magento\Framework\Api\SearchCriteriaInterface;
use Magento\Framework\Encryption\EncryptorInterface;
Expand Down Expand Up @@ -217,6 +218,7 @@ private function getProducts(Quote $quote)

$quoteProduct = [
'id' => $item->getProductId(),
'product_type' => $item->getProductType(),
'quantity' => $item->getQty()
];

Expand All @@ -228,6 +230,14 @@ private function getProducts(Quote $quote)
$quoteProduct['variant_id'] = $child->getProductId();
}
}

// If it is a simple product associated with a bundle, get the parent bundle product ID
if ($item->getProductType() == Type::TYPE_SIMPLE &&
$item->getParentItem() &&
$item->getParentItem()->getProductType() == Type::TYPE_BUNDLE) {
$quoteProduct['parent_id'] = $item->getParentItem()->getProductId();
}

$quoteProducts[] = $quoteProduct;
}
return $quoteProducts;
Expand Down
10 changes: 10 additions & 0 deletions Service/WebApi/Order.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

namespace Magmodules\Reloadify\Service\WebApi;

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

$orderedProduct = [
'id' => $item->getProductId(),
'product_type' => $item->getProductType(),
'quantity' => $item->getQtyOrdered(),
];

if ($item->getProductType() == 'configurable') {
$child = $item->getChildrenItems();
if (count($child) != 0) {
$child = reset($child);
$orderedProduct['variant_id'] = $child->getProductId();
}
}

// If it is a simple product associated with a bundle, get the parent bundle product ID
if ($item->getProductType() == Type::TYPE_SIMPLE &&
$item->getParentItem() &&
$item->getParentItem()->getProductType() == Type::TYPE_BUNDLE) {
$orderedProduct['parent_id'] = $item->getParentItem()->getProductId();
}
$orderedProducts[] = $orderedProduct;
}

Expand Down
25 changes: 19 additions & 6 deletions Service/WebApi/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use Magmodules\Reloadify\Model\RequestLog\CollectionFactory as RequestLogCollectionFactory;
use Magento\Catalog\Model\Product\Visibility;
use Magento\Store\Model\StoreManagerInterface;
use Magento\Catalog\Model\Product\Type;

/**
* Product web API service class
Expand Down Expand Up @@ -121,6 +122,7 @@ public function execute(int $storeId, array $extra = [], SearchCriteriaInterface
$data[] = [
"id" => $product->getId(),
"name" => $this->getAttributeValue($product, $name),
'product_type' => $product->getTypeId(),
"ean" => $this->getAttributeValue($product, $ean),
"short_description" => $product->getShortDescription(),
"description" => $this->getAttributeValue($product, $description),
Expand Down Expand Up @@ -234,7 +236,7 @@ private function getMainImage($product)
}

/**
* Returns simple products array for configurable product type
* Returns simple products array for parent product
*
* @param ProductModel $product
*
Expand All @@ -243,13 +245,24 @@ private function getMainImage($product)
private function getVariants(ProductModel $product)
{
$ids = [];
if ($product->getTypeId() == 'configurable') {
$products = $product->getTypeInstance()->getUsedProducts($product);
$ids = [];
foreach ($products as $product) {
$ids[] = $product->getId();
$childProducts = null;
switch ($product->getTypeId()) {
case 'configurable':
$childProducts = $product->getTypeInstance()->getUsedProducts($product);
break;
case 'grouped':
$childProducts = $product->getTypeInstance()->getAssociatedProducts($product);
break;
}

if ($childProducts) {
foreach ($childProducts as $childProduct) {
if ($childProduct->getTypeId() == 'simple') {
$ids[] = $childProduct->getId();
}
}
}

return $ids;
}

Expand Down
32 changes: 30 additions & 2 deletions Service/WebApi/Variants.php
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ private function getAttributeValue($product, $attribute)
*/
private function getChildProducts(int $entityId = null)
{
//configurable children
$connection = $this->resourceConnection->getConnection();
$selectProducts = $connection->select()->from(
$this->resourceConnection->getTableName('catalog_product_super_link'),
Expand All @@ -169,7 +170,35 @@ private function getChildProducts(int $entityId = null)
if ($entityId) {
$selectProducts->where('product_id = ?', $entityId);
}
return $connection->fetchPairs($selectProducts);
$configurable = $connection->fetchPairs($selectProducts);

//grouped children
$selectProducts = $connection->select()->from(
$this->resourceConnection->getTableName('catalog_product_link'),
['linked_product_id', 'product_id']
)->where('link_type_id = 3');
if ($entityId) {
$selectProducts->where('linked_product_id = ?', $entityId);
}
$grouped = $connection->fetchPairs($selectProducts);

//bundle children
$selectProducts = $connection->select()->from(
['r' => $this->resourceConnection->getTableName('catalog_product_relation')],
['child_id', 'parent_id']
)->joinLeft(
['e' => $this->resourceConnection->getTableName('catalog_product_entity')],
'r.parent_id = e.entity_id',
[]
)->where(
'e.type_id = "bundle"'
);
if ($entityId) {
$selectProducts->where('r.child_id = ?', $entityId);
}
$bundle = $connection->fetchPairs($selectProducts);

return $configurable + $grouped + $bundle;
}

/**
Expand All @@ -188,7 +217,6 @@ private function getCollection(
$collection = $this->productsCollectionFactory->create()
->addAttributeToSelect('*')
->addFieldToFilter('entity_id', ['in' => array_keys($productIds)])
->addPriceData()
->setStore($storeId);

$collection = $this->applyFilter($collection, $extra['filter']);
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "magmodules/magento2-reloadify",
"description": "Reloadify extension for Magento 2",
"type": "magento2-module",
"version": "1.9.0",
"version": "1.10.0",
"license": [
"BSD-2-Clause"
],
Expand Down
2 changes: 1 addition & 1 deletion etc/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<default>
<magmodules_reloadify>
<general>
<version>v1.9.0</version>
<version>v1.10.0</version>
<enable>0</enable>
<debug>0</debug>
</general>
Expand Down
13 changes: 13 additions & 0 deletions etc/db_schema_whitelist.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"reloadify_request_log": {
"column": {
"entity_id": true,
"type": true,
"store_id": true,
"created_at": true
},
"constraint": {
"PRIMARY": true
}
}
}

0 comments on commit 24acd8f

Please sign in to comment.