Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Facades for Cart and Coupons #10

Open
7 tasks done
mattias-persson opened this issue Dec 22, 2018 · 1 comment
Open
7 tasks done

Facades for Cart and Coupons #10

mattias-persson opened this issue Dec 22, 2018 · 1 comment
Labels
enhancement New feature or request
Milestone

Comments

@mattias-persson
Copy link
Contributor

mattias-persson commented Dec 22, 2018

Is your feature request related to a problem? Please describe.
We currently only support using the REST API for dealing with the cart. This may be insufficient for more complex shops where custom functionality needs to be combined with it.

Describe the solution you'd like
Implement facades and helper methods for managing the cart.

Additional context
Possibly also allow configuring whether the REST api should be enabled at all.

Implement facade methods for

  • Getting the cart summary
  • Getting the current cart count
  • Clearing the cart
  • Adding a cart item
  • Updating the quantity of a cart item
  • Removing a cart item
  • Applying a discount coupon
@mattias-persson mattias-persson added the enhancement New feature or request label Dec 22, 2018
@mattias-persson
Copy link
Contributor Author

Some suggestions for managing the cart:

use Happypixels\Shopr\Facades\Cart;

// Get the cart summary.
Cart::get();

// Get the cart count.
Cart::count();

// Clear the cart.
Cart::clear();

// Add a cart item, set the quantity of it, apply options, add sub items, ovverride the price.
Cart::add($shoppable)
    ->quantity($request->get('quantity'))
    ->withOptions($request->get('options'))
    ->withSubItems($request->get('sub_items'))
    ->overridePrice($request->get('price'))
    ->save();

// Update the cart item quantity.
Cart::find($id)->update(['quantity' => $request->get('quantity')]);

// Delete a cart item.
Cart::delete($id);

And for applying a discount coupon (I suggest we throw an exception for each validation rule so it's easy to handle each scenario if necessary):

try {
    Cart::addDiscount($coupon);
} catch (\Happypixels\Shopr\Exceptions\CartNotEmptyException $e) {
    // The cart isn't empty.
} catch (\Happypixels\Shopr\Exceptions\OnlyOneCouponPerOrderException $e) {
    // A coupon has already been applied.
} catch (\Happypixels\Shopr\Exceptions\CouponAlreadyAppliedException $e) {
    // This coupon has already been applied.
} catch (\Happypixels\Shopr\Exceptions\CouponNotFoundException $e) {
    // The coupon doesn't exist.
} catch (\Happypixels\Shopr\Exceptions\CouponTimespanInvalidException $e) {
    // The coupon is invalid due to it's timespan.
} catch (\Happypixels\Shopr\Exceptions\CartValueTooLowException $e) {
    // The cart value is below the coupon lower limit or value.
} catch (\Exception $e) {
    // Something else went wrong.
}

mattias-persson added a commit that referenced this issue Jul 31, 2019
mattias-persson added a commit that referenced this issue Jul 31, 2019
mattias-persson added a commit that referenced this issue Jul 31, 2019
mattias-persson added a commit that referenced this issue Jul 31, 2019
mattias-persson added a commit that referenced this issue Aug 2, 2019
@mattias-persson mattias-persson added this to the 2.0 milestone Sep 5, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant