Single Delivery Provider with multiple prices?

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!
swpierce
Posts: 53
Joined: 01 Nov 2015, 13:19

Single Delivery Provider with multiple prices?

Post by swpierce » 21 Nov 2015, 00:17

Is there a simple way to build a drop-down on the checkout page to allow the user to select a particular delivery service?

I can easily build a select box based on multiple providers by changing the radio selects to a select drop-down. What I need to do is display a drop-down of multiple services from a single provider.

I'd like to write a single Service/Provider/Delivery implementation that returns multiple prices. I want to then display a drop-down to the user with, for example: UPS Ground - 3.54, UPS 2nd Day - 5.72, UPS Overnight - 9.23 and let them select the service they'd like to use.

I'm not seeing a simple way to implement something like that. I see a way to have each of those 3 be a different provider in the admin interface but that would result in 3 calls to the back-end API instead of a single call that can retrieve all 3 prices.

Is it as simple as building an array in the provider implementation and adding a getPrices() method (or something similar) to use in the basket view? I'm not sure how to name the select drop-down, if so, such that the correct user selection makes it into the database.

Basically, I'm trying to not have to rewrite any of the checkout processing code if I don't have to. I'd rather be able to simply write a provider implementation and tweak the view to deal with the multiple options from that single provider.

Can you point me in the right direction?

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

Re: Single Delivery Provider with multiple prices?

Post by aimeos » 21 Nov 2015, 16:17

Some thoughts:
- If you have multiple variants of UPS, you need to distinguish them after ordering by a unique code. This requires multiple services each with one unique code. Thus, you can't use a single service provider easily
- The API is based on handling one price at a time for calcPrice()
- All decorators can also handle only one price
- Service providers also contain texts, images, etc. as well
- The "overhead" of calling three service providers to return the delivery services is small

Based on this, my suggestion would be to change the checkout delivery template and combine your UPS delivery options to one drop-down like you've said. Everything else would be too complicated and would also require changing the API.
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: Single Delivery Provider with multiple prices?

Post by BrianMecler » 22 Jul 2023, 11:01

Could we expand on this topic? I am looking to have the same functionality described here.

Is the suggested approach to:

- Login to the Admin panel and go to 'Setup' > 'Services'
- Add 3 new services, ex: UPS 1 Day, UPS 2 Day , UPS 3 Day
- The provider for the 3 new services is 'Standard'

Typically when the 3 new services are displayed on the checkout delivery page, the price shown comes from the static price configured under each service.

How would I get the price for each service to be dynamically calculated from the UPS API? And then display these prices next to each service on the checkout delivery screen?

Would that come from a custom decorator applied to each service?
Eg: 3 new decorators?

- /packages/mytheme/src/MShop/Service/Provider/Decorator/UPS1Day.php
- /packages/mytheme/src/MShop/Service/Provider/Decorator/UPS2Day.php
- /packages/mytheme/src/MShop/Service/Provider/Decorator/UPS3Day.php

If this is the case, is calcPrice() only used to update the totals on the checkout summary page? Or am I able to use calcPrice() to update the prices of each service on the checkout delivery page?

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

Re: Single Delivery Provider with multiple prices?

Post by BrianMecler » 22 Jul 2023, 11:46

I created a new decorator and added it to the new service. I only did the following in the new decorator:

Code: Select all

	public function calcPrice( \Aimeos\MShop\Order\Item\Iface $basket, array $options = [] ) : \Aimeos\MShop\Price\Item\Iface
	{
		// do something before
		$price = $this->getProvider()->calcPrice( $basket );
		// do something after

		$price->setCosts("99.00");

		return $price;
	}
This updated the shipping price for me on the checkout delivery screen as I wanted.

It seems like I would just make some API calls to UPS in this calcPrice() method and replace the value of '99.00' with the real price..

Is it really 'that simple' or did I just perform this is a very hacky way and bypassed a bunch of necessities?

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

Re: Single Delivery Provider with multiple prices?

Post by aimeos » 24 Jul 2023, 07:03

Yes, it's really that simple :-)
You can add configuration to your decorator and use the same implementation with different configuration for all UPS delivery options.
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

Post Reply