0

i need in product page add button or links, where when user click on this button, in cart we can send current product but with price = 0

i have button:

<button type="button" title="<?php echo $this->__('Add to Cart') ?>" class="addtocart" onclick="setLocation('<?php echo Mage::getUrl('checkout/cart/add', array('product'=>$_item->getId(),'qty'=>1)) ?>')"/> - button working, but how i can add value from price? 

<button type="button" title="<?php echo $this->__('Add to Cart') ?>" class="addtocart" onclick="setLocation('<?php echo Mage::getUrl('checkout/cart/add', array('product'=>$_item->getId(),'qty'=>1, 'price'=>0)) ?>')"/> - not working

Let me know how i can do better? Thanks

1 Answer 1

1

You can make it this way.

Dont change add-to-cart button url, keep it as is.

set proudct price to your desired when it adds to cart on fly. using sales_quote_save_before event.

and set price in your observer.

 $quote = $observer->getEvent()->getData();

 foreach ($quote['data_object']->getAllItems() as $key => $item) {
     if( !$item->getCustomPrice() ){
            $item->setCustomPrice( $customPrice );
            $item->setOriginalCustomPrice( $customPrice );
            $item->save();
     }
 }

Well I have not tested it with 0. But I hope it works.

2
  • Thanks, but maybe have easy way without observer? if no then i will do observer)
    – John Genry
    Commented Jul 9, 2014 at 10:44
  • No I don't think so, the way you did, controller loads product $product_id you provided and takes price from it. Commented Jul 9, 2014 at 10: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.