With normal mappers like the price one, we have no issues in replacing values, but the product reference one is slightly different because it relates the node (display) with the product id from commerce_product in a sepparate field.
If you want to load product references, the first time is just fine, but for updates you need to send all the product references again for adding a new one, which in some cases could be a pain.
Maybe it would make sense to have two mappers, one that is quicker and straightforward, replaces the field contents and that's it, another one would be "acumulative", and would not delete product ids but add them to the reference field.
I have a proof of concept working, if it makes sense I'll post the code here.
| Comment | File | Size | Author |
|---|---|---|---|
| #14 | 1188994_acumulative_mapper-14.patch | 5.01 KB | pcambra |
| #10 | 1188994_acumulative_mapper.patch | 3.7 KB | pcambra |
Comments
Comment #1
rfayI don't quite understand this. Can you give an example of how it works?
Comment #2
summit commentedSubscribing, greetings, Martijn
Comment #3
pcambraExample with code:
Comment #4
rfayI think an accumulative product reference is a really great idea... However, it makes a mess of normal updates, where the update might be coming from an external source and might be done over and over. Would we be closing the door on iterative updates?
Comment #5
pcambraYou're right, we shouldn't assume that users want to always do update. But I'm also worried about the likely confusion we could create having 2 different mappings for apparently the same thing.
Maybe we could keep one mapper and check the import mode, if we're creating/replacing we run the current mapping code, but when we're updating we run the acumulative one.
Comment #6
smokinggoat commentedHey Pedro -
I get an error on my test. I imported products using one Importer, then I created a new Display importer that attempts add several products to a single node (using the *same* product CSV - so one product per line). I used the module you sent me - and I get the following error:
Here is the export of my Importer:
Comment #7
rfay@smokinggoat, he just left a debug (dpm) statement in there. Enable devel module and the error will go away.
Comment #8
pcambraOops sorry about that, thanks Randy!
Comment #9
smokinggoat commentedYeah! Alright, it works! It properly accumulates the product references!
So Pedro, if you get an updated version with the conditional "accumulate" or "override" function, I'll test both cases. :-)
Comment #10
pcambraOk, here's a patch that considers the update_existing setting for the node processor and if it's set to update it uses the accumulative mapper, and if it's set to create or replace, it uses the usual mapper.
Comment #11
twistor commentedYou might want to check this against #996808: Update existing doesn't reset targets that have real_target set.. I think you might depending on behavior that's actually a bug. The $field that's attached to $entity is supposed to have been reset before the mapping starts. The reason for copying it off the entity is to support multiple mappings to the same target.
Comment #12
pcambraOk, reviewed what twistor says (finally) and it seems that our approach for accumulative processor is based in an "unexpected" behavior of Feeds, that seems that will disappear eventually as the majority of use cases are different of this one.
Normally one would expect to pass all the field values all over so you can delete references, i.e.
$node->field_values = array(1,2,3)
$node->field_values = array(1,2,4)
Will end with values: 1, 2 and 4
But we're dealing with an use case where we'll end with 1,2,3 and 4.
Probably we'll want to implement a FeedsProductDisplay plugin on top of FeedsProcessor to add a fourth option: add, replace, update and accumulate which will behave as we expect.
Setting back to needs work.
Comment #13
twistor commentedCouldn't you just set real_target to a non-existent attribute? Feeds would never reset it, and you would get the behavior you're looking for.
Comment #14
pcambraGreat idea twistor, thanks!
Here's a patch that changes the real target so that it's never reseted and just for the use case of updating (not replacing) it keeps the old records.
Comment #15
pcambraLet's commit this!
Thanks to everyone :)
Comment #17
summit commentedHi, sorry to ask, but is this commiitted?
greetings, Martijn
Comment #18
pcambraIt was committed to -dev version on Jan 13 as you can see in #15
Comment #19
summit commentedHi, Thanks for telling! Greetings, Martijn
Comment #20
chadmkidner commentedHello, I'm trying to understand whether my 'use case' is the same as the one solved with this patch or what changes I would need to make to have it work for my case.
I am understanding the idea behind accumulating values for the product references which is perfect but does this method of accumulate target this value specifically or effect all possible fields?
For example, if you have a product that comes in Small, Medium, and Large but also have other attributes.. say color is one. Would this method allow to accumulate for the unique value but update for non-unique attributes?
Comment #21
pcambraThis mapper option is for acumulating the product reference field in the product display, exactly as you can see in #12
This mapper option has anything to do with the product import itself but with the relationship between product display and product.
Comment #22
Isostar commentedThere is a problem with the accumulate in the case that in the import file some SKU's are removed from the product display.
In this case these product stay referenced.
Comment #23
pcambraPlease don't revive issues that have been committed, open a new one instead
Comment #24
vbard commentedHi!
Sorry, maybe I should create another issue, I'm new here... The question is whether this patch is already in 1.3 version of the module? If so, how can I use the feature discussed above? I came here from https://drupal.org/node/135116 and I'm trying to understand how can this feature help me to import multiple products into one product display node.
Comment #25
pcambraPlease do not reopen issues after a year of being closed.
Feature entered long ago and is available in the module.