當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。