![]() 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/fooman/pdfcore-m2/src/Model/Config/Source/ |
<?php /** * @copyright Copyright (c) 2015 Fooman Limited (http://www.fooman.co.nz) * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Fooman\PdfCore\Model\Config\Source; use Magento\Catalog\Ui\Component\Listing\Attribute\AbstractRepository; use Magento\Framework\Data\OptionSourceInterface; class ProductAttributes extends AbstractRepository implements OptionSourceInterface { protected $excludedAttributes = ['category_id', 'tier_price']; /** * @var \Magento\Framework\Escaper */ protected $escaper; /** * @var \Magento\Framework\Api\SearchCriteriaInterface */ protected $searchCriteria; /** * @var \Magento\Catalog\Api\ProductAttributeRepositoryInterface */ private $prodAttrRepo; /** * ProductAttributes constructor. * * @param \Magento\Catalog\Api\ProductAttributeRepositoryInterface $productAttributeRepository * @param \Magento\Framework\Api\SearchCriteriaBuilder $searchCriteriaBuilder * @param \Magento\Framework\Escaper $escaper * @param \Magento\Framework\Api\SearchCriteriaInterface $searchCriteria */ public function __construct( \Magento\Catalog\Api\ProductAttributeRepositoryInterface $productAttributeRepository, \Magento\Framework\Api\SearchCriteriaBuilder $searchCriteriaBuilder, \Magento\Framework\Escaper $escaper, \Magento\Framework\Api\SearchCriteriaInterface $searchCriteria ) { parent::__construct($productAttributeRepository, $searchCriteriaBuilder); $this->searchCriteria = $searchCriteria; $this->escaper = $escaper; $this->prodAttrRepo = $productAttributeRepository; } /** * supply dropdown choices for custom product attributes * * @return array */ public function toOptionArray() { $options = []; foreach ($this->getAttributeList() as $attribute) { if (!in_array($attribute->getAttributeCode(), $this->excludedAttributes) && in_array( $attribute->getFrontendInput(), [ 'select', 'multiselect', 'text', 'textarea', 'date', 'price', 'boolean' ] ) ) { $options[] = [ 'value' => 'product/' . $attribute->getAttributeCode(), 'label' => $this->getLabel($attribute) ]; } } $options[] = ['value' => 'salableQty', 'label' => __('Salable Qty')]; return $options; } public function getAttributeList() { return $this->prodAttrRepo->getList($this->searchCriteria)->getItems(); } protected function getLabel($attribute) { $label = ($attribute->getFrontendLabel() ? $attribute->getFrontendLabel() : $attribute->getAttributeCode()); return $this->escaper->escapeJsQuote($label); } protected function buildSearchCriteria() { return $this->searchCriteriaBuilder->create(); } }