本文整理汇总了PHP中ShoppingCart::add_item方法的典型用法代码示例。如果您正苦于以下问题:PHP ShoppingCart::add_item方法的具体用法?PHP ShoppingCart::add_item怎么用?PHP ShoppingCart::add_item使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ShoppingCart
的用法示例。
在下文中一共展示了ShoppingCart::add_item方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testAddArbitraryQuantityToItem
function testAddArbitraryQuantityToItem()
{
/* Add an item to the cart */
$this->get('product-2b/add');
/* See what's in the cart */
$items = ShoppingCart::get_items();
/* There is 1 item in the cart, with a quantity of 1 */
$this->assertEquals(count($items), 1, 'There is 1 item in the cart');
$this->assertEquals($items[0]->getQuantity(), 1, 'There is a quantity of 1 for the item in the cart');
/* Let's add 7 more of the same product to the cart */
ShoppingCart::add_item($items[0]->getIDAttribute(), 7);
/* See what's in the cart once more */
$items = ShoppingCart::get_items();
/* There is still 1 item in the cart, with a quantity of 8 */
$this->assertEquals(count($items), 1, 'There is 1 item in the cart');
$this->assertEquals($items[0]->getQuantity(), 8, 'There is a quantity of 1 for the item in the cart');
/* Clear the shopping cart */
ShoppingCart::clear();
}
示例2: additem
function additem()
{
$itemId = $this->urlParams['ID'];
if ($itemId) {
ShoppingCart::add_item($itemId);
if (!$this->isAjax()) {
Director::redirectBack();
}
}
}
示例3: additem
/**
* Either increments the count or creates a new item.
*/
function additem($request)
{
if ($itemId = $request->param('ID') && ($product = $this->buyableFromURL())) {
if ($item = ShoppingCart::get_item($this->urlFilter())) {
ShoppingCart::add_item($item);
return self::return_data("success", "Extra item added");
//TODO: i18n
} else {
if ($orderitem = $this->create_order_item($product, 1, self::get_clean_param_array($this->getRequest()->getVars()))) {
ShoppingCart::add_new_item($orderitem);
return self::return_data("success", "Item added");
//TODO: i18n
}
}
}
return self::return_data("failure", "Item could not be added");
//TODO: i18n
}