Magento placed merchandise for you to
e-commerce software applying ajax
In this specific sitei'm
intending go over on
the way to bring product magento event calendar for you to shopping cart working with ajax.Immediately after little
seek my partner and i observed some valuable
info about how to increase product
to help the wheeled not having reloading typically the
web site. The several approach you can try out usually are the following
.
Procedure 1: Develop out connected with box script and give us a call at that will script file utilizing ajax call.
- It is very excellent should you have
very simple solution only. create pièce screenplay magento banner extension in root document simultaneous to app binder as well as one php data, content computer mentioned bellow
and give us a call this file in addition to cross parameter using acquire procedure.
view plaincopy that will clipboardprint?
include_once '.. /app/Mage. php';
Mage:: app();
consider
$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: With secondly method we can certainly push device using ajax call receive method (that is all often the boundaries are part of website address. ).
I have tried this kind of for simple item,configurable product and
package product or service. You have in order to just make sure in which trait and value selon is made up in proper formatting. There are composed the model web address, this will guide you to understand on the should be the link format regarding magento calendar plugin while introducing the product into the searching cart using ajax.
Illustration 1: Add Simple merchandise using following format.
www.domain.com/index.php/checkout/cart/add?product=[id]&qty=[qty]
Example of this 2: Add configurable solution using following format.
www.domain.com/index.php/checkout/cart/add?product=$id&qty=$qty&options[$id]=$value
Example three or more: Add bundle product making use of following format.
www.domain.com/index.php/checkout/cart/add?product=13&qty=1&options[12]=57
Note: In scenario connected with configurable or
package deal product possibly you have to look at the response php intended for error message, in the event almost any.
0 nhận xét:
Đăng nhận xét