<h1>quick shopping</h1>
<div>
<form action="http://yoursite.com/redirect.php" method="post">
<label name="sku">Sku:</label>
<input type="text" title="Sku" maxlength="12" id="sku" name="sku"/>
<label name="qty">Qty:</label>
<input type="text" title="Qty" maxlength="12" id="qty" name="qty"/>
<button type="submit">Add to cart</button>
</form>
</div>
以前觉得外部add to cart没什么用,后来才发现可以再帮我们坐推广的网站上使用,其实网站外只需要几行html代码,把如上代码放在外部:
然后add to cart的时候需要做了一跳转:
<?php
include_once 'app/Mage.php';
Mage::app();
Mage::getSingleton('core/session', array('name' => 'frontend'));
$sku=$_POST['sku'];
$qty=$_POST['qty'];
$id = Mage::getModel('catalog/product')->getIdBySku($sku);
header('Location: '. Mage::getUrl('checkout/cart/add', array('product' => $id , 'qty' => $qty)));
?>
上面的代码能通过POST获取html的输入,从而执行筛选来获取product id,最后将id和qty作为参数给header来跳转到shopping cart,是不是很简单呢,不过这仅仅是simple product的做法,其他复杂的产品类型,大家可以参考这个来做。That's All!