delivery cost decorator

Help for integrating the Laravel package
Forum rules
Always add your Laravel, Aimeos and PHP version as well as your environment (Linux/Mac/Win)
Spam and unrelated posts will be removed immediately!
WGSF
Posts: 22
Joined: 04 Apr 2023, 11:12

delivery cost decorator

Post by WGSF » 08 Jun 2023, 11:09

Laravel 10, Aimeos 2022, php 8.2

I've added my own delivery service in admin>setup>services : MY-DELIVERY
and I want the compute my own delivery cost that appears in shop/checkout/delivery page.

The Computation of my delivery price is a little bit tricky, depending on product, weight and categories and I need to make my own computation because weight provider and options seems not sufficient.
For example :
-for each product in category 'BIG' the delivery cost = 10. If customer order 3 'BIG' the delivery cost= 30.
-for 'MEDIUM' category, delivery cost depends on weight
0-5Kg cost 6
6-15Kg cost 8
15-22Kg cost 10 (22 Kg is the last weight step)
When weight is greater than 22Kg ie 25Kg, delivery cost is 22Kg + 3 KG => cost : 10+6
Customer can order 'BIG' and 'MEDIUM' in the same basket : then the delivery cost for 3 BIG and 25Kg of 'MEDIUM' is 30+10+6.

Therefore, I've created a Decorator and located it in packages/mypackage/src/Client/Html/Common/Decorator/Mydecorator.php
In order to allow that decorator, I've also modified the config/shop.php with
'client' => [
'html' => ['decorators' => [
'default' => ['Mydecorator'],
],
...

The content of Mydecorator class looks like that :
<?php
namespace Aimeos\Client\Html\Common\Decorator;

class Mydecorator
extends \Aimeos\Client\Html\Common\Decorator\Base
implements \Aimeos\Client\Html\Common\Decorator\Iface
{

}


But inside that decorator I don't know how or what to access (or override) in order to compute the delivery price with quantity/weight/category.
Can you please help me ?
Regards

kdim95
Advanced
Posts: 208
Joined: 26 Aug 2022, 12:17

Re: delivery cost decorator

Post by kdim95 » 08 Jun 2023, 11:42

Hello,

I believe that it's better to create your own Delivery Service Provider.

Documentation on creating a Delivery Service Provider:
https://aimeos.org/docs/2022.x/provider ... /delivery/

Documentation on what methods you can override in your new Delivery Service Provider:
https://aimeos.org/docs/2022.x/providers/service/

I believe you're looking to override the calcPrice() method.

Once you've created your Delivery Service Provider, you can use it in your admin/setup/services instead of the "Standard" or whatever provider you're using.

In case you want to override an existing Delivery Service Provider and add additional price calculation functionality, I think you should only extend the original Delivery Service Provider in your new Delivery Service Provider and then override the calcPrice() or the methods that calcPrice() depends on in that custom Delivery Service Provider.

WGSF
Posts: 22
Joined: 04 Apr 2023, 11:12

Re: delivery cost decorator

Post by WGSF » 08 Jun 2023, 16:04

Thanks again kdim95
I'll try that very soon

User avatar
aimeos
Administrator
Posts: 7915
Joined: 01 Jan 1970, 00:00

Re: delivery cost decorator

Post by aimeos » 10 Jun 2023, 06:23

You can also use an existing delivery provider and implement your own decorator on top that does the shipping cost calculation according to your algorithm. For service provider decorators see here:
https://aimeos.org/docs/latest/provider ... ecorators/
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

Post Reply