Last active
January 29, 2019 20:54
-
-
Save deniscsz/2918a24a1e699334f1a08e8629a5f382 to your computer and use it in GitHub Desktop.
Get Attributes displayed into Product View - Magento 1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$excludeAttr = array(); | |
$attributes = $product->getAttributes(); | |
foreach ($attributes as $attribute) { | |
if ($attribute->getIsVisibleOnFront() && !in_array($attribute->getAttributeCode(), $excludeAttr)) { | |
$value = $attribute->getFrontend()->getValue($product); | |
if (!$product->hasData($attribute->getAttributeCode())) { | |
$value = ""; //Coloque aqui o que você quer para quando o atributo não existir para esse tipo de produto. No nosso caso na hiper a gente não exibe (filtramos depois). | |
} elseif ((string)$value == '') { | |
$value = ""; //Coloque aqui o que você quer para quando o atributo não estiver preenchido. No nosso caso na hiper a gente não exibe (filtramos depois). | |
} elseif ($attribute->getFrontendInput() == 'price' && is_string($value)) { | |
$value = Mage::app()->getStore()->convertPrice($value, true); | |
} | |
if (is_string($value) && strlen($value)) { | |
$data[$attribute->getAttributeCode()] = array( | |
'label' => $attribute->getStoreLabel(), | |
'value' => $value, | |
'code' => $attribute->getAttributeCode() | |
); | |
} | |
} | |
} | |
print_r($data); //Todos os atributos. | |
//Para alguns deles nós temos que fazer alguns ajustes, como o peso, que não possui a unidade (concaternar unidade na hora de imprimir) e por aí vai. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment