I am new in magento. I have made a custom module of price calculator in which a user enter the height and width of a product and it gets its price.
I want to implement add to cart functionality so that height,width and price goes to cart. But i don't know the code and syntax to implement it.
Cart functionality is already installed on my project.
This is controller
class Test_Mymodule_IndexController extends Mage_Core_Controller_Front_Action
{
public function indexAction()
{
$this->loadLayout();
$this->renderLayout();
}
public function calculateAction()
{
$request = $this->getRequest();
$printdata = $request->getPost();
if($this->getRequest()->isPost())
{
$obj = Mage::getModel("test_mymodule/results");
$show_results = $obj->showshuttersprice($printdata['width'],$printdata['height']);
}
Mage::register('data', $show_results);// In the Controller
Mage::register('width', $printdata['width']);// In the Controller
Mage::register('height', $printdata['height']);// In the Controller
$this->loadLayout();
$this->renderLayout();
}
}
This is my view in which i want to implement add to cart
<?php
$data = Mage::registry('data');// In the View;
$width = Mage::registry('width');// In the View;
$height = Mage::registry('height');// In the View;
if($data == "0" || $data == "NULL" || $data == "")
{
echo "Sorry, Product is Unavailable";
}
else
{
?>
<h6 align="center">Price Results for <?php echo $width; ?> mm by <?php echo $height; ?> mm Domestic Rollershutter</h6>
<table border="1" align="center" width="100%" cellspacing="4" cellpadding="4">
<tr>
<td>Price</td> <td><?php echo "$"." ".$data; ?></td>
</tr>
</table>
<?php
}
?>
<br />
<a href ="">Add to cart</a>
Any body help me…
Best Answer
There are two options.
Adding via Query string
http://www.magentocommerce.com/wiki/4_-_themes_and_template_customization/catalog/adding_a_product_to_the_cart_via_querystring
Adding via code
https://stackoverflow.com/questions/13698236/add-product-to-cart-with-custom-options