From 64cccd5f2af290285ff9f29b06e959224d2deffc Mon Sep 17 00:00:00 2001 From: Steve <34465153+xxl4@users.noreply.github.com> Date: Mon, 12 Aug 2024 09:51:08 +0800 Subject: [PATCH] fix --- src/Upselling.php | 35 +++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/src/Upselling.php b/src/Upselling.php index 3fa0167..96fc95c 100644 --- a/src/Upselling.php +++ b/src/Upselling.php @@ -82,9 +82,9 @@ public function applyUpselling($cart) { //$customer = auth()->guard('customer')->user(); //check the email of the customer have processing order in 24 hours - //$cart->customer_email = 'PLM3@163.com'; // for testing + $processingOrder = $this->orderRepository->findOneWhere([ - 'customer_email' => "PLM3@163.com", + 'customer_email' => $cart->customer_email, 'status' => 'processing', ]); //order findwhere created_at >= now()->subDay() @@ -94,19 +94,18 @@ public function applyUpselling($cart) { Log::info("Processing Data:". now()->subDay()); - if($processingOrder) { + if(!$processingOrder) { //Log::info('Processing order found '.json_encode($processingOrder)); Cart::saveShippingMethod('free_free'); - foreach ($cart->items as $item) { - $itemCartRuleIds = $this->process($item); - } + // Apply coupon code + Cart::setCouponCode('hao123'); + - // free shipping for the items - //Cart::collectTotals(); + Cart::collectTotals(); Log::info('Processing order cart found '.json_encode($cart)); } @@ -153,15 +152,19 @@ public function process(CartItem $item): array $baseDiscountAmount = ($quantity * $item->base_price + $item->base_tax_amount - $item->base_discount_amount) * ($rulePercent / 100); + + // 50% of the product price + $item->discount_amount = $discountAmount; + $item->base_discount_amount = $baseDiscountAmount; + + $item->discount_percent = $rulePercent; + $item->base_price = $item->base_price - $baseDiscountAmount; + $item->price = $item->price - $discountAmount; + $item->total = $item->price * $item->quantity; + $item->base_total = $item->base_price * $item->quantity; + - $item->discount_amount = min( - $item->discount_amount + $discountAmount, - $item->price * $quantity + $item->tax_amount - ); - $item->base_discount_amount = min( - $item->base_discount_amount + $baseDiscountAmount, - $item->base_price * $quantity + $item->base_tax_amount - ); + Log::info('Upselling Discount applied new '.json_encode($item));