Пример #1
0
 public function shipmentAction($productId = 0, $providerId = 0, $shipmentSeq = 1)
 {
     $productId = intval($productId);
     $providerId = intval($providerId);
     $shipmentSeq = intval($shipmentSeq);
     $productId = $productId > 0 ? $productId : $this->request->getPost("product_id", "int");
     $providerId = $providerId > 0 ? $providerId : $this->request->getPost("provider_id", "int");
     $shipmentSeq = $shipmentSeq > 0 ? $shipmentSeq : $this->request->getPost("shipment_seq", "int");
     if ($productId < 1 || $providerId < 1 || $shipmentSeq < 1 || $shipmentSeq > 3) {
         $this->flashJson(500, array(), "非法请求");
         exit;
     }
     $product = ProductModel::findFirst($productId);
     if (empty($product)) {
         $this->flashJson(500, array(), '抱歉,该商品不存在');
         exit;
     }
     $displayCart = self::getCart();
     if (empty($displayCart)) {
         $this->flashJson(500, array(), "非法请求");
         exit;
     }
     if (isset($displayCart[$providerId])) {
         $cart = $displayCart[$providerId];
     } else {
         $this->flashJson(500, array(), "过期请求");
         exit;
     }
     $provider = ProviderModel::findFirst("user_id={$providerId} AND product_id={$productId}");
     if (empty($provider)) {
         $this->flashJson(500, array(), "非法请求");
         exit;
     }
     $shipmentId = $provider->{"shipment_id_" . $shipmentSeq};
     if (!empty($provider->{"shipment" . $shipmentSeq})) {
         if ($cart->hasShipment($providerId . '-' . $providerId, false)) {
             $cart->unsetShipment($productId . '-' . $providerId, false);
         }
         $shipmentDetail = array('id' => $providerId . '-' . $productId, 'vendor' => $provider->{"shipment" . $shipmentSeq}->slug, 'method' => $provider->{"shipment" . $shipmentSeq}->method, 'price' => $provider->{"shipment_price_" . $shipmentSeq});
         $cartShipment = new Cart\Shipment();
         $cartShipment->importJson(json_encode($shipmentDetail));
         $cart->setShipment($cartShipment);
         $displayCart[$providerId] = $cart;
         self::putCart($displayCart);
         $this->flashJson(200);
     }
 }
Пример #2
0
 * 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
//compare objects are intended for creating trees of conditionals
$compare1 = new Cart\DiscountConditionCompare();
$compare1->setOp('or')->setSourceEntityType('shipments')->addCondition($condition1);
//set up a single discount condition, for the item sku
$condition2 = new Cart\DiscountCondition();
$condition2->setName('Item: sku = toothpaste-2')->setSourceEntityType('items')->setSourceEntityField('sku')->setCompareType(Cart\DiscountCondition::$compareEquals)->setCompareValue('toothpaste-2');
$condition3 = new Cart\DiscountCondition();
$condition3->setName('Item: qty >= 2')->setSourceEntityType('items')->setSourceEntityField('qty')->setCompareType(Cart\DiscountCondition::$compareGreaterThanEquals)->setCompareValue('2');