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


PHP ShoppingCart::create方法代码示例

本文整理汇总了PHP中ShoppingCart::create方法的典型用法代码示例。如果您正苦于以下问题:PHP ShoppingCart::create方法的具体用法?PHP ShoppingCart::create怎么用?PHP ShoppingCart::create使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ShoppingCart的用法示例。


在下文中一共展示了ShoppingCart::create方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: singleton

 /**
  * Allows access to the cart from anywhere in code.
  * @return ShoppingCart Object
  */
 public static function singleton()
 {
     if (!self::$singletoncart) {
         self::$singletoncart = ShoppingCart::create();
     }
     return self::$singletoncart;
 }
开发者ID:helpfulrobot,项目名称:sunnysideup-ecommerce,代码行数:11,代码来源:ShoppingCart.php

示例2: doAddItemToCart

 public function doAddItemToCart($data)
 {
     $product = Product::get()->byID($data['ProductID']);
     $customisations = array();
     foreach ($data as $key => $value) {
         if (!(strpos($key, 'customise') === false) && $value) {
             $custom_data = explode("_", $key);
             if ($custom_item = ProductCustomisation::get()->byID($custom_data[1])) {
                 $modify_price = 0;
                 // Check if the current selected option has a price modification
                 if ($custom_item->Options()->exists()) {
                     $option = $custom_item->Options()->filter("Title", $value)->first();
                     $modify_price = $option ? $option->ModifyPrice : 0;
                 }
                 $customisations[] = array("Title" => $custom_item->Title, "Value" => $value, "ModifyPrice" => $modify_price);
             }
         }
     }
     if ($product) {
         $cart = ShoppingCart::create();
         $cart->add($product, $data['Quantity'], $customisations);
         $cart->save();
         // Clear any postage data that has been set
         Session::clear("Commerce.PostageID");
         $message = _t('Commerce.AddedItemToCart', 'Added item to your shopping cart');
         $message .= ' <a href="' . $cart->Link() . '">';
         $message .= _t('Commerce.ViewCart', 'View cart');
         $message .= '</a>';
         $this->controller->setSessionMessage("success", $message);
     }
     return $this->controller->redirectBack();
 }
开发者ID:helpfulrobot,项目名称:i-lateral-silverstripe-commerce,代码行数:32,代码来源:AddItemToCartForm.php

示例3: init

 public function init()
 {
     parent::init();
     // If no shopping cart doesn't exist, redirect to base
     if (!ShoppingCart::create()->getItems()->exists()) {
         return $this->redirect(ShoppingCart::config()->url_segment);
     }
 }
开发者ID:i-lateral,项目名称:silverstripe-checkout,代码行数:8,代码来源:Checkout_Controller.php

示例4: get

 /**
  * Shortcut for ShoppingCart::create, exists because create()
  * doesn't seem quite right.
  *
  * @return ShoppingCart
  */
 public static function get()
 {
     return ShoppingCart::create();
 }
开发者ID:helpfulrobot,项目名称:i-lateral-silverstripe-commerce,代码行数:10,代码来源:ShoppingCart.php

示例5: getCommerceCart

 /**
  * Return a the current shopping cart
  *
  * @return ShoppingCart
  */
 public function getCommerceCart()
 {
     return ShoppingCart::create();
 }
开发者ID:helpfulrobot,项目名称:i-lateral-silverstripe-commerce,代码行数:9,代码来源:Ext_Commerce_Controller.php

示例6: getPostageAreas

 /**
  * Function to find relevent postage rates, based on supplied country and
  * zip/postal code data.
  *
  * We make this a function as part of Commerce Controller, as there are
  * several points in the payment/order process that will make use of this
  * functionality
  *
  * @param $country String listing the country to search, this has to be an ISO 3166 code
  * @param $zipcode String listing the zip/postage code to filter by
  */
 public function getPostageAreas($country, $zipcode)
 {
     $return = new ArrayList();
     $countries = new ArrayList();
     $cart = ShoppingCart::create();
     $all_rates = $this->SiteConfig()->PostageAreas();
     // First find all area's for this country directly (no wildcards)
     foreach ($all_rates as $rate) {
         if (!(strpos(strtolower($rate->Country), strtolower($country)) === false)) {
             $countries->add($rate);
         }
     }
     // If we have no countries in the list specificly, then check for wildcards
     if (!$countries->exists()) {
         foreach ($all_rates as $rate) {
             if ($rate->Country == "*") {
                 $countries->add($rate);
             }
         }
     }
     // If we have a list of countries check them for post codes
     foreach ($countries as $rate) {
         $rate_codes = explode(",", $rate->ZipCode);
         foreach ($rate_codes as $rate_to_check) {
             $curr_length = strlen($rate_to_check);
             if (strtolower(substr($zipcode, 0, $curr_length)) == strtolower($rate_to_check)) {
                 $return->add($rate);
             }
         }
     }
     // If we still don't have anything to return, check or list of countries
     // for a wildcard
     if (!$return->exists()) {
         foreach ($countries as $rate) {
             if ($rate->ZipCode == "*") {
                 $return->add($rate);
             }
         }
     }
     // Now we have a list of locations, start checking for additional
     // rules an remove if not applicable.
     $total_cost = str_replace(",", "", $cart->SubTotalCost());
     $total_weight = str_replace(",", "", $cart->TotalWeight());
     $total_items = str_replace(",", "", $cart->TotalItems());
     $max_cost = 0;
     $max_weight = 0;
     $max_items = 0;
     // First loop through and find items that are invalid
     foreach ($return as $location) {
         if ($location->Calculation == "Price" && (double) $total_cost < $location->Unit) {
             $return->remove($location);
         }
         if ($location->Calculation == "Weight" && (double) $total_weight < $location->Unit) {
             $return->remove($location);
         }
         if ($location->Calculation == "Items" && (double) $total_items < $location->Unit) {
             $return->remove($location);
         }
     }
     // Now find max values based on units
     foreach ($return as $location) {
         if ($location->Calculation == "Price" && $location->Unit > $max_cost) {
             $max_cost = $location->Unit;
         }
         if ($location->Calculation == "Weight" && $location->Unit > $max_weight) {
             $max_weight = $location->Unit;
         }
         if ($location->Calculation == "Items" && $location->Unit > $max_items) {
             $max_items = $location->Unit;
         }
     }
     // Now loop through again and calculate which brackets each
     // Location fits in
     foreach ($return as $location) {
         if ($location->Calculation == "Price" && $location->Unit < $max_cost) {
             $return->remove($location);
         }
         if ($location->Calculation == "Weight" && $location->Unit < $max_weight) {
             $return->remove($location);
         }
         if ($location->Calculation == "Items" && $location->Unit < $max_items) {
             $return->remove($location);
         }
     }
     return $return;
 }
开发者ID:helpfulrobot,项目名称:i-lateral-silverstripe-commerce,代码行数:97,代码来源:Commerce_Controller.php


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