Checkout process-update shipping cost

How to configure and adapt Aimeos based shops as developer
Forum rules
Always add your Aimeos and PHP version as well as your environment (Linux/Mac/Win)
Spam and unrelated posts will be removed immediately!
khizar
Posts: 99
Joined: 19 Jan 2021, 09:51

Checkout process-update shipping cost

Post by khizar » 27 Feb 2021, 05:57

Hi aimeos,
I am using aimeos with laravel.
Laravel version: laravel 8
Aimeos version: "~2020.10"

I have given a task to update shipping cost according to the total weight of the basket
Image
To achieve this task
1) i have created a decorator(Costdecorator) under the directory
ext\moudhah\client\html\src\Client\Html\Common\Decorator
which includes following code

Code: Select all

	<?php

namespace Aimeos\Client\Html\Common\Decorator;

class Costdecorator
extends \Aimeos\Client\Html\Common\Decorator\Base
implements \Aimeos\Client\Html\Common\Decorator\Iface
{
    public function calcPrice(\Aimeos\MShop\Order\Item\Base\Iface $basket)
    {   dd('ok');
        // do something before
        $price = $this->getProvider()->calcPrice($basket);
        // do something after
        
        return $price;
    }

   
}

2) i have added configuration inside shop.php file

Code: Select all

	'client' => [
		'html' => [
			................................
			'basket' => [
				'cache' => [
					// 'enable' => false, // Disable basket content caching for development
				],
				'related' => [
					'decorators' => [
						'global' => ['Costdecorator']
					]
				]
			],
			....................................
			
		],
	],
Now the problem is when i add items to the basket and when basket page is loaded that calcPrice function is not called please guide me what i am doing wrong

Note: please guide me that how can i access
1) total weight of the basket
2) shipping cost which i have defined in delivery service

and then recalculate shipping cost based on above two values.Please guide me step by step and please dont redirect me to the documentation links because i have searched the docs and also the previous questions being asked on the forum but got nothing to solve my problem

khizar
Posts: 99
Joined: 19 Jan 2021, 09:51

Re: Checkout process-update shipping cost

Post by khizar » 01 Mar 2021, 05:04

waiting for a reply

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

Re: Checkout process-update shipping cost

Post by aimeos » 01 Mar 2021, 10:48

There's already a Weight decorator that shows/hides the delivery options based on the product package-weigth properties:
https://github.com/aimeos/aimeos-core/b ... Weight.php

Here's the documentation for the Weight decorator:
https://aimeos.org/docs/latest/manual/s ... rs/#weight
Usage:
https://aimeos.org/docs/latest/manual/s ... ors/#usage

Keep in mind that it doesn't calculate the price of the shipping service but shows/hides shipping options depending on the weight. Add several shipping options like parcel, heavy transport, etc. with different weight range configurations.
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

khizar
Posts: 99
Joined: 19 Jan 2021, 09:51

Re: Checkout process-update shipping cost

Post by khizar » 01 Mar 2021, 11:38

i have waited two days what you told me is that i already know.i think you didn't read the question and just answered it i know there is a weight decorator but my requirement is that i want to recalculate the shipping cost please read my question and then answer it

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

Re: Checkout process-update shipping cost

Post by aimeos » 01 Mar 2021, 11:48

You haven't mentioned the Weight decorator and that doesn't fit your needs. Nevertheless, use it as reference for you own decorator esp. the register() method and the calculation of the weight for the products in the basket. In fact, you should extend from the Weight decorator and only add the calcPrice() method.

The rest, esp. how to configure your decorator so it's used also applies to your own one:
https://aimeos.org/docs/latest/manual/s ... ors/#usage
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

khizar
Posts: 99
Joined: 19 Jan 2021, 09:51

Re: Checkout process-update shipping cost

Post by khizar » 04 Mar 2021, 11:59

aimeos wrote: 01 Mar 2021, 11:48 You haven't mentioned the Weight decorator and that doesn't fit your needs. Nevertheless, use it as reference for you own decorator esp. the register() method and the calculation of the weight for the products in the basket. In fact, you should extend from the Weight decorator and only add the calcPrice() method.

The rest, esp. how to configure your decorator so it's used also applies to your own one:
https://aimeos.org/docs/latest/manual/s ... ors/#usage
hey aimeos please give me answer by my question
1) i think i have to extend my decorator from Costs decorator because i want to recalculate the shipping cost so how can i extend from Costs decorator.please tell me how, not redirect me to docs this time.

Code: Select all

	<?php

