Skip to content

Commit

Permalink
EC-46: Unknown Product issue resolved (#45)
Browse files Browse the repository at this point in the history
* EC-46 : Magento Importer entity_id vs row_id

* EC-46 : Magento Importer entity_id vs row_id

* EC-46 : adding logs for testing

* EC-46 : adding logs for testing

* EC-46 : logs removed

* EC-46 : composer version updated to 2.6.1
  • Loading branch information
mayursose authored Mar 27, 2023
1 parent e45114c commit d1c3a6a
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 120 deletions.
2 changes: 1 addition & 1 deletion app/code/Ometria/AbandonedCarts/etc/module.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Ometria_AbandonedCarts" setup_version="2.6.0"/>
<module name="Ometria_AbandonedCarts" setup_version="2.6.1"/>
</config>
131 changes: 15 additions & 116 deletions app/code/Ometria/Api/Controller/V1/Products.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use Magento\Store\Model\App\Emulation as AppEmulation;
use Ometria\Api\Helper\Filter\V1\Service as FilterService;
use Ometria\Api\Helper\Format\V1\Products as Helper;
use Ometria\Api\Model\ResourceModel\Product as ProductResource;

class Products extends Base
{
Expand Down Expand Up @@ -48,6 +49,9 @@ class Products extends Base
/** @var AppEmulation */
private $appEmulation;

/** @var ProductResource */
private $productResource;

protected $storeIdCache=false;
protected $productTypeFactory;

Expand Down Expand Up @@ -86,7 +90,8 @@ public function __construct(
\Magento\Catalog\Model\Product\TypeFactory $productTypeFactory,
StockRegistryInterface $stockRegistry,
HttpContext $httpContext,
AppEmulation $appEmulation
AppEmulation $appEmulation,
ProductResource $productResource
) {
parent::__construct($context);
$this->searchCriteriaBuilder = $searchCriteriaBuilder;
Expand All @@ -110,6 +115,7 @@ public function __construct(
$this->stockRegistry = $stockRegistry;
$this->httpContext = $httpContext;
$this->appEmulation = $appEmulation;
$this->productResource = $productResource;
}

public function execute()
Expand Down Expand Up @@ -234,14 +240,10 @@ protected function serializeItem($item)
$tmp['url'] = $this->getArrayKey($item, 'url');
$tmp['image_url'] = $this->getArrayKey($item, 'image_url');
$tmp['attributes'] = [];
$tmp['is_active'] = $this->getArrayKey($item, 'status') !== ProductStatus::STATUS_DISABLED;
$tmp['is_active'] = (bool) $this->getArrayKey($item, 'status') == ProductStatus::STATUS_ENABLED;
$tmp['stores'] = $this->getArrayKey($item, 'store_ids');

// Add parent ID if this is a variant simple product
if ($variantParentId = $this->getVariantParentId($item)) {
$tmp['parent_id'] = $variantParentId;
$tmp['is_variant'] = true;
}
$tmp['parent_id'] = $this->getVariantParentId($item);
$tmp['is_variant'] = (bool) $tmp['parent_id'] != null ? true : false;

if ($this->_request->getParam('raw') === 'true') {
$tmp['_raw'] = $item;
Expand Down Expand Up @@ -556,116 +558,13 @@ protected function prepareChildParentRelationships(array $items)
}

// fetch array of Configurable Product relationships, filtered by the items being processed
$this->childParentConfigurableProductIds = $this->getConfigurableProductParentChildIds($allProductIds);
$this->childParentConfigurableProductIds = $this->productResource->getConfigurableProductParentIds($allProductIds);

// fetch array of Bundle Product relationships, filtered by the items being processed
$this->childParentBundleProductIds = $this->getBundleProductParentChildIds($allProductIds);
$this->childParentBundleProductIds = $this->productResource->getBundleProductParentIds($allProductIds);

// fetch array of Grouped Product relationships, filtered by the items being processed
$this->childParentGroupedProductIds = $this->getGroupedProductParentChildIds($allProductIds);
}

/**
* Bulk version of the native method to retrieve relationships one by one.
* @see \Magento\ConfigurableProduct\Model\ResourceModel\Product\Type\Configurable::getParentIdsByChild
*
* @param array $childIds
* @return array
*/
protected function getConfigurableProductParentChildIds(array $childIds)
{
$childToParentIds = [];

$connection = $this->resourceConnection->getConnection();

$select = $connection->select()
->from(
$this->resourceConnection->getTableName('catalog_product_super_link'),
['product_id', 'parent_id']
)
->where(
'product_id IN (?)',
$childIds
)
// order by the oldest links first so the iterator will end with the most recent link
->order('link_id ASC');

$result = $connection->fetchAll($select);
foreach ($result as $_row) {
$childToParentIds[$_row['product_id']] = $_row['parent_id'];
}

return $childToParentIds;
}

/**
* Bulk version of the native method to retrieve relationships one by one.
* @see \Magento\Bundle\Model\ResourceModel\Selection::getParentIdsByChild
*
* @param array $childIds
* @return array
*/
protected function getBundleProductParentChildIds(array $childIds)
{
$childToParentIds = [];

$connection = $this->resourceConnection->getConnection();

$select = $connection->select()
->from(
$this->resourceConnection->getTableName('catalog_product_bundle_selection'),
['parent_product_id', 'product_id']
)
->where(
'product_id IN (?)',
$childIds
)
// order by the oldest selections first so the iterator will end with the most recent link
->order('selection_id ASC');

$result = $connection->fetchAll($select);
foreach ($result as $_row) {
$childToParentIds[$_row['product_id']] = $_row['parent_product_id'];
}

return $childToParentIds;
}

/**
* Bulk version of the native method to retrieve relationships one by one.
* @see \Magento\GroupedProduct\Model\ResourceModel\Product\Link::getParentIdsByChild
*
* @param array $childIds
* @return array
*/
protected function getGroupedProductParentChildIds(array $childIds)
{
$childToParentIds = [];

$connection = $this->resourceConnection->getConnection();

$select = $connection->select()
->from(
$this->resourceConnection->getTableName('catalog_product_link'),
['product_id', 'linked_product_id']
)
->where(
'linked_product_id IN (?)',
$childIds
)
->where(
'link_type_id = ?',
\Magento\GroupedProduct\Model\ResourceModel\Product\Link::LINK_TYPE_GROUPED
)
// order by the oldest links first so the iterator will end with the most recent link
->order('link_id ASC');

$result = $connection->fetchAll($select);
foreach ($result as $_row) {
$childToParentIds[$_row['linked_product_id']] = $_row['product_id'];
}

return $childToParentIds;
$this->childParentGroupedProductIds = $this->productResource->getGroupedProductParentIds($allProductIds);
}

/**
Expand All @@ -684,7 +583,7 @@ protected function getVariantParentId($item)
];
$visibility = $this->getArrayKey($item, 'visibility');
if (in_array($visibility, $visibleInSiteVisibilities)) {
return false;
return null;
}

// if the product is associated to a configurable product, return the parent ID
Expand All @@ -702,7 +601,7 @@ protected function getVariantParentId($item)
return $this->childParentGroupedProductIds[$productId];
}

return false;
return null;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion app/code/Ometria/Api/etc/module.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Ometria_Api" setup_version="2.6.0"/>
<module name="Ometria_Api" setup_version="2.6.1"/>
</config>
2 changes: 1 addition & 1 deletion app/code/Ometria/Core/etc/module.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Ometria_Core" setup_version="2.6.0"/>
<module name="Ometria_Core" setup_version="2.6.1"/>
</config>
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "ometria/magento2",
"type": "magento2-module",
"version": "2.6.0",
"version": "2.6.1",
"description": "Dev composer package for Ometria Extension",
"authors": [
{
Expand Down

0 comments on commit d1c3a6a

Please sign in to comment.