当前位置: 首页>>代码示例>>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;未经允许,请勿转载。