M
M
Mike Diam2016-07-05 10:54:31
JavaScript
Mike Diam, 2016-07-05 10:54:31

How to add hidden item to cart in magento?

There is an information page.
The goal is to click on the button to add a hidden product to the cart.
It is not required to display the product on the page, you just need to send it by clicking to the basket.

How to do it?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Mike Diam, 2016-07-05
@mikediam

Рабочий вариант:
<?php
  $productId = '123'; 
  $qty = '3';
  $product = Mage::getModel('catalog/product')->load($productId);
  $cart = Mage::getModel('checkout/cart');
  $cart->init();
  $cart->addProduct($product, array('qty' => $qty));
  $cart->save();
  Mage::getSingleton('checkout/session')->setCartWasUpdated(true);
?>

You can access the page with this code with Ajax

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question