Magento incorporate item in order to
shopping cart application utilizing ajax
In the following blog sitewe live
planning to debate on
precisely magento store manager how to increase product to help shopping cart making use of ajax.Soon after little
look for my spouse and i identified some valuable
guides on how to provide product
that will the basket with out reloading the actual
site. The distinct approach you can check out are generally the examples below
.
Process 1: Make out involving box script and give us a call at of which script file applying ajax call.
- Is considered fine when you have
straightforward merchandise only. create pieces of software magento menu extension piece of software in root document similar to app binder produce one php data file, backup codes mentioned bellow
and give us a call this file along with go parameter using have process.
view plaincopy in order to clipboardprint?
include_once '.. /app/Mage. php';
Mage:: app();
attempt
$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: Throughout subsequent method we could push solution using ajax call obtain method (that is all typically the guidelines are part of link. ).
I have screened this particular for simple device,configurable product and
lot of cash item. You have to be able to just make sure which extension event capability and value dans consists in proper style. I possess composed the example web link, this will support you to understand of what should be the website format pertaining to while putting the product on the store shopping cart using ajax.
Case 1: Add Simple product or service using following format.
www.domain.com/index.php/checkout/cart/add?product=[id]&qty=[qty]
Instance 2: Add configurable merchandise using following format.
www.domain.com/index.php/checkout/cart/add?product=$id&qty=$qty&options[$id]=$value
Example several: Add bundle product employing following format.
www.domain.com/index.php/checkout/cart/add?product=13&qty=1&options[12]=57
Note: In event involving configurable or
pack product maybe you have to verify the response css with regard to error message, in the event that just about any.
0 nhận xét:
Đăng nhận xét