Пример #1
0
 protected function setUp()
 {
     $this->entityModel = $this->getMock('Magento\\CatalogImportExport\\Model\\Import\\Product', ['getBehavior', 'getNewSku', 'getNextBunch', 'isRowAllowedToImport', 'getRowScope', 'getConnection'], [], '', false);
     $this->connection = $this->getMock('Magento\\Framework\\DB\\Adapter\\Pdo\\Mysql', ['select', 'fetchAll', 'fetchPairs', 'joinLeft', 'insertOnDuplicate', 'delete', 'quoteInto', 'fetchAssoc'], [], '', false);
     $select = $this->getMock('Magento\\Framework\\DB\\Select', [], [], '', false);
     $select->expects($this->any())->method('from')->will($this->returnSelf());
     $select->expects($this->any())->method('where')->will($this->returnSelf());
     $select->expects($this->any())->method('joinLeft')->will($this->returnSelf());
     $adapter = $this->getMock('Magento\\Framework\\DB\\Adapter\\Pdo\\Mysql', [], [], '', false);
     $adapter->expects($this->any())->method('quoteInto')->will($this->returnValue('query'));
     $select->expects($this->any())->method('getAdapter')->willReturn($adapter);
     $this->connection->expects($this->any())->method('select')->will($this->returnValue($select));
     $this->connection->expects($this->any())->method('fetchPairs')->will($this->returnValue(['1' => '1', '2' => '2']));
     $this->connection->expects($this->any())->method('insertOnDuplicate')->willReturnSelf();
     $this->connection->expects($this->any())->method('delete')->willReturnSelf();
     $this->connection->expects($this->any())->method('quoteInto')->willReturn('');
     $this->resource = $this->getMock('Magento\\Framework\\App\\Resource', ['getConnection', 'getTableName'], [], '', false);
     $this->resource->expects($this->any())->method('getConnection')->will($this->returnValue($this->connection));
     $this->resource->expects($this->any())->method('getTableName')->will($this->returnValue('tableName'));
     $this->attrSetColFac = $this->getMock('Magento\\Eav\\Model\\Resource\\Entity\\Attribute\\Set\\CollectionFactory', ['create'], [], '', false);
     $this->setCollection = $this->getMock('Magento\\Eav\\Model\\Resource\\Entity\\Attribute\\Set\\Collection', ['setEntityTypeFilter'], [], '', false);
     $this->attrSetColFac->expects($this->any())->method('create')->will($this->returnValue($this->setCollection));
     $this->setCollection->expects($this->any())->method('setEntityTypeFilter')->will($this->returnValue([]));
     $this->prodAttrColFac = $this->getMock('Magento\\Catalog\\Model\\Resource\\Product\\Attribute\\CollectionFactory', ['create'], [], '', false);
     $attrCollection = $this->getMock('\\Magento\\Catalog\\Model\\Resource\\Product\\Attribute\\Collection', [], [], '', false);
     $attrCollection->expects($this->any())->method('addFieldToFilter')->willReturn([]);
     $this->prodAttrColFac->expects($this->any())->method('create')->will($this->returnValue($attrCollection));
     $this->params = [0 => $this->entityModel, 1 => 'bundle'];
     $this->objectManagerHelper = new ObjectManagerHelper($this);
     $this->bundle = $this->objectManagerHelper->getObject('Magento\\BundleImportExport\\Model\\Import\\Product\\Type\\Bundle', ['attrSetColFac' => $this->attrSetColFac, 'prodAttrColFac' => $this->prodAttrColFac, 'resource' => $this->resource, 'params' => $this->params]);
 }
 /**
  * {@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();
 }
Пример #3
0
 protected function setUp()
 {
     $this->eavConfig = $this->getMockBuilder('Magento\\Eav\\Model\\Config')->disableOriginalConstructor()->getMock();
     $this->attributeCollection = $this->getMockBuilder('\\Magento\\Catalog\\Model\\Resource\\Product\\Attribute\\Collection')->disableOriginalConstructor()->getMock();
     $this->attributeCollectionFactory = $this->getMockBuilder('Magento\\Catalog\\Model\\Resource\\Product\\Attribute\\CollectionFactory')->setMethods(['create'])->disableOriginalConstructor()->getMock();
     $this->attributeCollectionFactory->expects($this->any())->method('create')->will($this->returnValue($this->attributeCollection));
     $this->attribute = $this->getMockBuilder('Magento\\Eav\\Model\\Entity\\Attribute')->disableOriginalConstructor()->getMock();
     $helper = new ObjectManager($this);
     $this->model = $helper->getObject('Magento\\Catalog\\Model\\Config\\CatalogClone\\Media\\Image', ['eavConfig' => $this->eavConfig, 'attributeCollectionFactory' => $this->attributeCollectionFactory]);
 }
Пример #4
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));
 }
Пример #5
0
 /**
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  */
 protected function setUp()
 {
     $this->setCollectionFactory = $this->getMock('Magento\\Eav\\Model\\Resource\\Entity\\Attribute\\Set\\CollectionFactory', ['create'], [], '', false);
     $this->setCollection = $this->getMock('Magento\\Eav\\Model\\Resource\\Entity\\Attribute\\Set\\Collection', ['setEntityTypeFilter'], [], '', false);
     $this->setCollectionFactory->expects($this->any())->method('create')->will($this->returnValue($this->setCollection));
     $item = new \Magento\Framework\Object(['id' => 1, 'attribute_set_name' => 'Default', '_attribute_set' => 'Default']);
     $this->setCollection->expects($this->any())->method('setEntityTypeFilter')->will($this->returnValue([$item]));
     $this->attrCollectionFactory = $this->getMock('Magento\\Catalog\\Model\\Resource\\Product\\Attribute\\CollectionFactory', ['create'], [], '', false);
     $this->attrCollection = $this->getMock('\\Magento\\Catalog\\Model\\Resource\\Product\\Attribute\\Collection', ['setAttributeSetFilter'], [], '', false);
     $superAttributes = [];
     foreach ($this->_getSuperAttributes() as $superAttribute) {
         $item = $this->getMock('\\Magento\\Eav\\Model\\Entity\\Attribute\\AbstractAttribute', ['isStatic'], $superAttribute, '', false);
         $item->setData($superAttribute);
         $item->method('isStatic')->will($this->returnValue(false));
         $superAttributes[] = $item;
     }
     $this->attrCollectionFactory->expects($this->any())->method('create')->will($this->returnValue($this->attrCollection));
     $this->attrCollection->expects($this->any())->method('setAttributeSetFilter')->will($this->returnValue($superAttributes));
     $this->_entityModel = $this->getMock('Magento\\CatalogImportExport\\Model\\Import\\Product', ['getNewSku', 'getOldSku', 'getNextBunch', 'isRowAllowedToImport', 'getConnection', 'getAttrSetIdToName', 'getAttributeOptions'], [], '', false);
     $this->params = [0 => $this->_entityModel, 1 => 'configurable'];
     $this->objectManagerHelper = new ObjectManagerHelper($this);
     $this->_connection = $this->getMock('Magento\\Framework\\DB\\Adapter\\Pdo\\Mysql', ['select', 'fetchAll', 'fetchPairs', 'joinLeft', 'insertOnDuplicate', 'delete', 'quoteInto'], [], '', false);
     $this->select = $this->getMock('Magento\\Framework\\DB\\Select', ['from', 'where', 'joinLeft', 'getAdapter'], [], '', false);
     $this->select->expects($this->any())->method('from')->will($this->returnSelf());
     $this->select->expects($this->any())->method('where')->will($this->returnSelf());
     $this->select->expects($this->any())->method('joinLeft')->will($this->returnSelf());
     $this->_connection->expects($this->any())->method('select')->will($this->returnValue($this->select));
     $adapter = $this->getMock('Magento\\Framework\\DB\\Adapter\\Pdo\\Mysql', [], [], '', false);
     $adapter->expects($this->any())->method('quoteInto')->will($this->returnValue('query'));
     $this->select->expects($this->any())->method('getAdapter')->willReturn($adapter);
     $this->_connection->expects($this->any())->method('insertOnDuplicate')->willReturnSelf();
     $this->_connection->expects($this->any())->method('delete')->willReturnSelf();
     $this->_connection->expects($this->any())->method('quoteInto')->willReturn('');
     $this->_connection->expects($this->any())->method('fetchPairs')->will($this->returnValue([]));
     $this->resource = $this->getMock('\\Magento\\Framework\\App\\Resource', ['getConnection', 'getTableName'], [], '', false);
     $this->resource->expects($this->any())->method('getConnection')->will($this->returnValue($this->_connection));
     $this->resource->expects($this->any())->method('getTableName')->will($this->returnValue('tableName'));
     $this->_entityModel->expects($this->any())->method('getConnection')->will($this->returnValue($this->_connection));
     $this->productCollectionFactory = $this->getMock('\\Magento\\Catalog\\Model\\Resource\\Product\\CollectionFactory', ['create'], [], '', false);
     $this->productCollection = $this->getMock('\\Magento\\Catalog\\Model\\Resource\\Product\\Collection', ['addFieldToFilter', 'addAttributeToSelect'], [], '', false);
     $products = [];
     $testProducts = [['id' => 1, 'attribute_set_id' => 4, 'testattr2' => 1, 'testattr3' => 1], ['id' => 2, 'attribute_set_id' => 4, 'testattr2' => 1, 'testattr3' => 1], ['id' => 20, 'attribute_set_id' => 4, 'testattr2' => 1, 'testattr3' => 1]];
     foreach ($testProducts as $product) {
         $item = $this->getMock('\\Magento\\Framework\\Object', ['getAttributeSetId'], [], '', false);
         $item->setData($product);
         $item->expects($this->any())->method('getAttributeSetId')->willReturn(4);
         $products[] = $item;
     }
     $this->productCollectionFactory->expects($this->any())->method('create')->will($this->returnValue($this->productCollection));
     $this->productCollection->expects($this->any())->method('addFieldToFilter')->will($this->returnValue($this->productCollection));
     $this->productCollection->expects($this->any())->method('addAttributeToSelect')->will($this->returnValue($products));
     $this->_entityModel->expects($this->any())->method('getAttributeOptions')->will($this->returnValue(['attr2val1' => '1', 'attr2val2' => '2', 'attr2val3' => '3', 'testattr3v1' => '4', 'testattr30v1' => '4', 'testattr3v2' => '5', 'testattr3v3' => '6']));
     $this->configurable = $this->objectManagerHelper->getObject('Magento\\ConfigurableImportExport\\Model\\Import\\Product\\Type\\Configurable', ['attrSetColFac' => $this->setCollectionFactory, 'prodAttrColFac' => $this->attrCollectionFactory, 'params' => $this->params, 'resource' => $this->resource, 'productColFac' => $this->productCollectionFactory]);
 }
Пример #6
0
 /**
  * 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;
 }
Пример #7
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;
 }
Пример #8
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;
 }
Пример #9
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;
 }
Пример #10
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;
 }
Пример #11
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;
 }
Пример #12
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;
 }
Пример #13
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;
 }
Пример #14
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;
 }
Пример #15
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;
 }
Пример #16
0
 public function testGetList()
 {
     $productCollectionMock = $this->getMock('\\Magento\\Catalog\\Model\\Resource\\Product\\Collection', [], [], '', false);
     $this->layerMock->expects($this->once())->method('getProductCollection')->will($this->returnValue($productCollectionMock));
     $setIds = [2, 3, 5];
     $productCollectionMock->expects($this->once())->method('getSetIds')->will($this->returnValue($setIds));
     $storeMock = $this->getMock('\\Magento\\Store\\Model\\Store', [], [], '', false);
     $this->storeManagerMock->expects($this->once())->method('getStore')->will($this->returnValue($storeMock));
     $storeId = 4321;
     $storeMock->expects($this->once())->method('getId')->will($this->returnValue($storeId));
     $collectionMock = $this->getMock('\\Magento\\Catalog\\Model\\Resource\\Product\\Attribute\\Collection', [], [], '', false);
     $this->collectionFactoryMock->expects($this->once())->method('create')->will($this->returnValue($collectionMock));
     $collectionMock->expects($this->once())->method('setItemObjectClass')->with('Magento\\Catalog\\Model\\Resource\\Eav\\Attribute')->will($this->returnSelf());
     $collectionMock->expects($this->once())->method('setAttributeSetFilter')->with($setIds)->will($this->returnSelf());
     $collectionMock->expects($this->once())->method('addStoreLabel')->with($storeId)->will($this->returnSelf());
     $collectionMock->expects($this->once())->method('setOrder')->with('position', 'ASC');
     $collectionMock->expects($this->once())->method('addIsFilterableInSearchFilter')->will($this->returnSelf());
     $collectionMock->expects($this->once())->method('load');
     $this->assertEquals($collectionMock, $this->model->getList());
 }
Пример #17
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;
 }
Пример #18
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;
 }
Пример #19
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;
 }
Пример #20
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());
 }
Пример #21
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);
 }
 /**
  * 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);
 }
Пример #23
0
 /**
  * Prepare product attributes grid collection object
  *
  * @return $this
  */
 protected function _prepareCollection()
 {
     $collection = $this->_collectionFactory->create()->addVisibleFilter();
     $this->setCollection($collection);
     return parent::_prepareCollection();
 }