Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
xxl4 committed Aug 12, 2024
1 parent a10ad5c commit 64cccd5
Showing 1 changed file with 19 additions and 16 deletions.
35 changes: 19 additions & 16 deletions src/Upselling.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = '[email protected]'; // for testing

$processingOrder = $this->orderRepository->findOneWhere([
'customer_email' => "[email protected]",
'customer_email' => $cart->customer_email,
'status' => 'processing',
]);
//order findwhere created_at >= now()->subDay()
Expand All @@ -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));
}
Expand Down Expand Up @@ -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));

Expand Down

0 comments on commit 64cccd5

Please sign in to comment.