0

I have the below HTML that I need to wrap in a PHP IF Statement. I need the statement to check if Enable Qty Increments = Yes (set in Inventory settings of Magento) however, I'm not sure what the attribute to check is.

<?php if($_product->getAttributeText('INSERT ATTRIBUTE HERE')=='Yes'): ?>
    <p>Only available in box quantities</p>
<?php else: ?>
    <p>Buy as much as you want</p>
<?php endif; ?> 
2

Try it like this:

<?php if($_product->getStockItem()->getQtyIncrements()): ?>
    <p><?php echo $this->__('Only available in box quantities');?></p>
<?php else: ?>
    <p><?php echo $this->__('Buy as much as you want');?></p>
<?php endif; ?> 
| improve this answer | |
  • Yep that's the right answer. See my alternative answer also ;) – Raphael at Digital Pianism Dec 12 '16 at 12:31
  • Thanks for the answer, but I get this: "Parse error: syntax error, unexpected ':' in /location/filename.phtml" relating to the first line. Thoughts? – Craig Dec 12 '16 at 12:48
  • sorry, I forgot a closing bracket. Try again. – Marius Dec 12 '16 at 12:48
  • Nice one. I'm now left with this message, "Fatal error: Call to a member function getStockItem() on a non-object". Do I have to add another line similar to this (<?php $_product = $this->getProduct(); ?>) in order to make this work? – Craig Dec 12 '16 at 13:03
  • make the if statement this $this->getProduct()->->getStockItem()->getQtyIncrements(). But it really depends on where you are using this. – Marius Dec 12 '16 at 13:04
0

Alternative to Marius answer to only check if the field is set to Yes and not check the actual values:

<?php if($_product->getStockItem()->getEnableQtyIncrements(): ?>
    <p><?php echo $this->__('Only available in box quantities');?></p>
<?php else: ?>
    <p><?php echo $this->__('Buy as much as you want');?></p>
<?php endif; ?> 
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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