Skip to content

Commit c784b9b

Browse files
authored
Release/2.2.2 (#30)
* Added compatibility with Magento Commerce Staging functionality for product relationships. * Ensure Products V2 API response "is_active" casts to bool correctly (disabled prodiuct status is "2"). * Bump version. * Remove redundant use statement.
1 parent 8653eaf commit c784b9b

File tree

6 files changed

+69
-36
lines changed

6 files changed

+69
-36
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
<?xml version="1.0"?>
22
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
3-
<module name="Ometria_AbandonedCarts" setup_version="2.2.1"/>
3+
<module name="Ometria_AbandonedCarts" setup_version="2.2.2"/>
44
</config>

app/code/Ometria/Api/Controller/V2/Products.php

100755100644
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
use Magento\Catalog\Api\Data\ProductInterface;
55
use Magento\Catalog\Api\ProductAttributeRepositoryInterface;
66
use Magento\Catalog\Model\CategoryRepository;
7+
use Magento\Catalog\Model\Product\Attribute\Source\Status as ProductStatus;
78
use Magento\Catalog\Model\Product\TypeFactory;
89
use Magento\Catalog\Model\Product\Visibility;
910
use Magento\Catalog\Model\ResourceModel\Product\Collection;
@@ -282,7 +283,7 @@ private function getProductData(ProductInterface $product)
282283
$productData[OmetriaProductInterface::IS_VARIANT] = (bool) $parentId != null ? true : false;
283284
$productData[OmetriaProductInterface::PARENT_ID] = $parentId;
284285
$productData[OmetriaProductInterface::ATTRIBUTES] = $this->getAttributes($product);
285-
$productData[OmetriaProductInterface::IS_ACTIVE] = (bool) $product->getStatus();
286+
$productData[OmetriaProductInterface::IS_ACTIVE] = (bool) $product->getStatus() == ProductStatus::STATUS_ENABLED;
286287
$productData[OmetriaProductInterface::STORES] = $product->getStoreIds();
287288
$productData[OmetriaProductInterface::IS_IN_STOCK] = $this->inventoryService->getStockStatus($product);
288289
$productData[OmetriaProductInterface::QTY] = $this->inventoryService->getSalableQuantity($product);

app/code/Ometria/Api/Model/ResourceModel/Product.php

Lines changed: 63 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,31 @@
11
<?php
22
namespace Ometria\Api\Model\ResourceModel;
33

4+
use Magento\Catalog\Api\Data\ProductInterface;
5+
use Magento\Framework\EntityManager\MetadataPool;
46
use Magento\Framework\Model\ResourceModel\Db\AbstractDb;
7+
use Magento\Framework\Model\ResourceModel\Db\Context;
58

69
class Product extends AbstractDb
710
{
11+
/** @var MetadataPool */
12+
private $metadataPool;
13+
14+
/**
15+
* @param Context $context
16+
* @param MetadataPool $metadataPool
17+
* @param null $connectionName
18+
*/
19+
public function __construct(
20+
Context $context,
21+
MetadataPool $metadataPool,
22+
$connectionName = null
23+
) {
24+
$this->metadataPool = $metadataPool;
25+
26+
parent::__construct($context, $connectionName);
27+
}
28+
829
protected function _construct()
930
{
1031
}
@@ -21,22 +42,26 @@ public function getConfigurableProductParentIds(array $childIds)
2142
$childToParentIds = [];
2243

2344
$connection = $this->getConnection();
24-
45+
$metadata = $this->metadataPool->getMetadata(ProductInterface::class);
2546
$select = $connection->select()
2647
->from(
27-
$this->getConnection()->getTableName('catalog_product_super_link'),
28-
['product_id', 'parent_id']
29-
)
30-
->where(
31-
'product_id IN (?)',
48+
['link_table' => $connection->getTableName('catalog_product_super_link')],
49+
['link_id', 'product_id']
50+
)->join(
51+
['e' => $this->metadataPool->getMetadata(ProductInterface::class)->getEntityTable()],
52+
'e.' . $metadata->getLinkField() . ' = link_table.parent_id',
53+
['e.entity_id']
54+
)->where(
55+
'link_table.product_id IN(?)',
3256
$childIds
3357
)
34-
// order by the oldest links first so the iterator will end with the most recent link
35-
->order('link_id ASC');
58+
->order(
59+
'link_id ASC'
60+
);
3661

3762
$result = $connection->fetchAll($select);
3863
foreach ($result as $_row) {
39-
$childToParentIds[$_row['product_id']] = $_row['parent_id'];
64+
$childToParentIds[$_row['product_id']] = $_row['entity_id'];
4065
}
4166

4267
return $childToParentIds;
@@ -54,22 +79,25 @@ public function getBundleProductParentIds(array $childIds)
5479
$childToParentIds = [];
5580

5681
$connection = $this->getConnection();
57-
82+
$metadata = $this->metadataPool->getMetadata(ProductInterface::class);
5883
$select = $connection->select()
5984
->from(
60-
$this->getConnection()->getTableName('catalog_product_bundle_selection'),
61-
['parent_product_id', 'product_id']
62-
)
63-
->where(
64-
'product_id IN (?)',
85+
['link_table' => $connection->getTableName('catalog_product_bundle_selection')],
86+
['selection_id', 'product_id']
87+
)->join(
88+
['e' => $this->metadataPool->getMetadata(ProductInterface::class)->getEntityTable()],
89+
'e.' . $metadata->getLinkField() . ' = link_table.parent_product_id',
90+
['e.entity_id']
91+
)->where(
92+
'link_table.product_id IN(?)',
6593
$childIds
66-
)
67-
// order by the oldest selections first so the iterator will end with the most recent link
68-
->order('selection_id ASC');
94+
)->order(
95+
'selection_id ASC'
96+
);
6997

7098
$result = $connection->fetchAll($select);
7199
foreach ($result as $_row) {
72-
$childToParentIds[$_row['product_id']] = $_row['parent_product_id'];
100+
$childToParentIds[$_row['product_id']] = $_row['entity_id'];
73101
}
74102

75103
return $childToParentIds;
@@ -87,26 +115,30 @@ public function getGroupedProductParentIds(array $childIds)
87115
$childToParentIds = [];
88116

89117
$connection = $this->getConnection();
90-
118+
$metadata = $this->metadataPool->getMetadata(ProductInterface::class);
91119
$select = $connection->select()
92120
->from(
93-
$this->getConnection()->getTableName('catalog_product_link'),
94-
['product_id', 'linked_product_id']
95-
)
96-
->where(
97-
'linked_product_id IN (?)',
98-
$childIds
99-
)
100-
->where(
121+
['link_table' => $connection->getTableName('catalog_product_link')],
122+
['link_id', 'linked_product_id']
123+
)->join(
124+
['e' => $this->metadataPool->getMetadata(ProductInterface::class)->getEntityTable()],
125+
'e.' . $metadata->getLinkField() . ' = link_table.product_id',
126+
['e.entity_id']
127+
)->where(
101128
'link_type_id = ?',
102129
\Magento\GroupedProduct\Model\ResourceModel\Product\Link::LINK_TYPE_GROUPED
103130
)
104-
// order by the oldest links first so the iterator will end with the most recent link
105-
->order('link_id ASC');
131+
->where(
132+
'link_table.linked_product_id IN(?)',
133+
$childIds
134+
)->order(
135+
'link_id ASC'
136+
);
106137

107138
$result = $connection->fetchAll($select);
139+
108140
foreach ($result as $_row) {
109-
$childToParentIds[$_row['linked_product_id']] = $_row['product_id'];
141+
$childToParentIds[$_row['linked_product_id']] = $_row['entity_id'];
110142
}
111143

112144
return $childToParentIds;
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
<?xml version="1.0"?>
22
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
3-
<module name="Ometria_Api" setup_version="2.2.1"/>
3+
<module name="Ometria_Api" setup_version="2.2.2"/>
44
</config>
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
<?xml version="1.0"?>
22
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
3-
<module name="Ometria_Core" setup_version="2.2.1"/>
3+
<module name="Ometria_Core" setup_version="2.2.2"/>
44
</config>

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "ometria/magento2",
33
"type": "magento2-module",
4-
"version": "2.2.1",
4+
"version": "2.2.2",
55
"description": "Dev composer package for Ometria Extension",
66
"authors": [
77
{

0 commit comments

Comments
 (0)