conedevelopment / bazar

Bazar is an e-commerce package for Laravel applications.
https://root.conedevelopment.com
MIT License
421 stars 56 forks source link

Shipping calculate cost problem #191

Closed bobitza closed 2 years ago

bobitza commented 2 years ago

Description:

I don't understand how to use Shipping, i want to setup on local-pickup with price 20 RON How i register on cart that cost? I tried but not working, docs is very bad:

   Shipping::calculate(function (Shippable $model) {
            //--
            return (float) $model->getTotal() - 20.0;
         });

I want something simple Shipping:add(20);

iamgergo commented 2 years ago

Where do you see this code you copied here in the docs?

I don't know if you are familiary with Laravel's drivers/manager concept. Shipping and Gateways are using this concept.

You need to create a new driver class and implement the calculate method. Then add the shipping class to the manager.

This is what the docs are saying: https://bazar.conedevelopment.com/docs/shipping#shipping-drivers

bobitza commented 2 years ago

Ok and after that, what i call to apply to my cart that driver cost ?

bobitza commented 2 years ago

OK i found: First you call: $shippingCart = Cart::getShipping(); Then $shippingCart->calculateCost(false); and from that you obtain$shippingCart->getPrice() to obtain cost of shipping