Butik
Search…
Shipping
You can implement your own Shipping types to calculate your shipping costs.

Create a new shipping type

Use our command to create a gateway boilerplate.
1
php please butik:shipping
Copied!
This will give you the following boilerplate.
1
<?php
2
3
namespace DummyNamespace;
4
5
class DummyClass extends ShippingType
6
{
7
/**
8
* Calculate the price as you need it. This example will return the price as defined
9
* in your shipping rate. This is how "shipping by price" does get calculated.
10
*/
11
public function shippingCosts(): string
12
{
13
return $this->rate->price;
14
15
/**
16
* As an second example. This is how we do calculate the "price per item"
17
*/
18
// $price = $this->makeAmountSaveable($this->rate->price);
19
// return $this->makeAmountHuman($price * $this->itemCount);
20
}
21
}
Copied!

More flexibility needed?

No Problem. Check out the ShippingType class to see what's happening under the hood. Overwrite those methods from the ShippingType if needed.

One example

In case you want more control over your Shipping Type name, you can overwrite the existing method.
1
class DummyClass extends ShippingType
2
{
3
protected function name(): string
4
{
5
return 'My new name';
6
}
7
8
public function shippingCosts(): string
9
{
10
// do your stuff
11
}
12
}
Copied!

Add it to the config

After creating your own shipping type, remember adding it to your config file.
1
'shipping' => [
2
// other types
3
'new-shipping-type' => \YourNameSpace\NewShippingType::class,
4
],
Copied!
Last modified 1yr ago