Magento increase merchandise for you to
cart applying ajax
In this particular magento ajax add to cart weblogwe have been
heading to talk about on
exactly how to include product in order to shopping cart utilizing ajax.Right after little
lookup we discovered some valuable
information about how to include product
to be able to the trolley without having reloading typically the
web page. The various approach you can attempt tend to be the following
.
Technique 1: Produce out associated with box script and give us a call at which script file making use of ajax call.
- It is great for those who have
easy item only. create intrigue software in root document similar to app binder and one php document, duplicate program code mentioned bellow
and give us a call this file as well as move parameter using obtain technique.
view plaincopy for you to clipboardprint?
include_once '.. /app/Mage. php';
Mage:: app();
try out
$result = array();
if(!isset($_GET['sku']))
$sku = '';
else
$sku = $_GET['sku'];
if(!isset($_GET['product_id']))
$product_id = '';
else
$product_id = $_GET['product_id'];
if(!isset($_GET['qty']))
$qty = '1';
else
$qty = $_GET['qty'];
if ($sku != "")
$product_id = Mage::getModel('catalog/product')-> getIdBySku("$sku");
if ($product_id == '')
$session-> addError(" <strong> Product Not Added </strong> The SKU you entered ($sku) was not found.");
}
}
$request = Mage::app()-> getRequest();
$product = Mage::getModel('catalog/product')-> load($product_id);
$session = Mage::getSingleton('core/session', array('name'=> 'frontend'));
$cart = Mage::helper('checkout/cart')-> getCart();
$cart-> addProduct($product, $qty);
$session-> setLastAddedProductId($product-> getId());
$session-> setCartWasUpdated(true);
$cart-> save();
$items_in_cart = Mage::helper('checkout/cart')-> getSummaryCount();
$result['result']="success";
$result['message']="Added!";
$result['items_in_cart'] = "$items_in_cart";
echo json_encode($result);
}
catch (Exception $e) {
$result['result'] = 'error';
$result['message'] = $e-> getMessage();
echo json_encode($result);
Method 2: Within 2nd method we may push product or service using ajax call acquire method (that is all the actual variables are part of web address. ).
I have examined this specific for simple merchandise,configurable product and
pack solution. You have to help just make sure that will feature and value pendant consists in proper file format. We have composed the small sample link,best magento affiliate extension this will assist you to understand about what should be the web link format with regard to while including the product towards the buying cart using ajax.
Instance 1: Add Simple device using following format.
www.domain.com/index.php/checkout/cart/add?product=[id]&qty=[qty]
Illustration 2: Add configurable item using following format.
www.domain.com/index.php/checkout/cart/add?product=$id&qty=$qty&options[$id]=$value
Example three: Add bundle product applying following format.
www.domain.com/index.php/checkout/cart/add?product=13&qty=1&options[12]=57
Note: In situation associated with magento coupon configurable or
package product you might have to examine the response code regarding error message, in case any kind of.
0 nhận xét:
Đăng nhận xét