Skip to content

Commit

Permalink
fix config the coupon code
Browse files Browse the repository at this point in the history
  • Loading branch information
xxl4 committed Sep 24, 2024
1 parent 306b05f commit d7200a9
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/Upselling.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ class Upselling {

private $cart;

private $coupon_code;

public function __construct(
protected CartRepository $cartRepository,
protected OrderRepository $orderRepository,
Expand All @@ -53,6 +55,11 @@ public function disable() {
config(['Upselling.enabled' => false]);
}

// set coupon code
public function setCouponCode($coupon_code) {
$this->coupon_code = $coupon_code;
}

public function applyUpselling($cart) {
$this->cart = $cart;

Expand All @@ -70,8 +77,11 @@ public function applyUpselling($cart) {
Cart::saveShippingMethod('free_free');

// Apply coupon code
$coupon_code = "upselling50"; // 50% discount coupon code
Cart::setCouponCode($coupon_code)->collectTotals();
if(!empty($this->coupon_code)) {
$coupon_code = $this->coupon_code;
Cart::setCouponCode($coupon_code)->collectTotals();
}


Cart::collectTotals();
Log::info('Processing order cart found '.json_encode($cart));
Expand Down

0 comments on commit d7200a9

Please sign in to comment.