0

I installed Magento 1.9.2.1 and I need to delete the box quantity only on some products.

I was thinking, for example, when max quantity is set to 1, instead of for other products leave the box.

Thank you, do you have any suggestions?

File addtocart.phtml

<?php $_product = $this->getProduct(); ?>
<?php $buttonTitle = $this->__('Add to Cart'); ?>
<?php if($_product->isSaleable()): ?>
    <div class="add-to-cart">
        <?php if(!$_product->isGrouped()): ?>
        <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" />
        <?php endif; ?>
        <button type="button" title="<?php echo $buttonTitle ?>" id="product-addtocart-button" class="button btn-cart" onclick="productAddToCartForm.submit(this)"><span><span><?php echo $buttonTitle ?></span></span></button>
        <?php echo $this->getChildHtml('', true, true) ?>
    </div>
    <div class="clear" style="clear:both;"></div>
    <?php echo Mage::helper('core/nbproductdesign')->showButtonDesign(); ?>
<?php endif; ?>

1 Answer 1

2

You need to work with this file below:

app/design/frontend/[yourPackage]/[yourTheme]/template/catalog/product/view/addtocart.phtml

Insert the code $_product->getStockItem()->getMaxSaleQty() == 1 condition around qty box:

<?php $_product = $this->getProduct(); ?>
<?php $buttonTitle = $this->__('Add to Cart'); ?>
<?php if($_product->isSaleable()): ?>
  <div class="add-to-cart">
    <?php if(!$_product->isGrouped()): ?>
    <!--START THE CONDITION -->
    <?php if($_product->getStockItem()->getMaxSaleQty() > 1): ?>
    <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" />
    <!--END THE CONDITION-->
    <?php endif; ?>
    <?php endif; ?>
    <button type="button" title="<?php echo $buttonTitle ?>" id="product-addtocart-button" class="button btn-cart" onclick="productAddToCartForm.submit(this)"><span><span><?php echo $buttonTitle ?></span></span></button>
    <?php echo $this->getChildHtml('', true, true) ?>
  </div>
<?php endif; ?>

Yes! The condition could be added to the first if:

if(!$_product->isGrouped() && $_product->getStockItem()->getMaxSaleQty() > 1)
3
  • Perfect works, you can also choose the value> or ==. Thank you May 5, 2017 at 6:11
  • If it has helped you then you should accept the answer. May 5, 2017 at 6:37
  • I agree with Adarsh Khatri :) May 5, 2017 at 15:32

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.