/** * 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\Resource\Eav\Attribute $subject * @param \Magento\Catalog\Model\Resource\Eav\Attribute $attribute * @return \Magento\Catalog\Model\Resource\Eav\Attribute * * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ public function afterDelete(\Magento\Catalog\Model\Resource\Eav\Attribute $subject, \Magento\Catalog\Model\Resource\Eav\Attribute $attribute) { if ($attribute->getIsUsedForPromoRules()) { $this->checkCatalogRulesAvailability($attribute->getAttributeCode()); } return $attribute; }
/** * Get Attribute Filter Class Name * * @param \Magento\Catalog\Model\Resource\Eav\Attribute $attribute * @return string */ protected function getAttributeFilterClass(\Magento\Catalog\Model\Resource\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; }
/** * Return Product Attribute Store Label * Set attribute name like frontend lable for custom attributes (which wasn't defined by Google) * * @param \Magento\Catalog\Model\Resource\Eav\Attribute $attribute * @param int $storeId Store View Id * @return string Attribute Store View Label or Attribute code */ public function getAttributeLabel($attribute, $storeId) { $attributeId = $attribute->getId(); $frontendLabel = $attribute->getFrontend()->getLabel(); if (is_array($frontendLabel)) { $frontendLabel = array_shift($frontendLabel); } if (!isset($this->_attributeLabels[$attributeId])) { $this->_attributeLabels[$attributeId] = $attribute->getStoreLabels(); } if (isset($this->_attributeLabels[$attributeId][$storeId])) { return $this->_attributeLabels[$attributeId][$storeId]; } elseif (!empty($frontendLabel)) { return $frontendLabel; } else { return $attribute->getAttributeCode(); } }
/** * Create filter * * @param \Magento\Catalog\Model\Resource\Eav\Attribute $attribute * @param \Magento\Catalog\Model\Layer $layer * @return mixed */ protected function createAttributeFilter(\Magento\Catalog\Model\Resource\Eav\Attribute $attribute, \Magento\Catalog\Model\Layer $layer) { $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]; } $filter = $this->objectManager->create($filterClassName, array('data' => array('attribute_model' => $attribute), 'layer' => $layer)); return $filter; }
/** * Retrieve Product Attribute Value * * @param Product $product * @param \Magento\Catalog\Model\Resource\Eav\Attribute $attribute * @return string */ public function getProductAttributeValue($product, $attribute) { if (!$product->hasData($attribute->getAttributeCode())) { return __('N/A'); } if ($attribute->getSourceModel() || in_array($attribute->getFrontendInput(), array('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\Resource\Eav\Attribute $attribute * @param \Magento\Catalog\Model\Resource\Product\Collection $collection * @return $this */ protected function addGlobalAttribute(\Magento\Catalog\Model\Resource\Eav\Attribute $attribute, \Magento\Catalog\Model\Resource\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; return $this; }