当前位置: 首页>>代码示例>>PHP>>正文


PHP ShoppingCart::remove_item方法代码示例

本文整理汇总了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();
 }
开发者ID:nicolaas,项目名称:silverstripe-ecommerce,代码行数:30,代码来源:ShoppingCartTest.php

示例2: removeitem

 function removeitem()
 {
     $itemId = $this->urlParams['ID'];
     if ($itemId) {
         ShoppingCart::remove_item($itemId);
         if (!$this->isAjax()) {
             Director::redirectBack();
         }
     }
 }
开发者ID:nicolaas,项目名称:silverstripe-ecommerce,代码行数:10,代码来源:ShoppingCart.php

示例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
 }
开发者ID:riddler7,项目名称:silverstripe-ecommerce,代码行数:10,代码来源:ShoppingCart.php


注:本文中的ShoppingCart::remove_item方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。