Getting physical properties in decorator

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

Getting physical properties in decorator

Post by BrianMecler » 27 Jul 2023, 13:14

Hello,

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

In the Admin I setup physical properties for length, width, height, weight on each product. I want to use these in my FedEx decorators calcPrice() method to generate an accurate shipping quote.

Below is how I am currently looping through the products in the cart and generating line items for the shipping quote. Is this optimal? I want to ensure that I am not taking the long route and doing too much unnecessary fetching and data massaging jus to get these product properties:

Code: Select all

		$ids = $basket->getProducts()->getProductId();
		$manager = \Aimeos\MShop::create($this->context(), 'product');
		$filter = $manager->filter(true);
		$filter->add('product.id', '==', $ids->toArray());
		$items = $manager->search($filter, ['product/property']);
		$item_properties = $items->getPropertyItems();

		$properties = [];

		foreach( $basket->getProducts() as $orderProduct ) {
			$order_items = $item_properties->get( $orderProduct->getProductId(), [] )->toArray();
			foreach ($order_items as $order_item) {
				$properties[$order_item->getType()] = $order_item->getValue();
			}

			$FedEx->addNewLineItem()
				->weight = $properties['package-weight']
				->length = $properties['package-length']
				->width = $properties['package-width']
				->height = $properties['package-height']
		}

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

Re: Getting physical properties in decorator

Post by aimeos » 28 Jul 2023, 06:32

There's a more efficient way: Use the PropertyAdd plugin to add those properties to the products in the basket automatically:
https://aimeos.org/docs/latest/manual/p ... ropertyadd
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: Getting physical properties in decorator

Post by BrianMecler » 28 Jul 2023, 13:18

Thank you,

In Admin > Setup > Plugins I didnt see an existing entry for the PropertyAdd plugin listed. I clicked the button to add a new entry and selected 'PropertyAdd' as the provider. The 'types' option automatically appears, but I am not able to insert a value. Initially the input box does not even appear for the value. I can add a new option, called it 'types' and input the JSON array, but once I hit save the input box is cleared again and doesnt display after page reload..

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

Re: Getting physical properties in decorator

Post by BrianMecler » 28 Jul 2023, 20:28

Maybe the issue with the value input field not showing is a 'me' problem with my install?

For different decorator that I have, I tried to switch my beConfig to a 'select' and the select drop down never appears:

Code: Select all

private array $beConfig = array(
		'servicetype' => array(
			'code' => 'servicetype',
			'internalcode' => 'servicetype',
			'label' => 'FedEx service delivery type.',
			'type' => 'select',
			'internaltype' => 'string',
			'default' => [
				'GROUND_HOME_DELIVERY' => 'GROUND_HOME_DELIVERY',
				'FEDEX_GROUND' => 'FEDEX_GROUND',
				'FEDEX_2_DAY' => 'FEDEX_2_DAY',
				'PRIORITY_OVERNIGHT' => 'PRIORITY_OVERNIGHT',
				'FIRST_OVERNIGHT' => 'FIRST_OVERNIGHT',
			],
			'required' => true,
		),
	);
In the admin interface the browsers web developer tools show this for both the AddProperty value and my select dropdown value:

Code: Select all

<td class="config-row-value"><!----> <!----> <!----> <!----> <!----> <!----> <!----> <!----></td>

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

Re: Getting physical properties in decorator

Post by aimeos » 29 Jul 2023, 06:49

Sorry, the "list" type hadn't been implemented in the new config table code. This is fixed now and you can get the new aimeos/ai-admin-jqadm package by executing "composer up".
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: Getting physical properties in decorator

Post by BrianMecler » 29 Jul 2023, 12:16

Thank you, that fixed the issue with the PropertyAdd config value.

Post Reply