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


PHP ShoppingCart::setQuantity方法代碼示例

本文整理匯總了PHP中ShoppingCart::setQuantity方法的典型用法代碼示例。如果您正苦於以下問題:PHP ShoppingCart::setQuantity方法的具體用法?PHP ShoppingCart::setQuantity怎麽用?PHP ShoppingCart::setQuantity使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在ShoppingCart的用法示例。


在下文中一共展示了ShoppingCart::setQuantity方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: setquantityitem

 /**
  * Sets the exact passed quantity.
  * Note: If no ?quantity=x is specified in URL, then quantity will be set to 1.
  *@return Mixed - if the request is AJAX, it returns JSON - CartResponse::ReturnCartData(); If it is not AJAX it redirects back to requesting page.
  */
 public function setquantityitem($request)
 {
     $this->cart->setQuantity($this->buyable(), $this->quantity(), $this->parameters());
     return $this->cart->setMessageAndReturn();
 }
開發者ID:nieku,項目名稱:silverstripe-ecommerce,代碼行數:10,代碼來源:ShoppingCart.php

示例2: executeAddToCart

 public function executeAddToCart()
 {
     if ($this->getRequest()->isXmlHttpRequest()) {
         sfProjectConfiguration::getActive()->loadHelpers('Partial');
         $this->user = $this->getUser()->getRaykuUser();
         $item_id = $this->getRequestParameter('it');
         $quantity = 1;
         $this->item = ItemPeer::retrieveByPK($item_id);
         if (!$this->item->getIsActive()) {
             $this->item = NULL;
         }
         if ($this->item) {
             if ($this->item->getQuantity() > $quantity) {
                 $this->user = $this->getUser()->getRaykuUser();
                 $c = new Criteria();
                 $c->add(ShoppingCartPeer::IS_ACTIVE, true);
                 $c->add(ShoppingCartPeer::USER_ID, $this->user->getId());
                 $c->addDescendingOrderByColumn(ShoppingCartPeer::CREATED_AT);
                 $this->cart_items = ShoppingCartPeer::doSelect($c);
                 $tot_price = 0;
                 foreach ($this->cart_items as $cart_item) {
                     $tot_price = $tot_price + $cart_item->getTotalPrice() + $cart_item->getTotalShippingCharge();
                 }
                 $tot_price = $tot_price + $this->item->getPricePerUnit() * $quantity + $this->item->getShippingChargePerUnit() * $quantity;
                 if ($tot_price <= $this->user->getPoints()) {
                     $shopping_cart = new ShoppingCart();
                     $shopping_cart->setItemId($item_id);
                     $shopping_cart->setUserId($this->user->getId());
                     $shopping_cart->setQuantity($quantity);
                     $shopping_cart->setTotalPrice($this->item->getPricePerUnit() * $quantity);
                     $shopping_cart->setTotalShippingCharge($this->item->getShippingChargePerUnit() * $quantity);
                     $shopping_cart->setIsActive(true);
                     $shopping_cart->save();
                     $quantity_avail = $this->item->getQuantity();
                     $quantity_avail = $quantity_avail - $quantity;
                     $this->item->setQuantity($quantity_avail);
                     $this->item->save();
                     return $this->renderText(get_component('shop', 'cartBox'));
                 } else {
                     return $this->renderText('<span style="line-height:26px"><center>Sorry! Not enough RP!</center></span>' . get_component('shop', 'cartBox'));
                 }
             } else {
                 return $this->renderText('Sorry! Item out of stock' . get_component('shop', 'cartBox'));
             }
         } else {
             return $this->renderText('Sorry! No item is there' . get_component('shop', 'cartBox'));
         }
     }
 }
開發者ID:rayku,項目名稱:rayku,代碼行數:49,代碼來源:actions.class.php


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