add fix for line items NaN

Hi everyone

I have noticed in a new install of suite 7.10.7 when inside a quote and adding line items,
if you choose a product with a price all the fields with prices in them will change to NaN.

after some investigation, I found that the id for the currency (“product_currency{LINE_ITEM_INDEX}”) to use inside the name_to_value_array coming back from the popup window
is “-99.00” instead of -99

because of this when it comes to setting the conversion rate to the product_currency_rate variable from the get_rate function, it returns back undefined instead of in this case 1.

every math function after that will then be trying to divide a value by undefined which fills everytthing with NaN’s

I don’t know what is causing the problem (products with no value i.e. £0.00 return back correct id -99)
but to patch over it client side edit the in the file modules/AOS_Products_Quotes/line_items.js file
directly after

product_currency_id = product_currency_id ? product_currency_id : -99;

I have added

if (product_currency_id === "-99.00") product_currency_id = Number(product_currency_id);

is this a known problem?

It’s quite similar to this one although it might be different

In that case the problem was user input, entering a string instead of a number, although there should be a validation before using the value…

Hi pgr

I don’t believe these issues are related.
parijke was indeed updating a drop down list incorrectly.

the value which is throwing off the calculations in line items for me is the id for the currency which if you have no additional currencies, the default currency id is -99.

after selecting the product from the pop_up window, the JSON object being returned from the server contains the malformed currency_id.
looks like it is being treated like a decimal value server side.

I want to dive into this a bit further but I haven’t figured out how the server deals with pop_up window requests

In LineItems.js: 297 it seems to be getting the value from the HTML

    document.getElementById('product_product_list_price' + ln).value = format2Number(ConvertFromDollar(dollar_product_price, lastRate));

and in fact my HTML has

<td><span class="alignedLabel">&nbsp;</span><input name="product_currency[0]" id="product_currency0" value="-99" type="hidden">

Which gives a correct “-99” value. I can’t reproduce your problem.

Does your HTML contain “-99.00” instead?

1 Like

Hi pgr
yes I had a look and I found the -99.00 value in the html

<input type="hidden" name="product_currency[0]" id="product_currency0" value="-99.00">

I wonder what could be different between my system and yours, to cause this different behaviour… I’m also on 7.10.7, so… :blink:

1 Like

I’m interested to find out.
@pgr do you know where in the source code I can find the functions/methods which fetches and sends the popup window data server side?

I’m planning to sprinkle in some extra log calls and hopefully shed some light on this.

I think it would be best to find out if this is something that may happen to other users and have a fix for it.
I don’t feel comfortable with my JavaScript patch as it will probably get nuked during updates.

The function seems to be called open_popup, I think it’s this one that gets invoked:

But I’m not sure, you’ll have to check with a debugger…