/** * Retrieve list of product attribute sets with search part contained in label * * @param string $labelPart * @return array */ public function getSuggestedSets($labelPart) { $labelPart = $this->resourceHelper->addLikeEscape($labelPart, ['position' => 'any']); /** @var \Magento\Eav\Model\ResourceModel\Entity\Attribute\Set\Collection $collection */ $collection = $this->attributeSetCollectionFactory->create(); $collection->setEntityTypeFilter($this->product->getTypeId())->addFieldToFilter('attribute_set_name', ['like' => $labelPart])->addFieldToSelect('attribute_set_id', 'id')->addFieldToSelect('attribute_set_name', 'label')->setOrder('attribute_set_name', \Magento\Eav\Model\ResourceModel\Entity\Attribute\Set\Collection::SORT_ORDER_ASC); return $collection->getData(); }
/** * Retrieve list of attributes with admin store label containing $labelPart * * @param string $labelPart * @return \Magento\Catalog\Model\ResourceModel\Product\Attribute\Collection */ public function getSuggestedAttributes($labelPart) { $escapedLabelPart = $this->_resourceHelper->addLikeEscape($labelPart, ['position' => 'any']); /** @var $collection \Magento\Catalog\Model\ResourceModel\Product\Attribute\Collection */ $collection = $this->configurableAttributeHandler->getApplicableAttributes()->addFieldToFilter('frontend_label', ['like' => $escapedLabelPart]); $result = []; foreach ($collection->getItems() as $id => $attribute) { /** @var $attribute \Magento\Catalog\Model\ResourceModel\Eav\Attribute */ if ($this->configurableAttributeHandler->isAttributeApplicable($attribute)) { $result[$id] = ['id' => $attribute->getId(), 'label' => $attribute->getFrontendLabel(), 'code' => $attribute->getAttributeCode(), 'options' => $attribute->getSource()->getAllOptions(false)]; } } return $result; }