Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
SuggestedSet.php
Go to the documentation of this file.
1 <?php
7 
12 {
19 
25  protected $resourceHelper;
26 
30  protected $product;
31 
37  public function __construct(
38  \Magento\Catalog\Model\ResourceModel\Product $product,
39  \Magento\Eav\Model\ResourceModel\Entity\Attribute\Set\CollectionFactory $attributeSetCollectionFactory,
40  \Magento\Catalog\Model\ResourceModel\Helper $resourceHelper
41  ) {
42  $this->attributeSetCollectionFactory = $attributeSetCollectionFactory;
43  $this->resourceHelper = $resourceHelper;
44  $this->product = $product;
45  }
46 
53  public function getSuggestedSets($labelPart)
54  {
55  $labelPart = $this->resourceHelper->addLikeEscape($labelPart, ['position' => 'any']);
57  $collection = $this->attributeSetCollectionFactory->create();
58  $collection->setEntityTypeFilter(
59  $this->product->getTypeId()
60  )->addFieldToFilter(
61  'attribute_set_name',
62  ['like' => $labelPart]
63  )->addFieldToSelect(
64  'attribute_set_id',
65  'id'
66  )->addFieldToSelect(
67  'attribute_set_name',
68  'label'
69  )->setOrder(
70  'attribute_set_name',
71  \Magento\Eav\Model\ResourceModel\Entity\Attribute\Set\Collection::SORT_ORDER_ASC
72  );
73  return $collection->getData();
74  }
75 }
__construct(\Magento\Catalog\Model\ResourceModel\Product $product, \Magento\Eav\Model\ResourceModel\Entity\Attribute\Set\CollectionFactory $attributeSetCollectionFactory, \Magento\Catalog\Model\ResourceModel\Helper $resourceHelper)