當前位置: 首頁>>代碼示例>>PHP>>正文


PHP ShoppingCart::add_item方法代碼示例

本文整理匯總了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();
 }
開發者ID:nicolaas,項目名稱:silverstripe-ecommerce,代碼行數:19,代碼來源:ShoppingCartTest.php

示例2: additem

 function additem()
 {
     $itemId = $this->urlParams['ID'];
     if ($itemId) {
         ShoppingCart::add_item($itemId);
         if (!$this->isAjax()) {
             Director::redirectBack();
         }
     }
 }
開發者ID:nicolaas,項目名稱:silverstripe-ecommerce,代碼行數:10,代碼來源:ShoppingCart.php

示例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
 }
開發者ID:riddler7,項目名稱:silverstripe-ecommerce,代碼行數:21,代碼來源:ShoppingCart.php


注:本文中的ShoppingCart::add_item方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。