/** * Add additional data to attribute. * * @param Attribute $attribute * @return bool */ public function overrideAttribute(Attribute $attribute) { if (!empty($this->_attributeOverrides[$attribute->getAttributeCode()])) { $data = $this->_attributeOverrides[$attribute->getAttributeCode()]; if (isset($data['options_method']) && method_exists($this, $data['options_method'])) { $data['filter_options'] = $this->{$data['options_method']}(); } $attribute->addData($data); return true; } return false; }
/** * @param \Magento\Catalog\Model\ResourceModel\Eav\Attribute $subject * @param \Magento\Catalog\Model\ResourceModel\Eav\Attribute $attribute * @return \Magento\Catalog\Model\ResourceModel\Eav\Attribute * * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ public function afterDelete(\Magento\Catalog\Model\ResourceModel\Eav\Attribute $subject, \Magento\Catalog\Model\ResourceModel\Eav\Attribute $attribute) { if ($attribute->getIsUsedForPromoRules()) { $this->checkCatalogRulesAvailability($attribute->getAttributeCode()); } return $attribute; }
/** * Get Attribute Filter Class Name * * @param \Magento\Catalog\Model\ResourceModel\Eav\Attribute $attribute * @return string */ protected function getAttributeFilterClass(\Magento\Catalog\Model\ResourceModel\Eav\Attribute $attribute) { $filterClassName = $this->filterTypes[self::ATTRIBUTE_FILTER]; if ($attribute->getAttributeCode() == 'price') { $filterClassName = $this->filterTypes[self::PRICE_FILTER]; } elseif ($attribute->getBackendType() == 'decimal') { $filterClassName = $this->filterTypes[self::DECIMAL_FILTER]; } return $filterClassName; }
/** * Retrieve Product Attribute Value * * @param Product $product * @param \Magento\Catalog\Model\ResourceModel\Eav\Attribute $attribute * @return \Magento\Framework\Phrase|string */ public function getProductAttributeValue($product, $attribute) { if (!$product->hasData($attribute->getAttributeCode())) { return __('N/A'); } if ($attribute->getSourceModel() || in_array($attribute->getFrontendInput(), ['select', 'boolean', 'multiselect'])) { //$value = $attribute->getSource()->getOptionText($product->getData($attribute->getAttributeCode())); $value = $attribute->getFrontend()->getValue($product); } else { $value = $product->getData($attribute->getAttributeCode()); } return (string) $value == '' ? __('No') : $value; }
/** * @param \Magento\Catalog\Model\ResourceModel\Eav\Attribute $attribute * @param \Magento\Catalog\Model\ResourceModel\Product\Collection $collection * @return $this */ protected function addGlobalAttribute(\Magento\Catalog\Model\ResourceModel\Eav\Attribute $attribute, \Magento\Catalog\Model\ResourceModel\Product\Collection $collection) { $storeId = $this->storeManager->getStore()->getId(); switch ($attribute->getBackendType()) { case 'decimal': case 'datetime': case 'int': $alias = 'at_' . $attribute->getAttributeCode(); $collection->addAttributeToSelect($attribute->getAttributeCode(), 'inner'); break; default: $alias = 'at_' . md5($this->getId()) . $attribute->getAttributeCode(); $collection->getSelect()->join([$alias => $collection->getTable('catalog_product_index_eav')], "({$alias}.entity_id = e.entity_id) AND ({$alias}.store_id = {$storeId})" . " AND ({$alias}.attribute_id = {$attribute->getId()})", []); } $this->joinedAttributes[$attribute->getAttributeCode()] = $alias . '.value'; return $this; }
/** * {@inheritdoc} */ public function getAttributeCode() { $pluginInfo = $this->pluginList->getNext($this->subjectType, 'getAttributeCode'); if (!$pluginInfo) { return parent::getAttributeCode(); } else { return $this->___callPlugins('getAttributeCode', func_get_args(), $pluginInfo); } }