/** * Return Google Content Attribute Type By Product Attribute * * @param \Magento\Catalog\Model\Resource\Eav\Attribute $attribute * @return string Google Content Attribute Type */ public function getGcontentAttributeType($attribute) { $typesMapping = ['price' => self::ATTRIBUTE_TYPE_FLOAT, 'decimal' => self::ATTRIBUTE_TYPE_INT]; if (isset($typesMapping[$attribute->getFrontendInput()])) { return $typesMapping[$attribute->getFrontendInput()]; } elseif (isset($typesMapping[$attribute->getBackendType()])) { return $typesMapping[$attribute->getBackendType()]; } else { return self::ATTRIBUTE_TYPE_TEXT; } }
/** * 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; }