![]() 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/old/vendor/amasty/feed/Model/ResourceModel/ |
<?php declare(strict_types=1); /** * @author Amasty Team * @copyright Copyright (c) Amasty (https://www.amasty.com) * @package Product Feed for Magento 2 */ namespace Amasty\Feed\Model\ResourceModel; use Magento\Catalog\Api\Data\CategoryLinkInterface; use Magento\Framework\App\ResourceConnection; use Magento\Framework\EntityManager\EntityMetadataInterface; use Magento\Framework\EntityManager\MetadataPool; class ProductCategoriesProvider { /** * @var ResourceConnection */ private $resourceConnection; /** * @var MetadataPool */ private $metadataPool; /** * @var EntityMetadataInterface */ protected $categoryLinkMetadata; public function __construct( ResourceConnection $resourceConnection, MetadataPool $metadataPool ) { $this->resourceConnection = $resourceConnection; $this->metadataPool = $metadataPool; } public function getCategoryIds(array $productIds = []): array { $connection = $this->resourceConnection->getConnection(); $select = $connection->select(); $select->from( $this->getCategoryLinkMetadata()->getEntityTable(), ['product_id', new \Zend_Db_Expr('GROUP_CONCAT(category_id)')] ); if ($productIds) { $select->where('product_id IN (?)', $productIds); } $select->group('product_id'); return (array)$connection->fetchPairs($select); } private function getCategoryLinkMetadata(): EntityMetadataInterface { if ($this->categoryLinkMetadata === null) { $this->categoryLinkMetadata = $this->metadataPool->getMetadata(CategoryLinkInterface::class); } return $this->categoryLinkMetadata; } }