Page 1 of 1

Change product price in payment provider

Posted: 12 Apr 2019, 14:00
by Moritz
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

Re: Change product price in payment provider

Posted: 14 Apr 2019, 09:47
by aimeos
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.

Re: Change product price in payment provider

Posted: 15 Apr 2019, 09:48
by Moritz
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 2546 times

Re: Change product price in payment provider

Posted: 15 Apr 2019, 10:56
by aimeos
Most likely, the ProductPrice basket plugin will update the price of the product again. Can you check?

Re: Change product price in payment provider

Posted: 15 Apr 2019, 11:10
by Moritz
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.

Re: Change product price in payment provider

Posted: 15 Apr 2019, 15:07
by aimeos
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.

Re: Change product price in payment provider

Posted: 16 Apr 2019, 09:30
by Moritz
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.

Re: Change product price in payment provider

Posted: 17 Apr 2019, 14:24
by aimeos
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.