0

Im trying to get a series of attributes to show if an attribute value is set to yes.

Here is my code but it is not working:

 <?php if($_product->getAttributeText("vm_activate")== 1) ?>
        <div class="product-sku"><span><?php echo $this->__('VMware SKU: ') ?></span><?php echo $_product->getVmwareSku() ?></div>
        <div class="product-sku"><span><?php echo $this->__('VMware Type: ') ?></span><?php echo $_product->getVmware() ?></div>
        <div class="product-sku"><span><?php echo $this->__('VMware Price: ') ?></span><?php echo $_product->getVmwarePrice() ?></div>
    <?php endif; ?>
13
  • what is the name you are created attribute? Commented Jul 17, 2017 at 19:45
  • It is set to vm_activate Commented Jul 17, 2017 at 19:46
  • What type of attribute is it? (Dropdown, text ...)
    – sv3n
    Commented Jul 21, 2017 at 9:38
  • Its a Yes/ No dropdown Commented Jul 21, 2017 at 17:36
  • Have you tried suggestion from below?
    – sv3n
    Commented Jul 21, 2017 at 18:10

2 Answers 2

1

After some tinkering this worked:

<?php if ($_product->getAttributeText('vm_activate') == "Yes"): ?>
    <div class="product-sku"><span><?php echo $this->__('VMware SKU: ') ?></span><?php echo $_product->getVmwareSku() ?></div>
    <div class="product-sku"><span><?php echo $this->__('VMware Type: ') ?></span><?php echo $_product->getVmware() ?></div>
    <div class="product-sku"><span><?php echo $this->__('VMware Price: ') ?></span><?php echo $_product->getVmwarePrice() ?></div>
<?php endif ?>
0

You can use :

<?php $attribute = $_product->getAttributeText("vm_activate"); ?> //return true of false, 0 or 1
<?php if($attribute) : ?> // if is true or 1
    <div class="product-sku"><span><?php echo $this->__('VMware SKU: ') ?></span><?php echo $_product->getVmwareSku() ?></div>
    <div class="product-sku"><span><?php echo $this->__('VMware Type: ') ?></span><?php echo $_product->getVmware() ?></div>
    <div class="product-sku"><span><?php echo $this->__('VMware Price: ') ?></span><?php echo $_product->getVmwarePrice() ?></div>
<?php endif; ?>
5
  • This works. However its pulling the db id and not the attribute value. Do I need to call something. additional to the page? Commented Jul 18, 2017 at 12:36
  • Normally it should work with getAttributeTest(), try this : ` $value = $product->getResource()->getAttribute($attribute_code)->getFrontend()->getValue($product);`
    – PЯINCƎ
    Commented Jul 18, 2017 at 12:39
  • If it's working for you, please accept the answer
    – PЯINCƎ
    Commented Jul 18, 2017 at 13:28
  • It does not. The code on the second comment kills the whole thing. Also, I'm trying to hide the whole section id its set to no. Commented Jul 19, 2017 at 14:38
  • I don't know but it works for me getAttributeText("vm_activate"), try this one $prod = Mage::getModel('catalog/product')->load($productId); $attribute = $prod->getResource()->getAttribute('vm_activate')->getFrontend()->getValue($prod); echo $attribute; otherwise i have no idea.
    – PЯINCƎ
    Commented Jul 19, 2017 at 14:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.