Page 1 of 1

Single Delivery Provider with multiple prices?

Posted: 21 Nov 2015, 00:17
by swpierce
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?

Re: Single Delivery Provider with multiple prices?

Posted: 21 Nov 2015, 16:17
by aimeos
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.

Re: Single Delivery Provider with multiple prices?

Posted: 22 Jul 2023, 11:01
by BrianMecler
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?

Re: Single Delivery Provider with multiple prices?

Posted: 22 Jul 2023, 11:46
by BrianMecler
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?

Re: Single Delivery Provider with multiple prices?

Posted: 24 Jul 2023, 07:03
by aimeos
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.