Magento put product or service to be able to
shopping cart software package making use of ajax
In that web sitewe have been
moving to talk about on
the best way to create product to ajax cart magento be able to shopping cart applying ajax.Right after little
seek out i just discovered some valuable
info on how to include product
for you to the carry without having reloading the particular
internet page. The unique approach you can test will be below
.
Strategy 1: Set up out with box script and give us a call at this script file employing ajax call.
- It has decent for those who have
uncomplicated device only. create canevas set of scripts in best magento affiliate extension root document similar to app binder develop one php report, clone program code mentioned bellow
and give us a call this file plus go away parameter using find strategy.
view plaincopy to help clipboardprint?
include_once '.. /app/Mage. php';
Mage:: app();
check 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: Around following method we might push item using ajax call have method (that is all the exact ranges are part of web link. ).
I have put into practice the following for simple product or service,configurable product and
bunch merchandise. You have that will just make sure of which credit and value en consists in proper arrangement. I did composed the hear website, this will assistance magento events calendar you to understand on the amount should be the website address format to get while placing the product towards browsing cart using ajax.
Case in point 1: Add Simple solution using following format.
www.domain.com/index.php/checkout/cart/add?product=[id]&qty=[qty]
Case 2: Add configurable device using following format.
www.domain.com/index.php/checkout/cart/add?product=$id&qty=$qty&options[$id]=$value
Example 3 or more: Add bundle product working with following format.
www.domain.com/index.php/checkout/cart/add?product=13&qty=1&options[12]=57
Note: In instance associated with configurable or
lot of cash product you will have to take a look at the response html document pertaining to error message, if perhaps any sort of.
0 nhận xét:
Đăng nhận xét