Пример #1
0
 public function testAddAttributeGrouping()
 {
     $select = $this->_model->getSelect();
     $this->assertEmpty($select->getPart(\Zend_Db_Select::GROUP));
     $this->_model->addAttributeGrouping();
     $this->assertEquals(['main_table.attribute_id'], $select->getPart(\Zend_Db_Select::GROUP));
 }
 /**
  * {@inheritdoc}
  */
 public function getAttributes($entityType, $attributeSetId)
 {
     /** @var \Magento\Eav\Api\Data\AttributeSetInterface $attributeSet */
     $attributeSet = $this->setRepository->get($attributeSetId);
     $requiredEntityTypeId = $this->eavConfig->getEntityType($entityType)->getId();
     if (!$attributeSet->getAttributeSetId() || $attributeSet->getEntityTypeId() != $requiredEntityTypeId) {
         throw NoSuchEntityException::singleField('attributeSetId', $attributeSetId);
     }
     $attributeCollection = $this->attributeCollection->setAttributeSetFilter($attributeSet->getAttributeSetId())->load();
     return $attributeCollection->getItems();
 }
Пример #3
0
 /**
  * {@inheritdoc}
  */
 public function getAttributeList($attributeSetId)
 {
     /** @var \Magento\Eav\Model\Entity\Attribute\Set $attributeSet */
     $attributeSet = $this->setFactory->create()->load($attributeSetId);
     $requiredEntityTypeId = $this->eavConfig->getEntityType(\Magento\Catalog\Model\Product::ENTITY)->getId();
     if (!$attributeSet->getId() || $attributeSet->getEntityTypeId() != $requiredEntityTypeId) {
         // Attribute set does not exist
         throw NoSuchEntityException::singleField('attributeSetId', $attributeSetId);
     }
     $attributeCollection = $this->attributeCollection->setAttributeSetFilter($attributeSet->getId())->load();
     $attributes = array();
     /** @var \Magento\Eav\Model\Entity\Attribute $attribute */
     foreach ($attributeCollection as $attribute) {
         $attributes[] = $this->attributeBuilder->setId($attribute->getAttributeId())->setCode($attribute->getAttributeCode())->setFrontendLabel($attribute->getData('frontend_label'))->setDefaultValue($attribute->getDefaultValue())->setIsRequired((bool) $attribute->getData('is_required'))->setIsUserDefined((bool) $attribute->getData('is_user_defined'))->setFrontendInput($attribute->getData('frontend_input'))->create();
     }
     return $attributes;
 }
Пример #4
0
 /**
  * Return collection of same attributes for selected products without unique
  *
  * @return \Magento\Eav\Model\Resource\Entity\Attribute\Collection
  */
 public function getAttributes()
 {
     if ($this->_attributes === null) {
         $this->_attributes = $this->_eavConfig->getEntityType(\Magento\Catalog\Model\Product::ENTITY)->getAttributeCollection()->addIsNotUniqueFilter()->setInAllAttributeSetsFilter($this->getProductsSetIds());
         if ($this->_excludedAttributes) {
             $this->_attributes->addFieldToFilter('attribute_code', ['nin' => $this->_excludedAttributes]);
         }
         // check product type apply to limitation and remove attributes that impossible to change in mass-update
         $productTypeIds = $this->getProducts()->getProductTypeIds();
         foreach ($this->_attributes as $attribute) {
             /* @var $attribute \Magento\Catalog\Model\Entity\Attribute */
             foreach ($productTypeIds as $productTypeId) {
                 $applyTo = $attribute->getApplyTo();
                 if (count($applyTo) > 0 && !in_array($productTypeId, $applyTo)) {
                     $this->_attributes->removeItemByKey($attribute->getId());
                     break;
                 }
             }
         }
     }
     return $this->_attributes;
 }
Пример #5
0
 /**
  * Test getAllAttributeMetadata
  */
 public function testGetAllAttributeMetadata()
 {
     $data = ['attribute_id' => 1, 'attribute_code' => 'description', 'frontend_label' => 'English', 'store_labels' => array(1 => 'France'), 'frontend_input' => 'textarea'];
     $attributeMock = $this->getMock('Magento\\Framework\\Object', array('usesSource', 'getSource', 'isScopeGlobal', 'getId'), array('data' => $data));
     $attributeMock->expects($this->once())->method('getId')->will($this->returnValue($data['attribute_id']));
     $attributeMock->expects($this->any())->method('isScopeGlobal')->will($this->returnValue(true));
     $attributeMock->expects($this->any())->method('usesSource')->will($this->returnValue(true));
     $attributeMock->expects($this->any())->method('getSource')->will($this->returnValue(new \Magento\Framework\Object()));
     $this->eavConfigMock->expects($this->any())->method('getAttribute')->will($this->returnValue($attributeMock));
     $this->attributeCollectionFactory->expects($this->once())->method('create')->will($this->returnValue($this->attributeCollection));
     $searchCriteria = $this->getMockBuilder('\\Magento\\Framework\\Service\\V1\\Data\\SearchCriteria')->disableOriginalConstructor()->setMethods(['getFilterGroups'])->getMock();
     $searchCriteria->expects($this->once())->method('getFilterGroups')->will($this->returnValue(array()));
     $this->attributeCollection->expects($this->once())->method('getSize')->will($this->returnValue(1));
     $this->attributeCollection->expects($this->once())->method('getIterator')->will($this->returnValue(new \ArrayIterator(array($attributeMock))));
     /** @var \Magento\Catalog\Service\V1\Data\Product\Attribute\SearchResults $searchResult */
     $searchResult = $this->service->getAllAttributeMetadata('entity_type', $searchCriteria);
     $dto = $searchResult->getItems()[0];
     $this->assertInstanceOf('Magento\\Framework\\Service\\Data\\AbstractExtensibleObject', $dto);
     $this->assertEquals($attributeMock->getFrontendInput(), $dto->getFrontendInput());
     $this->assertEquals(0, $dto->getFrontendLabel()[0]->getStoreId());
     $this->assertEquals(1, $dto->getFrontendLabel()[1]->getStoreId());
     $this->assertEquals('English', $dto->getFrontendLabel()[0]->getLabel());
     $this->assertEquals('France', $dto->getFrontendLabel()[1]->getLabel());
 }
