1

I want to hide the qty box on the product details page but only for items with a certain attribute set. I know i need to edit the addtocart.phtml file with an if statement. I found a similar issue solved with this if statement which works:

        <?php if($_product->getStockItem()->getMaxSaleQty() > 1): ?>
            <div class="qty-wrapper">
                <label for="qty"><?php echo $this->__('Qty:') ?></label>
                <input type="text" name="qty" id="qty" maxlength="12" value="<?php echo $this->getProductDefaultQty() * 1 ?>" title="<?php echo Mage::helper('core')->quoteEscape($this->__('Qty')) ?>" class="input-text qty" />
            </div>
        <?php endif; ?>

But, I don't want to base it off of MaxSaleQty. I want to base the condition on the qty available. Solution?

1 Answer 1

0

Well, I think you almost there just need right condition.

You should replace this code from your qty box code.

    <?php 
    $attributeSetModel = Mage::getModel("eav/entity_attribute_set");
    $attributeSetModel->load($_product->getAttributeSetId());
    $productAttributeSetName = $attributeSetModel->getAttributeSetName();
    if($productAttributeSetName != "Your attibute set Name for hide qty"): 
    ?>
    <div class="qty-wrapper">
        <label for="qty"><?php echo $this->__('Qty:') ?></label>
        <input type="text" name="qty" id="qty" maxlength="12" value="<?php echo $this->getProductDefaultQty() * 1 ?>" title="<?php echo Mage::helper('core')->quoteEscape($this->__('Qty')) ?>" class="input-text qty" />
    </div>
    <?php endif; ?>
6
  • This is all being done inside the addtocart.phtml file. Pardon my ignorance but does the syntax need to be different? I can't seem to get this solution to work. As is, the code text shows up in my page. When I enclose the above code in <?php code ?> then I loose the qty box AND the Add To Cart button for some reason on ALL products, not just the ones that match my attribute set.
    – Galen
    Commented Sep 23, 2017 at 2:57
  • Can you please post the code so I can correct that. Commented Sep 23, 2017 at 10:08
  • I have updated my original question with the complete current code section pulled directly out of my addtocart.phtml file.
    – Galen
    Commented Sep 24, 2017 at 14:01
  • Hii Galen, I updated my answer with your code. Please replace it with your code . You can tell me if anything goes wrong. Commented Sep 24, 2017 at 16:17
  • This works perfectly and is now an easy way to hide the qty box based on the Attribute Set of the product. Thank you to jaydip sinh Parmar.
    – Galen
    Commented Sep 25, 2017 at 16:57

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.