예제 #1
0
 /**
  * Return collection of same attributes for selected products without unique
  *
  * @return \Magento\Eav\Model\ResourceModel\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;
 }
예제 #2
0
 /**
  * Helper function that adds a FilterGroup to the collection.
  *
  * @param \Magento\Framework\Api\Search\FilterGroup $filterGroup
  * @param \Magento\Eav\Model\ResourceModel\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()]);
     }
 }
 /**
  * Helper function that adds a FilterGroup to the collection.
  *
  * @param \Magento\Framework\Api\Search\FilterGroup $filterGroup
  * @param \Magento\Eav\Model\ResourceModel\Entity\Attribute\Collection $collection
  * @return void
  * @throws \Magento\Framework\Exception\InputException
  */
 private function addFilterGroupToCollection(\Magento\Framework\Api\Search\FilterGroup $filterGroup, Collection $collection)
 {
     foreach ($filterGroup->getFilters() as $filter) {
         $condition = $filter->getConditionType() ? $filter->getConditionType() : 'eq';
         $field = $filter->getField();
         // Prevent ambiguity during filtration
         if ($field == \Magento\Eav\Api\Data\AttributeInterface::ATTRIBUTE_ID) {
             $field = 'main_table.' . $field;
         }
         $collection->addFieldToFilter($field, [$condition => $filter->getValue()]);
     }
 }