Пример #1
0
 /**
  * Retrieve list of product templates with search part contained in label
  *
  * @param string $labelPart
  * @return array
  */
 public function getSuggestedTemplates($labelPart)
 {
     $product = $this->_coreRegistry->registry('product');
     $entityType = $product->getResource()->getEntityType();
     $labelPart = $this->_resourceHelper->addLikeEscape($labelPart, ['position' => 'any']);
     /** @var \Magento\Eav\Model\Resource\Entity\Attribute\Set\Collection $collection */
     $collection = $this->_setColFactory->create();
     $collection->setEntityTypeFilter($entityType->getId())->addFieldToFilter('attribute_set_name', ['like' => $labelPart])->addFieldToSelect('attribute_set_id', 'id')->addFieldToSelect('attribute_set_name', 'label')->setOrder('attribute_set_name', \Magento\Eav\Model\Resource\Entity\Attribute\Set\Collection::SORT_ORDER_ASC);
     return $collection->getData();
 }
Пример #2
0
 /**
  * Retrieve list of attributes with admin store label containing $labelPart
  *
  * @param string $labelPart
  * @return \Magento\Catalog\Model\Resource\Product\Attribute\Collection
  */
 public function getSuggestedAttributes($labelPart)
 {
     $escapedLabelPart = $this->_resourceHelper->addLikeEscape($labelPart, ['position' => 'any']);
     /** @var $collection \Magento\Catalog\Model\Resource\Product\Attribute\Collection */
     $collection = $this->configurableAttributeHandler->getApplicableAttributes()->addFieldToFilter('frontend_label', ['like' => $escapedLabelPart]);
     $result = [];
     foreach ($collection->getItems() as $id => $attribute) {
         /** @var $attribute \Magento\Catalog\Model\Resource\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;
 }
Пример #3
0
 /**
  * Retrieve list of attributes with admin store label containing $labelPart
  *
  * @param string $labelPart
  * @return \Magento\Catalog\Model\Resource\Product\Attribute\Collection
  */
 public function getSuggestedAttributes($labelPart)
 {
     $escapedLabelPart = $this->_resourceHelper->addLikeEscape($labelPart, array('position' => 'any'));
     /** @var $collection \Magento\Catalog\Model\Resource\Product\Attribute\Collection */
     $collection = $this->_attributeColFactory->create();
     $collection->addFieldToFilter('frontend_input', 'select')->addFieldToFilter('frontend_label', array('like' => $escapedLabelPart))->addFieldToFilter('is_configurable', array(array("eq" => 1), array('null' => true)))->addFieldToFilter('is_user_defined', 1)->addFieldToFilter('is_global', \Magento\Catalog\Model\Resource\Eav\Attribute::SCOPE_GLOBAL);
     $result = array();
     $types = array(\Magento\Catalog\Model\Product\Type::TYPE_SIMPLE, \Magento\Catalog\Model\Product\Type::TYPE_VIRTUAL, \Magento\ConfigurableProduct\Model\Product\Type\Configurable::TYPE_CODE);
     foreach ($collection->getItems() as $id => $attribute) {
         /** @var $attribute \Magento\Catalog\Model\Resource\Eav\Attribute */
         if (!$attribute->getApplyTo() || count(array_diff($types, $attribute->getApplyTo())) === 0) {
             $result[$id] = array('id' => $attribute->getId(), 'label' => $attribute->getFrontendLabel(), 'code' => $attribute->getAttributeCode(), 'options' => $attribute->getSource()->getAllOptions(false));
         }
     }
     return $result;
 }
Пример #4
0
 /**
  * Retrieve list of attributes with admin store label containing $labelPart
  *
  * @param string $labelPart
  * @return \Magento\Catalog\Model\Resource\Product\Attribute\Collection
  */
 public function getSuggestedAttributes($labelPart)
 {
     $escapedLabelPart = $this->resourceHelper->addLikeEscape($labelPart, ['position' => 'any']);
     $availableFrontendTypes = $this->getAvailableFrontendTypes();
     /** @var $collection \Magento\Catalog\Model\Resource\Product\Attribute\Collection */
     $collection = $this->attributeCollectionFactory->create();
     $collection->addFieldToFilter('main_table.frontend_input', ['in' => $availableFrontendTypes->getData('values')])->addFieldToFilter('frontend_label', ['like' => $escapedLabelPart])->addFieldToFilter('is_user_defined', 1)->addFieldToFilter('is_global', \Magento\Catalog\Model\Resource\Eav\Attribute::SCOPE_GLOBAL);
     $result = [];
     $types = [\Magento\Catalog\Model\Product\Type::TYPE_SIMPLE, \Magento\Catalog\Model\Product\Type::TYPE_VIRTUAL, \Magento\ConfigurableProduct\Model\Product\Type\Configurable::TYPE_CODE];
     foreach ($collection->getItems() as $id => $attribute) {
         /** @var $attribute \Magento\Catalog\Model\Resource\Eav\Attribute */
         if (!$attribute->getApplyTo() || count(array_diff($types, $attribute->getApplyTo())) === 0) {
             $result[$id] = ['id' => $attribute->getId(), 'label' => $attribute->getFrontendLabel(), 'code' => $attribute->getAttributeCode(), 'options' => $attribute->getSource()->getAllOptions(false)];
         }
     }
     return $result;
 }