Pass data from delivery service decorator to view

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!
BrianMecler
Posts: 41
Joined: 03 Jun 2023, 17:30

Pass data from delivery service decorator to view

Post by BrianMecler » 15 Aug 2023, 21:44

Hello,

Laravel Framework 10.13.1, php8.1-fpm, aimeos/aimeos-laravel 2023.04.2

In my delivery service decorator I am getting FedEx shipping rates from the FedEx API for use in calcPrice(). I also want to use the shipping transit time from their API as well and display it with each delivery option presented during checkout.

What would be the best way to approach this?

It looks like I might need to copy the following into my templates folder?
./vendor/aimeos/ai-client-html/templates/client/html/checkout/standard/delivery-body.php

And then somehow inject an attribute from inside the calcPrice() method and utilize it in delivery-body.php?

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

Re: Pass data from delivery service decorator to view

Post by aimeos » 18 Aug 2023, 12:52

In that case the better approach might be to query the FedEx API in the getConfigFE() method and store the returned data to be used in calcPrice() later too.
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

BrianMecler
Posts: 41
Joined: 03 Jun 2023, 17:30

Re: Pass data from delivery service decorator to view

Post by BrianMecler » 19 Aug 2023, 16:14

Thank you this helps me get a little further.
I have been reading the documentation and playing with getConfigFE(), but not sure I am understanding..

When I implement the following test in my custom decorator:

Code: Select all

	public function getConfigFE( \Aimeos\MShop\Order\Item\Iface $basket ) : array
	{
		$list = parent::getConfigFE($basket);
		
		$feConfig = [
			'fedex.test1' => [
				'type' => 'string',
				'code' => 'fedex.test1',
				'label' => 'This is my label',
				'default' => '2-3 days',
				'public' => false
			],
			'fedex.test2'	=> [
				'type' => 'string',
				'code' => 'fedex.test2',
				'label' => 'This is my label',
				'public' => false,
				'default' => '3-5 days',
				'required' => false
			],
		];

		foreach( $feConfig as $key => $config ) {
			$list[$key] = new \Aimeos\Base\Criteria\Attribute\Standard( $config );
		}
	
		return $list;
	}
I see that I end up getting two new form fields for the customer to fill out on the delivery method selection screen. I could see how I might be able to use this, by setting the default value to the shipping transit time and then trying to hide the field label somehow.

But I suspect this isn't how you intended for me to use this when you suggested its usage..

Is there a way I should be using getConfigFE() to pass hidden data, rather than for collecting data from the customer/end user?

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

Re: Pass data from delivery service decorator to view

Post by aimeos » 31 Aug 2023, 06:24

The suggestion was to use getConfigFE() for querying the Fedex API as a side effect because it's the method that is called first and you can add options (only if you want). There is currently no other way to add additional data from an external API to delivery the options.
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

BrianMecler
Posts: 41
Joined: 03 Jun 2023, 17:30

Re: Pass data from delivery service decorator to view

Post by BrianMecler » 16 Sep 2023, 13:38

Thank you Aimeos,

When I implement the following in $feConfig:

Code: Select all

$feConfig = [
			'fedex.test1' => [
				'type' => 'string',
				'code' => 'fedex.test1',
				'label' => 'This is my label',
				'default' => '2-3 days',
				'public' => false
			],
			'fedex.test2'	=> [
				'type' => 'string',
				'code' => 'fedex.test2',
				'label' => 'This is my label',
				'public' => false,
				'default' => '3-5 days',
				'required' => false
			],
		];
I see the two configuration options appear on the delivery tab.

I am attempting to hide these from being displayed on the screen. Is that possible? Reading the documentation, I was under the impression that If i set these two options, they may be hidden:

'public' => false,
'required' => false

I am not sure if im misinterpreting the configuration documentation.

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

Re: Pass data from delivery service decorator to view

Post by aimeos » 18 Sep 2023, 21:25

It makes no sense to define frontend options if you want to hide them. From you previous reply, I would guess that you want to the customers to choose if they want standard or express delivery.
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

Post Reply