Skip to content

Commit

Permalink
fix upselling coupon
Browse files Browse the repository at this point in the history
  • Loading branch information
xxl4 committed Sep 5, 2024
1 parent 8e7d109 commit 6ea84e1
Showing 1 changed file with 4 additions and 53 deletions.
57 changes: 4 additions & 53 deletions src/Upselling.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,84 +45,35 @@ public function __construct(
// enable the upselling
public function enable() {
// Enable upselling logic here
//Log::info('Upselling logic enabled');
config(['Upselling.enabled' => true]);
}

// disable the upselling
public function disable() {
// Disable upselling logic here
//Log::info('Upselling logic disabled');
config(['Upselling.enabled' => false]);
}

public function applyUpselling($cart) {
$this->cart = $cart;
// Apply upselling logic here
//Log::info('Upselling logic applied '.json_encode($cart));

// // Get cart items
// $cartItems = $this->cartItemRepository->findWhere(['cart_id' => $this->cart->id]);

// // Get cart total
// $cartTotal = $this->cart->grand_total;

// // Get cart total quantity

// $cartTotalQuantity = 0;
// foreach ($cartItems as $cartItem) {
// $cartTotalQuantity += $cartItem->quantity;
// }

// // Get cart total price
// $cartTotalPrice = 0;
// foreach ($cartItems as $cartItem) {
// $cartTotalPrice += $cartItem->total;
// }

// // Get cart total weight
// $cartTotalWeight = 0;
// foreach ($cartItems as $cartItem) {
// $cartTotalWeight += $cartItem->product->weight * $cartItem->quantity;
// }

// // Get cart total volume
// $cartTotalVolume = 0;
// foreach ($cartItems as $cartItem) {
// $cartTotalVolume += $cartItem->product->volume * $cartItem->quantity;
// }

//check the email of the customer have processing order
//$customer = auth()->guard('customer')->user();


//check the email of the customer have processing order in 24 hours

// created_at betwwen 24 hours
$processingOrder = $this->orderRepository->findOneWhere([
'customer_email' => $cart->customer_email,
'status' => 'processing',
'created_at' => ['>=', now()->subDay()]
]);
//order findwhere created_at >= now()->subDay()

Log::error('Processing order email '.$cart->customer_email);
Log::error('Processing order cart '.json_encode($cart));
Log::error('Processing order found '.json_encode($processingOrder));
Log::error("Processing Data:". now()->subDay());


if($processingOrder && !empty($cart->customer_email)) {
//Log::info('Processing order found '.json_encode($processingOrder));

Cart::saveShippingMethod('free_free');

// Apply coupon code
$coupon_code = "upselling50";
$coupon_code = "upselling50"; // 50% discount coupon code
Cart::setCouponCode($coupon_code)->collectTotals();




Cart::collectTotals();

Log::info('Processing order cart found '.json_encode($cart));
}

Expand Down

0 comments on commit 6ea84e1

Please sign in to comment.