Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
AttributesList.php
Go to the documentation of this file.
1 <?php
6 namespace Magento\Swatches\Model;
7 
9 
15 {
19  protected $collectionFactory;
20 
24  protected $dataHelper;
25 
30  public function __construct(
31  \Magento\Catalog\Model\ResourceModel\Product\Attribute\CollectionFactory $collectionFactory,
32  \Magento\Swatches\Helper\Data $dataHelper
33  ) {
34  $this->collectionFactory = $collectionFactory;
35  $this->dataHelper = $dataHelper;
36  }
37 
44  public function getAttributes($ids)
45  {
46  $collection = $this->collectionFactory->create();
47  $collection->addFieldToFilter('main_table.attribute_id', $ids);
48  $attributes = [];
49  foreach ($collection->getItems() as $attribute) {
50  $attributes[] = [
51  'id' => $attribute->getId(),
52  'label' => $attribute->getFrontendLabel(),
53  'code' => $attribute->getAttributeCode(),
54  'options' => $attribute->getSource()->getAllOptions(false),
55  'canCreateOption' => !$this->dataHelper->isSwatchAttribute($attribute),
56  ];
57  }
58  return $attributes;
59  }
60 }
__construct(\Magento\Catalog\Model\ResourceModel\Product\Attribute\CollectionFactory $collectionFactory, \Magento\Swatches\Helper\Data $dataHelper)
$attributes
Definition: matrix.phtml:13