Shipping based on number of items #898
Unanswered
ja-gallagher
asked this question in
Q&A
Replies: 1 comment
-
In your own plugin boot method, You can listen for cart's events : public function boot()
{
Event::listen('mall.cart.product.added', '\Acme\Mall\Classes\CartHandler');
Event::listen('mall.cart.product.updated', '\Acme\Mall\Classes\CartHandler');
Event::listen('mall.cart.product.removed', '\Acme\Mall\Classes\CartHandler');
// ...
} And in your own cart handler class you can set the shipping price according to your rules : // \Acme\Mall\Classes\CartHandler
class CartHandler
{
public function handle($cartProduct, $oldQuantity = null, $newQuantity = null)
{
$cart = Cart::byUser(Auth::getUser());
// Do your shipping calculations
$shippingPrice = 400;
// Set cart shipping price according to the documentation
// https://offline-gmbh.github.io/oc-mall-plugin/development/cart-model.html#enforce-shipping-price
//
$cart->forceShippingPrice(
ShippingMethod::getAvailableByCart($cart)->first()->id,
['EUR' => $shippingPrice],
'Optional, alternative name'
);
}
} |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi,
Wondering if anyone knows if it's possible to calculate shipping based on the number of items in an order?
I can only see options for flat-rate and by weight.
Thanks in advance!
Beta Was this translation helpful? Give feedback.
All reactions