![]() Server : Apache System : Linux server2.corals.io 4.18.0-348.2.1.el8_5.x86_64 #1 SMP Mon Nov 15 09:17:08 EST 2021 x86_64 User : corals ( 1002) PHP Version : 7.4.33 Disable Function : exec,passthru,shell_exec,system Directory : /home/corals/cartforge.co/app/code/Magefan/Community/Model/ |
<?php /** * Copyright © Magefan ([email protected]). All rights reserved. * Please visit Magefan.com for license details (https://magefan.com/end-user-license-agreement). */ declare(strict_types=1); namespace Magefan\Community\Model; use Magefan\Community\Api\GetParentProductIdsInterface; use Magento\Framework\App\ResourceConnection; class GetParentProductIds implements GetParentProductIdsInterface { /** * @var ResourceConnection */ protected $resourceConnection; /** * @var \Magento\Framework\DB\Adapter\AdapterInterface */ private $connection; /** * GetParentProductIds constructor. * @param ResourceConnection $resourceConnection */ public function __construct( ResourceConnection $resourceConnection ) { $this->resourceConnection = $resourceConnection; $this->connection = $resourceConnection->getConnection(); } /** * @param array $productIds * @return array */ public function execute(array $productIds): array { $parentProductIds = []; /* Fix for configurable, bundle, grouped */ if ($productIds) { $productTable = $this->resourceConnection->getTableName('catalog_product_entity'); $entityIdColumn = $this->connection->tableColumnExists($productTable, 'row_id') ? 'row_id' : 'entity_id'; $select = $this->connection->select() ->from( ['main_table' => $this->resourceConnection->getTableName('catalog_product_relation')], [] )->join( ['e' => $productTable], 'e.' . $entityIdColumn . ' = main_table.parent_id', ['e.' .$entityIdColumn] ) ->where('main_table.child_id IN (?)', $productIds) ->where('e.entity_id IS NOT NULL'); foreach ($this->connection->fetchAll($select) as $product) { $parentProductIds[$product[$entityIdColumn]] = $product[$entityIdColumn]; } } /* End fix */ return $parentProductIds; } }