Usage
After successfully installing the Cart package, you can start managing your shopping cart using the following methods:
Cart::add(mixed $id, string $name, int $quantity = 1, float $price, array $options = [], float|null $taxrate = null);
Cart::add(mixed $id, string $name, int $quantity = 1, float $price, array $options = [], float|null $taxrate = null);
Adds an item to the cart.
Cart::all();
Cart::all();
Retrieves all items in the cart as a collection of objects with detailed information about each item.
Cart::associate($id, $model);
Cart::associate($id, $model);
Associates an item in the cart with a corresponding model.
Cart::clear();
Cart::clear();
Clears the entire cart, removing all items.
Cart::count();
Cart::count();
Returns the total number of items in the cart.
Cart::empty();
Cart::empty();
Checks if the cart is empty.
Cart::get($id);
Cart::get($id);
Retrieves the item with the given ID from the cart, returning the item if it exists, or null otherwise.
Cart::subtotal();
Cart::subtotal();
Calculates and returns the subtotal (pre-tax) price for all items in the cart.
Cart::tax();
Cart::tax();
Calculates and returns the total taxes for all items in the cart.
Cart::total();
Cart::total();
Calculates and returns the total price (including taxes) for all items in the cart.
Cart::updateQuantity($id, $quantity);
Cart::updateQuantity($id, $quantity);
Updates the quantity of an item in the cart. If the new quantity is less than or equal to 0, the item will be removed from the cart.
Cart::updateDetails($id, array $details);
Cart::updateDetails($id, array $details);
Updates the details (name, price, options) of an item in the cart.
Cart::updateName($id, $name);
Cart::updateName($id, $name);
Updates the name of an item in the cart.
Cart::updateOptions($id, array $options);
Cart::updateOptions($id, array $options);
Updates the options of an item in the cart.
Cart::updatePrice($id, $price);
Cart::updatePrice($id, $price);
Updates the price of an item in the cart.
Cart::applyCoupon(Coupon $coupon);
Cart::applyCoupon(Coupon $coupon);
Applies a coupon to the current session. Ensure that the coupon is valid and not expired before applying. If the coupon is invalid, an exception will be thrown.
Cart::removeCoupon();
Cart::removeCoupon();
Removes the currently applied coupon from the session.
Cart::getAppliedCouponDetails();
Cart::getAppliedCouponDetails();
Retrieves the details of the applied coupon from the session, including the code, type, and discount amount. If no coupon is applied, returns null.