Пример #6
0
 /**
  * Clean up attribute collection.
  *
  * @param \Magento\Eav\Model\Resource\Entity\Attribute\Collection $collection
  * @return \Magento\Eav\Model\Resource\Entity\Attribute\Collection
  */
 public function filterAttributeCollection(\Magento\Eav\Model\Resource\Entity\Attribute\Collection $collection)
 {
     $collection->load();
     foreach ($collection as $attribute) {
         if (in_array($attribute->getAttributeCode(), $this->_disabledAttrs)) {
             $collection->removeItemByKey($attribute->getId());
         }
     }
     return $collection;
 }
Пример #7
0
 /**
  * Helper function that adds a FilterGroup to the collection.
  *
  * @param \Magento\Framework\Service\V1\Data\Search\FilterGroup  $filterGroup
  * @param \Magento\Eav\Model\Resource\Entity\Attribute\Collection $collection
  * @return void
  * @throws \Magento\Framework\Exception\InputException
  */
 private function addFilterGroupToCollection(FilterGroup $filterGroup, Collection $collection)
 {
     foreach ($filterGroup->getFilters() as $filter) {
         $condition = $filter->getConditionType() ? $filter->getConditionType() : 'eq';
         $collection->addFieldToFilter($this->translateField($filter->getField()), [$condition => $filter->getValue()]);
     }
 }
Пример #8
0
 /**
  * @param \Magento\Framework\Data\Collection\EntityFactory $entityFactory
  * @param \Psr\Log\LoggerInterface $logger
  * @param \Magento\Framework\Data\Collection\Db\FetchStrategyInterface $fetchStrategy
  * @param \Magento\Framework\Event\ManagerInterface $eventManager
  * @param \Magento\Eav\Model\Config $eavConfig
  * @param \Magento\Store\Model\StoreManagerInterface $storeManager
  * @param mixed $connection
  * @param \Magento\Framework\Model\Resource\Db\AbstractDb $resource
  */
 public function __construct(\Magento\Framework\Data\Collection\EntityFactory $entityFactory, \Psr\Log\LoggerInterface $logger, \Magento\Framework\Data\Collection\Db\FetchStrategyInterface $fetchStrategy, \Magento\Framework\Event\ManagerInterface $eventManager, \Magento\Eav\Model\Config $eavConfig, \Magento\Store\Model\StoreManagerInterface $storeManager, $connection = null, \Magento\Framework\Model\Resource\Db\AbstractDb $resource = null)
 {
     $this->_storeManager = $storeManager;
     parent::__construct($entityFactory, $logger, $fetchStrategy, $eventManager, $eavConfig, $connection, $resource);
 }
 /**
  * Helper function that adds a FilterGroup to the collection.
  *
  * @param \Magento\Framework\Api\Search\FilterGroup $filterGroup
  * @param \Magento\Eav\Model\Resource\Entity\Attribute\Collection $collection
  * @return void
  * @throws \Magento\Framework\Exception\InputException
  */
 private function addFilterGroupToCollection(\Magento\Framework\Api\Search\FilterGroup $filterGroup, Collection $collection)
 {
     /** @var \Magento\Framework\Api\Search\FilterGroup $filter */
     foreach ($filterGroup->getFilters() as $filter) {
         $condition = $filter->getConditionType() ? $filter->getConditionType() : 'eq';
         $collection->addFieldToFilter($filter->getField(), [$condition => $filter->getValue()]);
     }
 }
Пример #10
0
 /**
  * Clean up attribute collection.
  *
  * @param \Magento\Eav\Model\Resource\Entity\Attribute\Collection $collection
  * @return \Magento\Eav\Model\Resource\Entity\Attribute\Collection
  */
 public function filterAttributeCollection(\Magento\Eav\Model\Resource\Entity\Attribute\Collection $collection)
 {
     $collection->load();
     foreach ($collection as $attribute) {
         if (in_array($attribute->getAttributeCode(), $this->_disabledAttrs)) {
             if (isset($this->_parameters[\Magento\ImportExport\Model\Export::FILTER_ELEMENT_SKIP])) {
                 if ($attribute->getAttributeCode() == ImportAdvancedPricing::COL_TIER_PRICE && in_array($attribute->getId(), $this->_parameters[\Magento\ImportExport\Model\Export::FILTER_ELEMENT_SKIP])) {
                     $this->_passTierPrice = 1;
                 }
                 if ($attribute->getAttributeCode() == ImportAdvancedPricing::COL_GROUP_PRICE && in_array($attribute->getId(), $this->_parameters[\Magento\ImportExport\Model\Export::FILTER_ELEMENT_SKIP])) {
                     $this->_passGroupPrice = 1;
                 }
             }
             $collection->removeItemByKey($attribute->getId());
         }
     }
     return $collection;
 }
Пример #11
0
 /**
  * Return array of fields to load attribute values
  *
  * @return string[]
  */
 protected function _getLoadDataFields()
 {
     $fields = array_merge(parent::_getLoadDataFields(), ['additional_table.is_global', 'additional_table.is_html_allowed_on_front', 'additional_table.is_wysiwyg_enabled']);
     return $fields;
 }