I found a problem using a custom "gift" extension for magento. It let the user choose a gift product in the checkout cart page. So the user will find under the cart a product grid and can select max 1 product to get as gift and then add it to cart.
My problem is that after the user add product he's still able to edit the qty. So he can order 10 items of product as gift.
I need to force user to don't edit the product quantity for the "gift" products in cart.
The products listed as "Gifts" can be also purchased as regular products so that rule has to be applied on the "Gift" situation.
Actually the function "add cart" of the extension is this one:
public function addAction()
{
if ($this->getRequest()->isGet()) {
$gift_id = $this->getRequest()->getParam('gift', 0);
if($gift_id){
if(!Mage::helper('gifts')->isGiftUsed() && in_array($gift_id, Mage::helper('gifts')->getGiftsIds())){
$quote = Mage::getSingleton('checkout/session')->getQuote();
$cart = Mage::getModel('checkout/cart');
$product = new Mage_Catalog_Model_Product();
$product->load($gift_id);
$cart->addProduct($product, 1);
$cart->save();
foreach ($quote->getAllItems() as $item) {
if ($item->getProductId() == $gift_id) {
$item->setCustomPrice(0);
$item->setOriginalCustomPrice(0);
//$item->setOption('inventory_max_sale_qty',1);
}
}
$cart->init();
$cart->save();
Mage::getSingleton('checkout/session')->setCartWasUpdated(true);
}
}
}
$this->_redirect('checkout/cart');
}
thank you