/**
  * {@inheritdoc}
  */
 public function getList($attributeSetName)
 {
     /** @var \Magento\Catalog\Model\Resource\Product\Attribute\Collection $collection */
     $collection = $this->collectionFactory->create();
     $collection->setAttributeSetFilterBySetName($attributeSetName, Product::ENTITY);
     $collection->setFrontendInputTypeFilter('media_image');
     $collection->addStoreLabel($this->storeManager->getStore()->getId());
     return $collection->getItems();
 }
Beispiel #2
0
 /**
  * Search for attributes by part of attribute's label in admin store
  *
  * @return void
  */
 public function execute()
 {
     $this->storeManager->setCurrentStore(\Magento\Store\Model\Store::ADMIN_CODE);
     $collection = $this->collectionFactory->create();
     $collection->addFieldToFilter('main_table.attribute_id', $this->getRequest()->getParam('attributes'));
     $attributes = [];
     foreach ($collection->getItems() as $attribute) {
         $attributes[] = ['id' => $attribute->getId(), 'label' => $attribute->getFrontendLabel(), 'code' => $attribute->getAttributeCode(), 'options' => $attribute->getSource()->getAllOptions(false)];
     }
     $this->getResponse()->representJson($this->jsonHelper->jsonEncode($attributes));
 }
Beispiel #3
0
 /**
  * Retrieve list of attributes with admin store label containing $labelPart
  *
  * @param string $labelPart
  * @param int $templateId
  * @return \Magento\Catalog\Model\Resource\Product\Attribute\Collection
  */
 public function getSuggestedAttributes($labelPart, $templateId = null)
 {
     $escapedLabelPart = $this->_resourceHelper->addLikeEscape($labelPart, ['position' => 'any']);
     /** @var $collection \Magento\Catalog\Model\Resource\Product\Attribute\Collection */
     $collection = $this->_collectionFactory->create()->addFieldToFilter('frontend_label', ['like' => $escapedLabelPart]);
     $collection->setExcludeSetFilter($templateId ?: $this->getRequest()->getParam('template_id'))->setPageSize(20);
     $result = [];
     foreach ($collection->getItems() as $attribute) {
         /** @var $attribute \Magento\Catalog\Model\Resource\Eav\Attribute */
         $result[] = ['id' => $attribute->getId(), 'label' => $attribute->getFrontendLabel(), 'code' => $attribute->getAttributeCode()];
     }
     return $result;
 }
 /**
  * Retrieve list of filterable attributes
  *
  * @return array|\Magento\Catalog\Model\Resource\Product\Attribute\Collection
  */
 public function getList()
 {
     $setIds = $this->layer->getProductCollection()->getSetIds();
     if (!$setIds) {
         return array();
     }
     /** @var $collection \Magento\Catalog\Model\Resource\Product\Attribute\Collection */
     $collection = $this->collectionFactory->create();
     $collection->setItemObjectClass('Magento\\Catalog\\Model\\Resource\\Eav\\Attribute')->setAttributeSetFilter($setIds)->addStoreLabel($this->storeManager->getStore()->getId())->setOrder('position', 'ASC');
     $collection = $this->_prepareAttributeCollection($collection);
     $collection->load();
     return $collection;
 }
Beispiel #5
0
 /**
  * Check if group contains system attributes
  *
  * @return bool
  */
 public function hasSystemAttributes()
 {
     $result = false;
     /** @var $attributesCollection \Magento\Catalog\Model\Resource\Product\Attribute\Collection */
     $attributesCollection = $this->_attributeCollectionFactory->create();
     $attributesCollection->setAttributeGroupFilter($this->getId());
     foreach ($attributesCollection as $attribute) {
         if (!$attribute->getIsUserDefined()) {
             $result = true;
             break;
         }
     }
     return $result;
 }
Beispiel #6
0
 /**
  * Get fields prefixes
  *
  * @return array
  */
 public function getPrefixes()
 {
     // use cached eav config
     $entityTypeId = $this->_eavConfig->getEntityType(\Magento\Catalog\Model\Product::ENTITY)->getId();
     /* @var $collection \Magento\Catalog\Model\Resource\Product\Attribute\Collection */
     $collection = $this->_attributeCollectionFactory->create();
     $collection->setEntityTypeFilter($entityTypeId);
     $collection->setFrontendInputTypeFilter('media_image');
     $prefixes = [];
     foreach ($collection as $attribute) {
         /* @var $attribute \Magento\Eav\Model\Entity\Attribute */
         $prefixes[] = ['field' => $attribute->getAttributeCode() . '_', 'label' => $attribute->getFrontend()->getLabel()];
     }
     return $prefixes;
 }
