示例#1
0
 private function getNewOrderItem(Address $address = null, CartItem $cartItem, ShippingOption $shippingOption = null)
 {
     $product = $cartItem->getProduct();
     $feeType = $address ? $address->getFeeType() : null;
     /** @var \App\Modules\OrderModule\Entities\OrderItem $orderItem */
     $orderItem = $this->orderItemRepository->createModel(['product_name' => $product->name, 'price' => $product->price, 'sale_price' => $product->sale_price, 'products_total' => $cartItem->products_total ?? 0, 'shipping_total' => $shippingOption && $feeType ? $shippingOption->{$feeType} * $cartItem->quantity : 0, 'quantity' => $cartItem->quantity]);
     $orderItem->setAttributes($cartItem->getAttributeOptions());
     if ($shippingOption && $address) {
         $orderItem->setShiping($shippingOption->snapshot($feeType, $cartItem->quantity));
     }
     $orderItem->setProduct($cartItem->getProduct());
     $this->cartItemRepository->delete($cartItem);
     return $orderItem;
 }
 private function checkProductHasNoValidShippingPlanForAddress($product)
 {
     if (!$this->address) {
         return true;
     }
     $this->address->setFeeType($this->seller);
     $shippingPlans = $this->shippingPlanRepository->findWhereProduct($product);
     foreach ($shippingPlans as $shippingPlan) {
         foreach ($shippingPlan->shippingOptions as $option) {
             if (isset($option->{$this->address->getFeeType()}) and $option->{$this->address->getFeeType()}) {
                 return false;
             }
         }
     }
     return true;
 }