Hi,

I tried for ages to import prices in a pricefield. After awhile I saw that I had a space after the price so instead of ;275; it was ;275 ;
And because of that the prices wouldn't import.
Could may be the field be trimmed so that spaces before of after the price are cleaned with importing?

A great module this is further, thanks for building!
Greetings, Martijn

Comments

ryumkin’s picture

Actualy even worse for my experience.
I was trying to import in the following formats: "4500.00", "4500,00".
I got "45.0" in both cases - that's realy strange. It looks like it devide on 100, why?
Import was HTTP CSV.

pcambra’s picture

Hi ryumkin,
I don't think that is the same subject as the original request of trimming the spaces out of the prices prior to import.
Anyways, your question has been answered many times both in this issue queue and the commerce one, decimal places aren't actually a property of each price but from the currency itself, so if you import 4500, you'll always get 45.00 in those currencies such as dollars or euros that have 2 decimal places configured in hook_currency_info(), that's the way Commerce works for prices, storing them in what we call "minor units" so the price amount stored is totally independent of the currency properties for getting much more flexibility and less constraints and rounding issues.

So basically if you wanna import, being the target currency € or $ or whatever with 2 decimal places, you need to take this into account, and for getting 4500€ as price, you need to have 450000 as the quantity in the import, for preprocessing data, I'd recommend you to take a look to feeds tamper module.

pcambra’s picture

Status: Active » Fixed

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

gigabates’s picture

Issue summary: View changes
Status: Closed (fixed) » Needs work
StatusFileSize
new1.09 KB

The commit in #3 doesn't fix the problem. The trim function will never get called because the value is being checked with `is_numeric()` first, which will return false if the value contains whitespace.

We need to trim the value before the validation. It also wouldn't hurt to trim for currency codes too.

acidpotato’s picture

Status: Needs work » Fixed

Try using feeds tamper module, it is very useful for trimming whitespace around prices and in general all text fields. I've used it to import thousands of products and has worked well.

Trimming feature in commerce feeds is useful but redundant.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.