本文整理匯總了PHP中ShoppingCart::remove_item方法的典型用法代碼示例。如果您正苦於以下問題:PHP ShoppingCart::remove_item方法的具體用法?PHP ShoppingCart::remove_item怎麽用?PHP ShoppingCart::remove_item使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類ShoppingCart
的用法示例。
在下文中一共展示了ShoppingCart::remove_item方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: testRemoveItemFromCart
function testRemoveItemFromCart()
{
/* Add 2 different products to the cart */
$this->get('product-2a/add');
$this->get('product-2b/add');
$this->get('product-2b/add');
$item1ID = $this->idFromFixture('Product', 'p2a');
$item2ID = $this->idFromFixture('Product', 'p2b');
/* See what's in the cart in session */
$items = ShoppingCart::get_items();
/* There are 2 items in the cart. 1 of the first item, 2 of the second item */
$this->assertEquals(count($items), 2, 'There are 2 items in the cart');
$this->assertEquals($items[0]->getIDAttribute(), $item1ID, 'The first item is the same ID as the first product.');
$this->assertEquals($items[0]->getQuantity(), 1, 'There is 1 of the first item.');
$this->assertEquals($items[1]->getIDAttribute(), $item2ID, 'The second item is the same ID as the second product.');
$this->assertEquals($items[1]->getQuantity(), 2, 'There are 2 of the second item.');
/* Let's remove 1 piece of the second item from the cart */
ShoppingCart::remove_item($item2ID, 1);
/* We now have 1 piece left of the second item in the cart */
$items = ShoppingCart::get_items();
$this->assertEquals($items[1]->getQuantity(), 1, 'We now have 1 piece of the second item in the cart, we removed 1.');
/* Now, let's remove the final piece of the item, removing that item from the cart completely */
ShoppingCart::remove_item($item2ID, 1);
/* Take a peek in the cart once again to see what changed */
$items = ShoppingCart::get_items();
/* We have none of the second item in the cart, because we removed both 2 pieces of it that existed */
$this->assertTrue(empty($items[1]), 'There is no index of 1 because the item doesn\'t exist in the cart any longer.');
/* Clear the shopping cart */
ShoppingCart::clear();
}
示例2: removeitem
function removeitem()
{
$itemId = $this->urlParams['ID'];
if ($itemId) {
ShoppingCart::remove_item($itemId);
if (!$this->isAjax()) {
Director::redirectBack();
}
}
}
示例3: removeitem
function removeitem($request)
{
if ($item = ShoppingCart::get_item($this->urlFilter())) {
ShoppingCart::remove_item($item);
return self::return_data("success", "Item removed");
//TODO: i18n
}
return self::return_data("failure", "Item could not be found in cart");
//TODO: i18n
}