VirtueMart Forum

VirtueMart 2 + 3 + 4 => Virtuemart Development and bug reports => Topic started by: sleepigrl on August 09, 2012, 20:17:10 PM

Title: [BUGFIX?] Custom field Customer Text Input - Pricing
Post by: sleepigrl on August 09, 2012, 20:17:10 PM
I ran across what I think is a small issue with the pricing for the custom field "Customer Text Input."   If I set the "Price Per Letter" value to Yes, everything works fine.  However, if I set it to No, the customer is charged the amount assigned in the product, whether they enter text or not.

Seems to me that the logical flow for pricing for a should be like this:

Field is Empty: NO charge

Field has text:
- Price per letter is Yes, charged per letter amount as assigned in product
- Price per letter is No, charged flat amount as assigned in product

I tracked down the code to \plugins\vmcustom\textinput\textinput.php.   Adding the following else statement to the plgVmCalculateCustomVariant function around line 336 (right after the closing } from if ($productCustomsPrice->custom_price_by_letter ==1)  allows the calculation to work as stated above.  The logic is a bit different as I didn't want to rewrite the existing code, but it seems to be working just fine for me.   


else {
if (!empty($customVariant['comment'])) {
$productCustomsPrice->custom_price = 1 * $productCustomsPrice->custom_price ;
} else {
$productCustomsPrice->custom_price = 0.0;
}
}





Title: Re: [BUGFIX?] Custom field Customer Text Input - Pricing
Post by: Milbo on August 12, 2012, 02:20:49 AM
I wonder about your version, my file has only 190 lines, but I think I corrected it, take a look

if (!empty($customVariant['comment'])) {
if ($productCustomsPrice->custom_price_by_letter ==1) {
$charcount = strlen ($customVariant['comment']);
} else {
$charcount = 1.0;
}
$productCustomsPrice->custom_price = $charcount * $productCustomsPrice->custom_price ;
} else {
$productCustomsPrice->custom_price = 0.0;
}
Title: Re: [BUGFIX?] Custom field Customer Text Input - Pricing
Post by: sleepigrl on August 12, 2012, 15:39:18 PM
Thanks, Milbo!  That works well and the logic makes sense, at least the way it seems to me this should work.

I'm using 2.0.8e, but my file has lots of extra whitespace.  I think that's from unix to windows linefeed conversion, I probably need to grab new copies via FTP/binary so the line numbers are correct.