Martin1182
2 months ago
288
2
Laravel

Fix ecommerce Listeners\CartUpdatedListener error

Posted 2 months ago by Martin1182

Hi, Could you help me fix the error I'm getting?

CartUpdatedListener.php

    public function handle($event)
    {
        $couponName = session()->get('coupon')['name'];

        if ($couponName) {
            $coupon = Coupon::where('code', $couponName)->first();

            dispatch_now(new UpdateCoupon($coupon));
        }
    }

Execute the job

public function handle()
    {
        if (Cart::currentInstance() === 'default') {
            session()->put('coupon', [
                'name' => $this->coupon->code,
                'discount' => $this->coupon->discount(Cart::subtotal()),
            ]);
        }
    }

ERROR: Trying to access array offset on value of type null

Please sign in or create an account to participate in this conversation.