1

I have added to add 3 to cart and add to cart buttons.In this buttons, I clicked add 3 to cart added 3 quantities and add to cart button also added 3 quantities.My requirement is only added 3 to cart button add only 3 quantities and remaining buttons added only one quantity.Can you please help me? for example is below. Add 3 to cart->add 3 quantities Add to cart->add one quantity Buy now ->add one quantity Can you please help me?

1 Answer 1

1

3 Qty:

<?php echo Mage::helper('checkout/cart')->getAddUrl($_product, array('qty' => 3)); ?>

EDIT:

<a href="<?php echo Mage::helper('checkout/cart')->getAddUrl($_product, array('qty' => 3)); ?>"><?php echo $this->__('Add 3')?></a>

Buy Now:

<button type="button" title="<?php echo $buttonTitle ?>" class="button btn-cart" onclick="productBuyNowForm.submit(this)"> <span><span>Buynow</span></span></button>
<input type="hidden" value="<?php echo Mage::getUrl('checkout/onepage')?>" name="return_url" />

<script type="text/javascript">
    var productBuyNowForm = new VarienForm('product_addtocart_form');
    productBuyNowForm.submit = function (button, url) {
    if (this.validator.validate()) {
        var form = this.form;
        var oldUrl = form.action;
        alert(form.action);
        if (url) {
            form.action = url;
        }

        /* add return Url */
        var inputreturn= document.createElement("input");
        inputreturn.type = "hidden";
        inputreturn.name = "return_url";
        inputreturn.value = "<?php echo Mage::getUrl('checkout/onepage')?>";
        document.getElementById('product_addtocart_form').appendChild(inputreturn);
        /* add return Url */
        // Append a line break 
        var e = null;
        try {
            this.form.submit();
        } catch (e) {
        }
        this.form.action = oldUrl;
        if (e) {
            throw e;
        }

        if (button && button != 'undefined') {
            button.disabled = true;
        }
    }
}.bind(productBuyNowForm);  
</script>
8
  • Hi @ prince , Where 3 quantity code add <?php echo Mage::helper('checkout/cart')->getAddUrl($_product, array('qty' => 3)); ?> Commented Jan 9, 2018 at 10:24
  • Can you please tell me file path and particular place where code added? Commented Jan 9, 2018 at 10:25
  • app/design/frontend/{your package}/{your theme}/template/catalog/product/view.phtml
    – PЯINCƎ
    Commented Jan 9, 2018 at 10:26
  • Hi, I have already buy now code added it is working.But my requirement is added 3 to cart button how to add and click add 3 to cart button only add 3 quantities.Can you please help me? Commented Jan 9, 2018 at 10:30
  • Look my adit now
    – PЯINCƎ
    Commented Jan 9, 2018 at 10:30

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.