Beispiel #7
0
 /**
  * Retrieve searchable attributes
  *
  * @param string $backendType
  * @return \Magento\Eav\Model\Entity\Attribute[]
  */
 protected function getSearchableAttributes($backendType = null)
 {
     if (null === $this->searchableAttributes) {
         $this->searchableAttributes = [];
         $productAttributes = $this->productAttributeCollectionFactory->create();
         $productAttributes->addToIndexFilter(true);
         /** @var \Magento\Eav\Model\Entity\Attribute[] $attributes */
         $attributes = $productAttributes->getItems();
         $this->eventManager->dispatch('catelogsearch_searchable_attributes_load_after', ['engine' => $this->engineProvider->get(), 'attributes' => $attributes]);
         $entity = $this->getEavConfig()->getEntityType(\Magento\Catalog\Model\Product::ENTITY)->getEntity();
         foreach ($attributes as $attribute) {
             $attribute->setEntity($entity);
         }
         $this->searchableAttributes = $attributes;
     }
     if ($backendType !== null) {
         $attributes = [];
         foreach ($this->searchableAttributes as $attributeId => $attribute) {
             if ($attribute->getBackendType() == $backendType) {
                 $attributes[$attributeId] = $attribute;
             }
         }
         return $attributes;
     }
     return $this->searchableAttributes;
 }
Beispiel #8
0
 /**
  * Retrieve searchable attributes
  *
  * @param string $backendType
  * @return array
  */
 protected function _getSearchableAttributes($backendType = null)
 {
     if (null === $this->_searchableAttributes) {
         $this->_searchableAttributes = array();
         $productAttributes = $this->_productAttributeCollectionFactory->create();
         if ($this->_engineProvider->get() && $this->_engineProvider->get()->allowAdvancedIndex()) {
             $productAttributes->addToIndexFilter(true);
         } else {
             $productAttributes->addSearchableAttributeFilter();
         }
         $attributes = $productAttributes->getItems();
         $this->_eventManager->dispatch('catelogsearch_searchable_attributes_load_after', array('engine' => $this->_engineProvider->get(), 'attributes' => $attributes));
         $entity = $this->getEavConfig()->getEntityType(\Magento\Catalog\Model\Product::ENTITY)->getEntity();
         foreach ($attributes as $attribute) {
             $attribute->setEntity($entity);
         }
         $this->_searchableAttributes = $attributes;
     }
     if (!is_null($backendType)) {
         $attributes = array();
         foreach ($this->_searchableAttributes as $attributeId => $attribute) {
             if ($attribute->getBackendType() == $backendType) {
                 $attributes[$attributeId] = $attribute;
             }
         }
         return $attributes;
     }
     return $this->_searchableAttributes;
 }
 /**
  * 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;
 }
 /**
  * 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;
 }
Beispiel #11
0
 /**
  * Retrieve searchable attributes
  *
  * @return Attribute[]
  */
 private function getSearchableAttributes()
 {
     if ($this->searchableAttributes === null) {
         $this->searchableAttributes = [];
         /** @var \Magento\Catalog\Model\Resource\Product\Attribute\Collection $productAttributes */
         $productAttributes = $this->collectionFactory->create();
         $productAttributes->addToIndexFilter(true);
         /** @var \Magento\Eav\Model\Entity\Attribute[] $attributes */
         $attributes = $productAttributes->getItems();
         $entity = $this->eavConfig->getEntityType(Product::ENTITY)->getEntity();
         foreach ($attributes as $attribute) {
             $attribute->setEntity($entity);
         }
         $this->searchableAttributes = $attributes;
     }
     return $this->searchableAttributes;
 }
Beispiel #12
0
 /**
  * Retrieve collection of all attributes
  *
  * @return \Magento\Framework\Data\Collection\AbstractDb
  */
 protected function _getAttributesCollection()
 {
     if (!$this->_attributesCollection) {
         $this->_attributesCollection = $this->_attributeCollectionFactory->create()->load();
         foreach ($this->_attributesCollection as $attribute) {
             $attribute->setEntity($this->getEntity());
         }
     }
     return $this->_attributesCollection;
 }
Beispiel #13
0
 /**
  * Retrieve searchable attributes list
  *
  * @return array
  */
 protected function _getSearchableAttributes()
 {
     if (is_null($this->_searchableAttributes)) {
         /** @var $attributeCollection \Magento\Catalog\Model\Resource\Product\Attribute\Collection */
         $attributeCollection = $this->_attributeCollectionFactory->create();
         $attributeCollection->addIsSearchableFilter();
         foreach ($attributeCollection as $attribute) {
             $this->_searchableAttributes[] = $attribute->getAttributeCode();
         }
     }
     return $this->_searchableAttributes;
 }
