/** * @param \Magento\Catalog\Model\ResourceModel\Eav\Attribute $attribute * @param \Magento\Catalog\Model\ResourceModel\Product\Collection $collection * @return $this */ protected function addNotGlobalAttribute(\Magento\Catalog\Model\ResourceModel\Eav\Attribute $attribute, \Magento\Catalog\Model\ResourceModel\Product\Collection $collection) { $storeId = $this->storeManager->getStore()->getId(); $values = $collection->getAllAttributeValues($attribute); $validEntities = []; if ($values) { foreach ($values as $entityId => $storeValues) { if (isset($storeValues[$storeId])) { if ($this->validateAttribute($storeValues[$storeId])) { $validEntities[] = $entityId; } } else { if ($this->validateAttribute($storeValues[\Magento\Store\Model\Store::DEFAULT_STORE_ID])) { $validEntities[] = $entityId; } } } } $this->setOperator('()'); $this->unsetData('value_parsed'); if ($validEntities) { $this->setData('value', implode(',', $validEntities)); } else { $this->unsetData('value'); } return $this; }
/** * Collect validated attributes * * @param \Magento\Catalog\Model\ResourceModel\Product\Collection $productCollection * @return $this */ public function collectValidatedAttributes($productCollection) { $attribute = $this->getAttribute(); if ('category_ids' != $attribute) { $productCollection->addAttributeToSelect($attribute, 'left'); if ($this->getAttributeObject()->isScopeGlobal()) { $attributes = $this->getRule()->getCollectedAttributes(); $attributes[$attribute] = true; $this->getRule()->setCollectedAttributes($attributes); } else { $this->_entityAttributeValues = $productCollection->getAllAttributeValues($attribute); } } return $this; }