![]() 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/app/code/Cnc/Catalog/Model/Attribute/Source/ |
<?php /** * Copyright (c) 2020 Kaliop Digital Commerce (https://digitalcommerce.kaliop.com) All Rights Reserved. * https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) * Cnc * Radosław Stępień <[email protected]> <[email protected]> */ namespace Cnc\Catalog\Model\Attribute\Source; use Cnc\Catalog\Model\ResourceModel\Manufacturer\CollectionFactory; use Magento\Eav\Model\Entity\Attribute\Source\AbstractSource; use Magento\Framework\Data\OptionSourceInterface; class Manufacturer extends AbstractSource implements OptionSourceInterface { /** @var CollectionFactory */ private $collection; /** * Manufacturer constructor. * @param CollectionFactory $collection */ public function __construct( CollectionFactory $collection ) { $this->collection = $collection; } /** * @return array */ public function getAllOptions(): array { $manufacturers = $this->collection->create(); $this->_options = []; $this->_options []= [ 'value' => '', 'label' => ' ', ]; foreach ($manufacturers as $manufacturer) { $this->_options[] = [ 'value' => $manufacturer->getId(), 'label' => $manufacturer->getName(), ]; } return $this->_options; } public function addValueSortToCollection($collection, $dir = \Magento\Framework\Data\Collection::SORT_ORDER_DESC) { $attributeCode = $this->getAttribute()->getAttributeCode(); $attributeId = $this->getAttribute()->getId(); $attributeTable = $this->getAttribute()->getBackend()->getTable(); $linkField = $this->getAttribute()->getEntity()->getLinkField(); $valueTable1 = $attributeCode . '_t1'; $collection->getSelect()->joinLeft( [$valueTable1 => $attributeTable], "e.{$linkField}={$valueTable1}.{$linkField}" . " AND {$valueTable1}.attribute_id='{$attributeId}'" . " AND {$valueTable1}.store_id='0'", [] ); $collection->getSelect()->joinLeft( ['cnc_manufacturer_table' => $collection->getTable('cnc_manufacturer')], "cnc_manufacturer_t1.value=cnc_manufacturer_table.entity_id", [] ); $collection->getSelect()->order("cnc_manufacturer_table.name $dir"); return $this; } }