Service custom price with CalcPrice()
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!
Always add your Aimeos and PHP version as well as your environment (Linux/Mac/Win)
Spam and unrelated posts will be removed immediately!
Service custom price with CalcPrice()
Hello,
I would like to calculate a custom price for my delivery service... I created a provider and add a custom calcprice() function based on a service attribute choosen by user, I added :
$myprices = //array of prices;
$value = $service->getAttribute('mycode','delivery');
$thecost = myprices[$value];
$manager = \Aimeos\MShop\Factory::createManager( $this->getContext(), 'price' );
$price = $manager->createItem();
$price->setCosts($thecost);
return $price;
but most of the time, this calcprice() function is not taken in account and the service cost is finally 0.00
I checked my code and I realized that $basket->getService is empty at that point.
So my $value also is.
I'm not sure the reason why... The service is probably not added yet to the basket at this point.
Maybe I do need to move my custom CalcPrice() function to a decorator that will be called later?
Or maybe I do need to move it in a basket plugin set to addService after?
Sorry, I'm a bit confused !
Could you help me?
Thank you very much in advance
I would like to calculate a custom price for my delivery service... I created a provider and add a custom calcprice() function based on a service attribute choosen by user, I added :
$myprices = //array of prices;
$value = $service->getAttribute('mycode','delivery');
$thecost = myprices[$value];
$manager = \Aimeos\MShop\Factory::createManager( $this->getContext(), 'price' );
$price = $manager->createItem();
$price->setCosts($thecost);
return $price;
but most of the time, this calcprice() function is not taken in account and the service cost is finally 0.00
I checked my code and I realized that $basket->getService is empty at that point.
So my $value also is.
I'm not sure the reason why... The service is probably not added yet to the basket at this point.
Maybe I do need to move my custom CalcPrice() function to a decorator that will be called later?
Or maybe I do need to move it in a basket plugin set to addService after?
Sorry, I'm a bit confused !
Could you help me?
Thank you very much in advance
Re: Service custom price with CalcPrice()
As you've noticed correctly, the calcPrice() method is called before the (delivery) service options are displayed so the costs can be based on the current basket content. At this point, the basket doesn't contain any service. When the customer has chosen the service attribute and the "Next" button is clicked, the calcPrice() method is called again. At this point, the service and the attributes aren't part of the basket because it's only added afterwards.
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, give us a star
If you like Aimeos, give us a star
Re: Service custom price with CalcPrice()
Ok ... Sorry ! I thought that the calcprice() method was called to set the cost of the selected service.
So what is the correct way to set the cost of the service with a dynamic price?
Where do I need to set the cost:
- otherwhere in my provider?
- in a decorator that is maybe called after the service is added?
- in the basket plugin using the listener' setService.after '?
Thank you very much !
sbn
So what is the correct way to set the cost of the service with a dynamic price?
Where do I need to set the cost:
- otherwhere in my provider?
- in a decorator that is maybe called after the service is added?
- in the basket plugin using the listener' setService.after '?
Thank you very much !
sbn
Re: Service custom price with CalcPrice()
As long as we don't extend the calcPrice() method and hand over the attributes as well, the only way is by implementing a basket plugin.
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, give us a star
If you like Aimeos, give us a star