namespace Aimeos\Client\Html\Common\Decorator;

class Costdecorator
extends \Aimeos\Client\Html\Common\Decorator\Base
implements \Aimeos\Client\Html\Common\Decorator\Iface
{
    public function calcPrice(\Aimeos\MShop\Order\Item\Base\Iface $basket)
    {   dd('ok');
        // do something before
        $price = $this->getProvider()->calcPrice($basket);
        // do something after
        
        return $price;
    }

   
}
2) please tell me is there any problem in my configuaration

Code: Select all

'client' => [
		'html' => [
			'locale' => [
				'select' => [
					'currency' => [
						'param-name' => 'currency',
					],
					'language' => [
						'param-name' => 'locale',
					],
				],
			],
			'basket' => [
				'cache' => [
					// 'enable' => false, // Disable basket content caching for development
				],
				'related' => [
					'decorators' => [
						'global' => ['Costdecorator']
					]
				]
			],
			.....................
			
			
		],
	],
3) is it neccessary to apply Costs decorator on my delivery service in order to work my Costdecorator(custom decorator) because you can see in the code i have implemented die and dump and it is not working.please give me answer by my question.Thanks

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

Re: Checkout process-update shipping cost

Post by aimeos » 05 Mar 2021, 14:32

khizar wrote: 04 Mar 2021, 11:59 1) i think i have to extend my decorator from Costs decorator because i want to recalculate the shipping cost so how can i extend from Costs decorator.please tell me how, not redirect me to docs this time.
No, because it's easier to extend from the Weight decorator and implement the calcPrice() method in addition.

Extending from another class in basic object-orientend programming stuff you should know if you want to extend Aimeos:

Code: Select all

class Costdecorator
	extends \Aimeos\Client\Html\Common\Decorator\Weight
	implements \Aimeos\Client\Html\Common\Decorator\Iface
khizar wrote: 04 Mar 2021, 11:59 2) please tell me is there any problem in my configuaration
Yes, service decorators are not configured in the config files but in the admin backend instead. Therefore I've added the links to the docs in my reply before.
khizar wrote: 04 Mar 2021, 11:59 3) is it neccessary to apply Costs decorator on my delivery service in order to work my Costdecorator(custom decorator) because you can see in the code i have implemented die and dump and it is not working.please give me answer by my question.Thanks
No, the Costs decorator isn't required because it would interfere with your own decorator. Check again the service decorator documentation to understand how service decorators work:
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

khizar
Posts: 99
Joined: 19 Jan 2021, 09:51

Re: Checkout process-update shipping cost

Post by khizar » 08 Mar 2021, 10:00

aimeos wrote: 05 Mar 2021, 14:32
khizar wrote: 04 Mar 2021, 11:59 1) i think i have to extend my decorator from Costs decorator because i want to recalculate the shipping cost so how can i extend from Costs decorator.please tell me how, not redirect me to docs this time.
No, because it's easier to extend from the Weight decorator and implement the calcPrice() method in addition.

Extending from another class in basic object-orientend programming stuff you should know if you want to extend Aimeos:

Code: Select all

class Costdecorator
	extends \Aimeos\Client\Html\Common\Decorator\Weight
	implements \Aimeos\Client\Html\Common\Decorator\Iface
khizar wrote: 04 Mar 2021, 11:59 2) please tell me is there any problem in my configuaration
Yes, service decorators are not configured in the config files but in the admin backend instead. Therefore I've added the links to the docs in my reply before.
khizar wrote: 04 Mar 2021, 11:59 3) is it neccessary to apply Costs decorator on my delivery service in order to work my Costdecorator(custom decorator) because you can see in the code i have implemented die and dump and it is not working.please give me answer by my question.Thanks
No, the Costs decorator isn't required because it would interfere with your own decorator. Check again the service decorator documentation to understand how service decorators work:
https://aimeos.org/docs/latest/provider ... ecorators/
can you tell me how can i apply my new decorator(which i mentioned above) to service provider because when i go to my admin panel ,the provider field is disabled i cannot type the my decorator name
Image

khizar
Posts: 99
Joined: 19 Jan 2021, 09:51

Re: Checkout process-update shipping cost

Post by khizar » 09 Mar 2021, 06:02

waiting for reply

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

Re: Checkout process-update shipping cost

Post by aimeos » 09 Mar 2021, 18:00

Click on the "+" symbol right of the "Provider" field to add your decorator to the service:
https://aimeos.org/docs/latest/manual/s ... ors/#usage
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

Post Reply