-
-
Notifications
You must be signed in to change notification settings - Fork 19
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
Labels
enhancement
New feature or request
Milestone
Comments
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
Aug 18, 2019
mattias-persson
added a commit
that referenced
this issue
Aug 18, 2019
mattias-persson
added a commit
that referenced
this issue
Aug 22, 2019
mattias-persson
added a commit
that referenced
this issue
Aug 22, 2019
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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
The text was updated successfully, but these errors were encountered: