RSS
 

Les attributs dans Magento

23 juin

Insertion de blocs statiques en fonction de la valeur de l’attribut dans la page attribute.phtml

<?php if ($_product->getData('MON-ATTRIBUT')): ?>
<?php $_valeur_attribut= $_product->getResource()->getAttribute('MON-ATTRIBUT')->getFrontend()->getValue($_product); ?>
<?php if (($_valeur_attribut=='valeur1') or ($_valeur_attribut=='valeur2')){
echo $this->getLayout()->createBlock('cms/block')->setBlockId('mon-bloc1')->toHtml()
; }
else {
echo $this->getLayout()->createBlock('cms/block')->setBlockId('mon-bloc-alternatif')->toHtml()
; } ?>
<?php endif; ?>

Action if et else sur les attributs

<?php if ($_product->getData('MON-ATTRIBUT')): ?>
<?php $_mon_attribut= $_product->getResource()->getAttribute('MON-ATTRIBUT')->getFrontend()->getValue($_product); ?>

<?php if ($_mon_attribut==”valeur”): ?><p>Si mon attribut est égal à valeur alors j'affiche le lien <a href=”/radio-tuner.html” title=”Radio Tuner”>HD Radio</a>

Afficher l’attribut dans le fichier template/catalog/product/list.phtml

<?php echo $this->htmlEscape($_product->getData('MON-ATTRIBUT')); ?>

Afficher l’attribut dans le fichier template/catalog/product/view.phtml

<?php echo $_product->getResource()->getAttribute('MON-ATTRIBUT')->getFrontend()->getValue($_product) ?>
<?php echo $_product->getAttributeText('MON-ATTRIBUT') ?>

Afficher la quantité

$_product->getStockItem()->getQty()
 
 

Tags : , ,

Réagissez