/**
  * Get options.
  *
  * @return array
  */
 public function toOptionArray()
 {
     $attributes = $this->attributes->addVisibleFilter();
     $attributeArray = [];
     $attributeArray[] = ['label' => __('---- Default Option ----'), 'value' => '0'];
     foreach ($attributes as $attribute) {
         $attributeArray[] = ['label' => $attribute->getFrontendLabel(), 'value' => $attribute->getAttributeCode()];
     }
     return $attributeArray;
 }
 /**
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  */
 protected function setUp()
 {
     parent::setUp();
     $this->setCollectionFactory = $this->getMock('Magento\\Eav\\Model\\ResourceModel\\Entity\\Attribute\\Set\\CollectionFactory', ['create'], [], '', false);
     $this->setCollection = $this->getMock('Magento\\Eav\\Model\\ResourceModel\\Entity\\Attribute\\Set\\Collection', ['setEntityTypeFilter'], [], '', false);
     $this->setCollectionFactory->expects($this->any())->method('create')->will($this->returnValue($this->setCollection));
     $item = new \Magento\Framework\DataObject(['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\\ResourceModel\\Product\\Attribute\\CollectionFactory', ['create'], [], '', false);
     $this->attrCollection = $this->getMock('\\Magento\\Catalog\\Model\\ResourceModel\\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', 'getErrorAggregator', 'getAttributeOptions'], [], '', false);
     $this->_entityModel->method('getErrorAggregator')->willReturn($this->getErrorAggregatorObject());
     $this->params = [0 => $this->_entityModel, 1 => 'configurable'];
     $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', 'getConnection'], [], '', 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));
     $connectionMock = $this->getMock('Magento\\Framework\\DB\\Adapter\\Pdo\\Mysql', [], [], '', false);
     $connectionMock->expects($this->any())->method('quoteInto')->will($this->returnValue('query'));
     $this->select->expects($this->any())->method('getConnection')->willReturn($connectionMock);
     $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('fetchAll')->will($this->returnValue([]));
     $this->resource = $this->getMock('\\Magento\\Framework\\App\\ResourceConnection', ['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\\ResourceModel\\Product\\CollectionFactory', ['create'], [], '', false);
     $this->productCollection = $this->getMock('\\Magento\\Catalog\\Model\\ResourceModel\\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\\DataObject', ['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]);
 }
Exemplo n.º 3
0
 /**
  * {@inheritdoc}
  */
 public function getData()
 {
     $items = [];
     $skippedItems = 0;
     foreach ($this->getCollection()->getItems() as $attribute) {
         if ($this->configurableAttributeHandler->isAttributeApplicable($attribute)) {
             $items[] = $attribute->toArray();
         } else {
             $skippedItems++;
         }
     }
     return ['totalRecords' => $this->collection->getSize() - $skippedItems, 'items' => $items];
 }
 public function testGetAttributes()
 {
     $ids = [1];
     $result = [['id' => 'id', 'label' => 'label', 'code' => 'code', 'options' => ['options']]];
     $this->collectionMock->expects($this->any())->method('addFieldToFilter')->with('main_table.attribute_id', $ids);
     $this->attributeMock->expects($this->once())->method('getId')->will($this->returnValue('id'));
     $this->attributeMock->expects($this->once())->method('getFrontendLabel')->will($this->returnValue('label'));
     $this->attributeMock->expects($this->once())->method('getAttributeCode')->will($this->returnValue('code'));
     $source = $this->getMock('Magento\\Eav\\Model\\Entity\\Attribute\\Source\\AbstractSource', [], [], '', false);
     $source->expects($this->once())->method('getAllOptions')->with(false)->will($this->returnValue(['options']));
     $this->attributeMock->expects($this->once())->method('getSource')->will($this->returnValue($source));
     $this->assertEquals($result, $this->attributeListModel->getAttributes($ids));
 }
Exemplo n.º 5
0
 /**
  * {@inheritdoc}
  */
 public function resolve(array $fields)
 {
     $resolvedFields = [];
     foreach ($fields as $field) {
         if ('*' === $field) {
             $resolvedFields = [$this->fieldFactory->create(['attributeId' => null, 'column' => 'data_index', 'type' => FieldInterface::TYPE_FULLTEXT])];
             break;
         }
         $attribute = $this->attributeCollection->getItemByColumnValue('attribute_code', $field);
         $attributeId = $attribute ? $attribute->getId() : 0;
         $resolvedFields[$field] = $this->fieldFactory->create(['attributeId' => $attributeId, 'column' => 'data_index', 'type' => FieldInterface::TYPE_FULLTEXT]);
     }
     return $resolvedFields;
 }
Exemplo n.º 6
0
 /**
  * Retrieve attribute collection prefiltered with only attribute usable in rules.
  *
  * @return \Magento\Catalog\Model\ResourceModel\Product\Attribute\Collection
  */
 public function getAttributeCollection()
 {
     if ($this->attributeCollection === null) {
         $this->attributeCollection = $this->attributeCollectionFactory->create();
         $mapping = $this->getMapping();
         $attributeNameMapping = array_flip($this->fieldNameMapping);
         $arrayNameCb = function (FieldInterface $field) use($attributeNameMapping) {
             $attributeName = $field->getName();
             if (isset($attributeNameMapping[$attributeName])) {
                 $attributeName = $attributeNameMapping[$attributeName];
             }
             return $attributeName;
         };
         $attributeFilterCb = function (FieldInterface $field) use($mapping) {
             try {
                 $fieldName = $field->getName();
                 $optionTextFieldName = $this->mappingHelper->getOptionTextFieldName($fieldName);
                 $field = $mapping->getField($optionTextFieldName);
             } catch (\Exception $e) {
             }
             return $field->isFilterable() || $field->isSearchable();
         };
         $fieldNames = array_map($arrayNameCb, array_filter($this->getMapping()->getFields(), $attributeFilterCb));
         $this->attributeCollection->addFieldToFilter('attribute_code', $fieldNames)->addFieldToFilter('backend_type', ['neq' => 'datetime']);
     }
     return $this->attributeCollection;
 }
Exemplo n.º 7
0
 public function testGetPrefixes()
 {
     $entityTypeId = 3;
     /** @var \Magento\Eav\Model\Entity\Type|\PHPUnit_Framework_MockObject_MockObject $entityType */
     $entityType = $this->getMockBuilder('Magento\\Eav\\Model\\Entity\\Type')->disableOriginalConstructor()->getMock();
     $entityType->expects($this->once())->method('getId')->will($this->returnValue($entityTypeId));
     /** @var AbstractFrontend|\PHPUnit_Framework_MockObject_MockObject $frontend */
     $frontend = $this->getMockBuilder('Magento\\Eav\\Model\\Entity\\Attribute\\Frontend\\AbstractFrontend')->setMethods(['getLabel'])->disableOriginalConstructor()->getMockForAbstractClass();
     $frontend->expects($this->once())->method('getLabel')->will($this->returnValue('testLabel'));
     $this->attributeCollection->expects($this->once())->method('setEntityTypeFilter')->with($this->equalTo($entityTypeId));
     $this->attributeCollection->expects($this->once())->method('setFrontendInputTypeFilter')->with($this->equalTo('media_image'));
     $this->attribute->expects($this->once())->method('getAttributeCode')->will($this->returnValue('attributeCode'));
     $this->attribute->expects($this->once())->method('getFrontend')->will($this->returnValue($frontend));
     $this->attributeCollection->expects($this->any())->method('getIterator')->will($this->returnValue(new \ArrayIterator([$this->attribute])));
     $this->eavConfig->expects($this->any())->method('getEntityType')->with($this->equalTo(Product::ENTITY))->will($this->returnValue($entityType));
     $this->assertEquals([['field' => 'attributeCode_', 'label' => 'testLabel']], $this->model->getPrefixes());
 }
Exemplo n.º 8
0
 /**
  * @param string $code
  * @param string $backendType
  * @param string $backendTable
  * @param int $attributeId
  * @param string $frontendInput
  * @param int $positionInCollection
  */
 private function createAttributeMock($code, $backendType = null, $backendTable = null, $attributeId = 120, $frontendInput = 'select', $positionInCollection = 0)
 {
     $attribute = $this->getMockBuilder('\\Magento\\Catalog\\Model\\ResourceModel\\Eav\\Attribute')->setMethods(['getBackendType', 'getBackendTable', 'getId', 'getFrontendInput'])->disableOriginalConstructor()->getMock();
     $attribute->method('getId')->willReturn($attributeId);
     $attribute->method('getBackendType')->willReturn($backendType);
     $attribute->method('getBackendTable')->willReturn($backendTable);
     $attribute->method('getFrontendInput')->willReturn($frontendInput);
     $this->attributeCollection->expects($this->at($positionInCollection))->method('getItemByColumnValue')->with('attribute_code', $code)->willReturn($attribute);
 }
Exemplo n.º 9
0
 /**
  * Entity attributes collection getter.
  *
  * @return \Magento\Catalog\Model\ResourceModel\Product\Attribute\Collection
  */
 public function getAttributeCollection()
 {
     return $this->_attributeColFactory->create();
 }
 /**
  * @param \Magento\Catalog\Model\ResourceModel\Product\Attribute\Collection $collection
  * @return \Magento\Catalog\Model\ResourceModel\Product\Attribute\Collection
  */
 protected function _prepareAttributeCollection($collection)
 {
     $collection->addIsFilterableInSearchFilter()->addVisibleFilter();
     return $collection;
 }
Exemplo n.º 11
0
 /**
  * @param string $field
  * @return \Magento\Catalog\Model\ResourceModel\Eav\Attribute
  */
 private function getAttributeByCode($field)
 {
     $attribute = $this->attributeCollection->getItemByColumnValue('attribute_code', $field);
     return $attribute;
 }
Exemplo n.º 12
0
 /**
  * Attach Attributes By Id
  *
  * @param string $attributeSetName
  * @param array $attributeIds
  * @return void
  */
 protected function attachAttributesById($attributeSetName, $attributeIds)
 {
     foreach ($this->_prodAttrColFac->create()->addFieldToFilter('main_table.attribute_id', ['in' => $attributeIds]) as $attribute) {
         $attributeCode = $attribute->getAttributeCode();
         $attributeId = $attribute->getId();
         if ($attribute->getIsVisible() || in_array($attributeCode, $this->_forcedAttributesCodes)) {
             self::$commonAttributesCache[$attributeId] = ['id' => $attributeId, 'code' => $attributeCode, 'is_global' => $attribute->getIsGlobal(), 'is_required' => $attribute->getIsRequired(), 'is_unique' => $attribute->getIsUnique(), 'frontend_label' => $attribute->getFrontendLabel(), 'is_static' => $attribute->isStatic(), 'apply_to' => $attribute->getApplyTo(), 'type' => \Magento\ImportExport\Model\Import::getAttributeType($attribute), 'default_value' => strlen($attribute->getDefaultValue()) ? $attribute->getDefaultValue() : null, 'options' => $this->_entityModel->getAttributeOptions($attribute, $this->_indexValueAttributes)];
             self::$attributeCodeToId[$attributeCode] = $attributeId;
             $this->_addAttributeParams($attributeSetName, self::$commonAttributesCache[$attributeId], $attribute);
         }
     }
 }
Exemplo n.º 13
0
 /**
  * @return $this
  */
 public function _getAttributes()
 {
     $attributes = $this->attributeCollection->addFieldToFilter('is_visible', 1)->addFieldToFilter('frontend_input', ['nin' => ['boolean', 'date', 'datetime', 'gallery', 'image', 'media_image', 'select', 'multiselect', 'textarea']])->load();
     return $attributes;
 }
Exemplo n.º 14
0
 /**
  * Load the attributes displayed in the suggest.
  *
  * @return \Smile\ElasticsuiteCatalog\Model\Autocomplete\Product\Attribute\DataProvider
  */
 private function loadAttributeCollection()
 {
     $storeId = $this->storeManager->getStore()->getId();
     $this->attributeCollection->addStoreLabel($storeId)->addFieldToFilter('is_displayed_in_autocomplete', true)->load();
     return $this;
 }
Exemplo n.º 15
0
 protected function _toOptionArray($valueField = 'attribute_code', $labelField = 'frontend_label', $additional = array())
 {
     $this->addVisibleFilter();
     return parent::_toOptionArray($valueField, $labelField, $additional);
 }