Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
If you import a product and the price is zero, the price gets dropped. Here's the patch to fix it.
Comment | File | Size | Author |
---|---|---|---|
#21 | commerce_feeds-Issue-1183006-21.patch | 1.69 KB | geek-merlin |
Comments
Comment #1
pcambraGood catch, commited.
Comment #3
iMiksuAfter this patch I'm getting error:
SQLSTATE[HY000]: General error: 1366 Incorrect integer value: '' for column 'commerce_price_amount' at row 1
multiple times and in the end I get:
SQLSTATE[21S01]: Insert value list does not match column list: 1136 Column count doesn't match value count at row 1
I was using XML file which contained an XML-node having an attribute being the price. In some cases there were not price attribute defined at all which probably caused my errors...
I'm not currently that familiar with Feeds API yet so I won't post a patch yet. Feel free to post a patch which handles my case too :)
Comment #4
rfayIt sounds like you have an empty input value in your price field?
I do kind of think this would be better as
if (!isset($price)) {
$price = 0;
}
When I made the patch I was just trying to respect existing code, but I think it would be better to set the price to zero.
Comment #8
iMiksuApparently in my case I was getting empty strings into the mapper function which wasn't meeting the conditions of !isset().
Because of that the value was passed as empty string which leaded PDO complaining about the incorrect integer value.
To fix the issue (and still being handling intended 0 values) I added extra check for skipping empty strings values too. This patch shouldn't drop 0 values, but I haven't tested it. Feel free to test :)
Comment #9
rfayI disagree. I think an empty value should be set to zero unless there's some reason not to. @iMiksu, you can solve your own problem by just having a nonempty field.
If somebody can say why a product should not get a price of 0 on import if no other price is set, please say so.
Comment #10
iMiksuAccording to your first message, I understood that the price of zero needs to be mapped and other empty values not. For me it sounds good to have default value of zero whatever happens.
How about checking if the value is not numeric, it would be replaced by zero?
Comment #11
iMiksuComment #12
rfayI think it has to be (!empty($v) && is_numeric($v)) or you'll have a warning.
Also, I think it's Drupal convention to use more meaningful variable names, so probably $value is better.
Comment #13
iMiksuTrue, that would be better. I think this is RTBC.
Comment #14
rfayDid you mean to attach a patch?
Comment #15
iMiksuYes. Would be great to have it tested.
My import works good with these changes.
Comment #16
rfayWell, I didn't actually test it but it looks perfect to me.
Comment #17
pcambraOk, let's commit it then, thanks Randy and iMiksu!
Comment #19
geek-merlinI ran into this and have an answer to #9 from rfay:
> If somebody can say why a product should not get a price of 0 on import if no other price is set, please say so.
Yep here: I have a "special price" field which may or may not have a value (is not required).
Comment #20
geek-merlinAlso, looking at the code, it looks like it will break for multiple value price fields:
* have 3 values in price field
* importer brings 2 values
result: 2 values imported, 3rd value as before.
Comment #21
geek-merlinAfter applying this patch
* ordinary price is imported to price field
* zero pricce is imported as zero
* empty price is imported as empty field
Comment #22
AdamGerthel CreditAttribution: AdamGerthel at Odd Hill commentedI was having the same problem as Axel (using a secondary "on sale" price field). Patch in #21 works very well.
Comment #23
geek-merlinso RTBC.
Comment #24
mglamanThis doesn't apply anymore with recent commit. Thanks for patch axel.rutz, I'll re-roll.
Comment #26
mglamanThanks, everyone!