Beispiel #14
0
 /**
  * Retrieve array of attributes used in advanced search
  *
  * @return array|\Magento\Catalog\Model\Resource\Product\Attribute\Collection
  */
 public function getAttributes()
 {
     $attributes = $this->getData('attributes');
     if ($attributes === null) {
         $product = $this->_productFactory->create();
         $attributes = $this->_attributeCollectionFactory->create()->addHasOptionsFilter()->addDisplayInAdvancedSearchFilter()->addStoreLabel($this->_storeManager->getStore()->getId())->setOrder('main_table.attribute_id', 'asc')->load();
         foreach ($attributes as $attribute) {
             $attribute->setEntity($product->getResource());
         }
         $this->setData('attributes', $attributes);
     }
     return $attributes;
 }
Beispiel #15
0
 /**
  * Loads all attributes with options for attribute
  *
  * @param string $attributeCode
  * @return $this
  */
 protected function loadAttributeOptions($attributeCode)
 {
     /** @var \Magento\Catalog\Model\Resource\Product\Attribute\Collection $collection */
     $collection = $this->attributeCollectionFactory->create();
     $collection->addFieldToSelect(['attribute_code', 'attribute_id']);
     $collection->addFieldToFilter('attribute_code', $attributeCode);
     $collection->setFrontendInputTypeFilter(['in' => ['select', 'multiselect']]);
     foreach ($collection as $item) {
         $options = $this->attrOptionCollectionFactory->create()->setAttributeFilter($item->getAttributeId())->setPositionOrder('asc', true)->load();
         $this->attributeCodeOptionsPair[$item->getAttributeCode()] = $options;
     }
     return $this;
 }
Beispiel #16
0
 /**
  * {@inheritdoc}
  */
 public function types($attributeSetId)
 {
     $attributeSet = $this->setFactory->create()->load($attributeSetId);
     if (!$attributeSet->getId()) {
         throw NoSuchEntityException::singleField('attribute_set_id', $attributeSetId);
     }
     $productEntityId = $this->eavConfig->getEntityType(\Magento\Catalog\Model\Product::ENTITY)->getId();
     if ($attributeSet->getEntityTypeId() != $productEntityId) {
         throw InputException::invalidFieldValue('entity_type_id', $attributeSetId);
     }
     $collection = $this->collectionFactory->create();
     $collection->setAttributeSetFilter($attributeSetId);
     $collection->setFrontendInputTypeFilter('media_image');
     $collection->addStoreLabel($this->storeManager->getStore()->getId());
     return $this->prepareData($collection->getItems());
 }
Beispiel #17
0
 /**
  * Retrieve Unused in Attribute Set Attribute Tree as JSON
  *
  * @return string
  */
 public function getAttributeTreeJson()
 {
     $items = [];
     $setId = $this->_getSetId();
     $collection = $this->_collectionFactory->create()->setAttributeSetFilter($setId)->load();
     $attributesIds = ['0'];
     /* @var $item \Magento\Eav\Model\Entity\Attribute */
     foreach ($collection->getItems() as $item) {
         $attributesIds[] = $item->getAttributeId();
     }
     $attributes = $this->_collectionFactory->create()->setAttributesExcludeFilter($attributesIds)->addVisibleFilter()->load();
     foreach ($attributes as $child) {
         $attr = ['text' => $child->getAttributeCode(), 'id' => $child->getAttributeId(), 'cls' => 'leaf', 'allowDrop' => false, 'allowDrag' => true, 'leaf' => true, 'is_user_defined' => $child->getIsUserDefined(), 'entity_id' => $child->getEntityId()];
         $items[] = $attr;
     }
     if (count($items) == 0) {
         $items[] = ['text' => __('Empty'), 'id' => 'empty', 'cls' => 'folder', 'allowDrop' => false, 'allowDrag' => false];
     }
     return $this->_jsonEncoder->encode($items);
 }
Beispiel #18
0
 /**
  * Prepare product attributes grid collection object
  *
  * @return $this
  */
 protected function _prepareCollection()
 {
     $collection = $this->_collectionFactory->create()->addVisibleFilter();
     $this->setCollection($collection);
     return parent::_prepareCollection();
 }
 /**
  * Retrieve list of attributes applicable for configurable product
  *
  * @return \Magento\Catalog\Model\Resource\Product\Attribute\Collection
  */
 public function getApplicableAttributes()
 {
     /** @var $collection \Magento\Catalog\Model\Resource\Product\Attribute\Collection */
     $collection = $this->collectionFactory->create();
     return $collection->addFieldToFilter('frontend_input', 'select')->addFieldToFilter('is_user_defined', 1)->addFieldToFilter('is_global', \Magento\Catalog\Model\Resource\Eav\Attribute::SCOPE_GLOBAL);
 }