Esempio n. 1
0
 public function insertItemAction($productId = 0, $providerId = 0)
 {
     $productId = intval($productId);
     $providerId = intval($providerId);
     $productId = $productId > 0 ? $productId : $this->request->getPost("product_id", "int");
     $providerId = $providerId > 0 ? $providerId : $this->request->getPost("provider_id", "int");
     if ($productId < 1 || $providerId < 1) {
         $this->flashJson(500, array(), "非法请求");
         exit;
     }
     $qty = $this->request->getPost("qty", "int");
     if ($qty < 1) {
         $qty = 1;
     }
     $product = ProductModel::findFirst($productId);
     if (empty($product)) {
         $this->flashJson(500, array(), '抱歉,该商品不存在');
         exit;
     }
     $provider = ProviderModel::findFirst("user_id={$providerId} AND product_id={$productId}");
     if (empty($provider)) {
         $this->flashJson(500, array(), '非法请求');
         exit;
     }
     $displayCart = self::getCart();
     if (isset($displayCart[$providerId])) {
         $cart = $displayCart[$providerId];
     } else {
         $cart = new Cart\Cart();
     }
     if ($cart->hasItem($productId, false)) {
         $item = $cart->getItem($productId, false);
         $item->setQty($qty);
     } else {
         $item = new Cart\Item();
         $item->setId($productId)->setProvider($providerId)->setQty($qty)->setName($product->name)->setCustom("image_url", $product->image_url)->setSku('')->setPrice($provider->price)->setIsTaxable(true)->setIsDiscountable(true);
         $cart->setItem($item);
     }
     $displayCart[$providerId] = $cart;
     self::putCart($displayCart);
     if ($this->request->isAjax()) {
         $ajaxRet = $item->toArray();
         $ajaxRet['totals'] = $cart->getTotals();
         $this->flashJson(200, $ajaxRet);
         exit;
     } else {
         $this->response->redirect('cart/')->sendHeaders();
         exit;
     }
 }
Esempio n. 2
0
 */
/* This program is part of "Baidu Darwin PHP Software"; you can redistribute it and/or
 * modify it under the terms of the Baidu General Private License as
 * published by Baidu Campus.
 *
 * You should have received a copy of the Baidu General Private License
 * along with this program; see the file COPYING. If not, write to
 * the Baidu Campus NO.10 Shangdi 10th Street Haidian District, Beijing The Peaple's
 * Republic of China, 100085.
 */
/* Code: */
require_once __DIR__ . "/bootstrap/cli.php";
registerTask('sample');
use BullSoft\Cart;
//create toothbrush
$itemA = new Cart\Item();
$itemA->setId(1)->setName('ToothBrush')->setSku('toothbrush-1')->setPrice('1.99')->setQty(3)->setIsTaxable(true)->setIsDiscountable(true);
//create toothpaste
$itemB = new Cart\Item();
$itemB->setId(2)->setName('ToothPaste')->setSku('toothpaste-2')->setPrice('2.99')->setQty(1)->setIsTaxable(true)->setIsDiscountable(true);
$itemC = new Cart\Item();
$itemC->setId(3)->setName('Anniversary Present')->setSku('present-1')->setPrice('99.99')->setQty(1)->setIsTaxable(true)->setIsDiscountable(true);
//create a shipment
$shipmentA = new Cart\Shipment();
$shipmentA->setId(1)->setVendor('ups')->setMethod('ground')->setPrice('6.95')->setIsDiscountable(true)->setIsTaxable(true);
$cart = new Cart\Cart();
$cart->setItem($itemA)->setItem($itemB)->setItem($itemC)->setShipment($shipmentA)->setIncludeTax(true)->setTaxRate('0.07025')->setId(3);
//set up a single discount condition, for the shipping method
$condition1 = new Cart\DiscountCondition();
$condition1->setName('Shipping: code = ups_ground')->setCompareType(Cart\DiscountCondition::$compareEquals)->setCompareValue('ups_ground')->setSourceEntityType('shipments')->setSourceEntityField('code');
//discount conditions are wrapped by a condition compare object