Change product price in payment provider

Questions around the TYPO3 integration and plugins
Forum rules
Always add your TYPO3, Aimeos and PHP version as well as your environment (Linux/Mac/Win)
Spam and unrelated posts will be removed immediately!
Moritz
Advanced
Posts: 153
Joined: 07 Nov 2018, 14:05

Change product price in payment provider

Post by Moritz » 12 Apr 2019, 14:00

Hello,

I want to change the price of all products and its sum in the basket if my self created payment provider is selected as payment option.
I try to do that in the calcPrice() method.
On the confirmation page the price is correctly changed but after completion the old price is shown again in the order.
Is that the right place to change the prices or might be a basket plugin the better place?

Best regard,
Moritz
Ubuntu 22.04.01
PHP 7.4.30
Typo3 v11.5.21 LTS
Aimeos web shop 22.10.4-pre3

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

Re: Change product price in payment provider

Post by aimeos » 14 Apr 2019, 09:47

In calcPrice() of service decorators can should only set the shipping costs or shipping rebates but not modify the price items of the basket because calcPrice() is called even if it isn't selected. In a basket plugin you can do what you want but make sure that you add a new line with the rebate in the basket because the total is constantly recalculated based on the basket content.
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

Moritz
Advanced
Posts: 153
Joined: 07 Nov 2018, 14:05

Re: Change product price in payment provider

Post by Moritz » 15 Apr 2019, 09:48

Ok, thanks!
I tried it with a plugin to set all prices to 0.00€ if the configured payment is selected.
That works until I click 'change payment' on confirmation page and select a different payment.
The prices then are 0.00€ aswell.
Maybe I should call something like resetPrices() if a different payment as the configured is set.
Here is my code for better understanding:
basket_plugin.png
basket_plugin.png (80.25 KiB) Viewed 2584 times
Ubuntu 22.04.01
PHP 7.4.30
Typo3 v11.5.21 LTS
Aimeos web shop 22.10.4-pre3

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

Re: Change product price in payment provider

Post by aimeos » 15 Apr 2019, 10:56

Most likely, the ProductPrice basket plugin will update the price of the product again. Can you check?
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

Moritz
Advanced
Posts: 153
Joined: 07 Nov 2018, 14:05

Re: Change product price in payment provider

Post by Moritz » 15 Apr 2019, 11:10

The price will only be updated when I return to the shopping cart or click on "Buy Now".
However, I get an error message that the price has changed and have to click the button again to continue.
This may make sense if the price changes from 0.00€ to 19.99€.
However, if the prices are all changed to 0.00€ due to the chosen payment method, I would like to avoid the error message.
Ubuntu 22.04.01
PHP 7.4.30
Typo3 v11.5.21 LTS
Aimeos web shop 22.10.4-pre3

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

Re: Change product price in payment provider

Post by aimeos » 15 Apr 2019, 15:07

You have to disable the ProductPrice basket plugin to avoid this.
In the latest version, modified prices are skipped by the ProductPrice plugin so they will stay as is.
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

Moritz
Advanced
Posts: 153
Joined: 07 Nov 2018, 14:05

Re: Change product price in payment provider

Post by Moritz » 16 Apr 2019, 09:30

Disable the ProductPrice plugin is no option for me because then no price will be reset if I choose an other payment.
I think the error messages are ok for me.
My main problem is currently that I can't place an order if the prices are set to 0.00€ before.
When clicking "buy now" I get the price changed error again and again.
Ubuntu 22.04.01
PHP 7.4.30
Typo3 v11.5.21 LTS
Aimeos web shop 22.10.4-pre3

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

Re: Change product price in payment provider

Post by aimeos » 17 Apr 2019, 14:24

Because you ar getting into a loop at which the ProductPrice plugin updates the price again and throws an error that displays the warning. The solution is that you manage the product price in your own plugin (reduce the price if necessary and restore the price if a different option is chosen) with the ProductPrice plugin disabled.
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

Post Reply