Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
SuggestedAttributeList.php
Go to the documentation of this file.
1 <?php
9 
11 {
16 
22  protected $_resourceHelper;
23 
28  public function __construct(
30  \Magento\Catalog\Model\ResourceModel\Helper $resourceHelper
31  ) {
32  $this->configurableAttributeHandler = $configurableAttributeHandler;
33  $this->_resourceHelper = $resourceHelper;
34  }
35 
42  public function getSuggestedAttributes($labelPart)
43  {
44  $escapedLabelPart = $this->_resourceHelper->addLikeEscape($labelPart, ['position' => 'any']);
46  $collection = $this->configurableAttributeHandler->getApplicableAttributes()->addFieldToFilter(
47  'frontend_label',
48  ['like' => $escapedLabelPart]
49  );
50  $result = [];
51  foreach ($collection->getItems() as $id => $attribute) {
53  if ($this->configurableAttributeHandler->isAttributeApplicable($attribute)) {
54  $result[$id] = [
55  'id' => $attribute->getId(),
56  'label' => $attribute->getFrontendLabel(),
57  'code' => $attribute->getAttributeCode(),
58  'options' => $attribute->getSource()->getAllOptions(false),
59  ];
60  }
61  }
62  return $result;
63  }
64 }
$id
Definition: fieldset.phtml:14
__construct(\Magento\ConfigurableProduct\Model\ConfigurableAttributeHandler $configurableAttributeHandler, \Magento\Catalog\Model\ResourceModel\Helper $resourceHelper)