Page 1 of 1

Set the price for an item from a textfield // Variable Price

Posted: 01 Apr 2017, 20:45
by ltwmaster
Hey Girls and Guys,

following question, you may respond in german if its easier for your:
I want to have an item which has a variable price. I'm selling physical vouchers. Customers should be able to purchase the voucher at any value they want. eg. 55,55€.

My approach would be to price the voucher at 0,01€ and do some easy Javascript magic with the quantityfield. So for example if they enter 55,55€ to translate that in to 5555 in to the quantity.

Any better ideas than this workaround?

Cheers,
LTW

Re: Set the price for an item from a textfield // Variable P

Posted: 02 Apr 2017, 16:52
by aimeos
This way, you would have the problem that you need to adapt the templates where the basket/order data is shown to avoid quantities of "5555" and values of "0.01" which might be confusing to customers.

Another way would be to create a new product type (e.g. "voucher") and implement a new decorator for the basket frontend controller like done for bundles: https://github.com/aimeos/ai-controller ... Bundle.php

You can assign a custom attribute to the voucher product which displays an input field and set the price of the product in your new decorator to that value. Only the ProductPrice basket plugin couldn't be used in that setup because it would reset the price value.

Re: Set the price for an item from a textfield // Variable P

Posted: 03 Apr 2017, 16:34
by ltwmaster
Hi Aimeos,

thank you for the quick reply. I'll try that and come back to you incase I have questions, but your answer is very straight forward!

Cheers,
LTW

Re: Set the price for an item from a textfield // Variable P

Posted: 03 Apr 2017, 20:57
by aimeos
If you are successful, we would love to get a pull request of what you've implemented :-)

Re: Set the price for an item from a textfield // Variable P

Posted: 15 May 2017, 12:23
by ltwmaster
Hi Guys,

its me again :)

I'm a bit stuck on the logic of this case:
So I introduce a new product type called "voucher" and this one uses a specific decorator, like in the example for bundles that you have posted above...

Is this also used on the Invoice? In the E-Mails?

Is there really no way to have a variable price? :)

Thank you

Re: Set the price for an item from a textfield // Variable P

Posted: 15 May 2017, 22:18
by aimeos
The "voucher" decorator has to do the same as the implementation for the simple articles, which are only a few lines of code. The only difference to simple articles is that it will set the price according to the given value from the user (including some checks that it isn't negative for example).

At the end, the product is a simple article and displaying the price in the checkout process and the e-mails will be automatically correct.