Example #1
0
 /**
  * Clean up already loaded attribute collection.
  *
  * @param \Magento\Eav\Model\ResourceModel\Entity\Attribute\Collection $collection
  * @return \Magento\Eav\Model\ResourceModel\Entity\Attribute\Collection
  */
 public function filterAttributeCollection(\Magento\Eav\Model\ResourceModel\Entity\Attribute\Collection $collection)
 {
     $validTypes = array_keys($this->_productTypeModels);
     $validTypes = array_combine($validTypes, $validTypes);
     foreach (parent::filterAttributeCollection($collection) as $attribute) {
         if (in_array($attribute->getAttributeCode(), $this->_bannedAttributes)) {
             $collection->removeItemByKey($attribute->getId());
             continue;
         }
         $attrApplyTo = $attribute->getApplyTo();
         $attrApplyTo = array_combine($attrApplyTo, $attrApplyTo);
         $attrApplyTo = $attrApplyTo ? array_intersect_key($attrApplyTo, $validTypes) : $validTypes;
         if ($attrApplyTo) {
             foreach ($attrApplyTo as $productType) {
                 // override attributes by its product type model
                 if ($this->_productTypeModels[$productType]->overrideAttribute($attribute)) {
                     break;
                 }
             }
         } else {
             // remove attributes of not-supported product types
             $collection->removeItemByKey($attribute->getId());
         }
     }
     return $collection;
 }