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.
I have found the Feeds integration great, and have used it to speed up the importing of products to Commerce. Thank You.
What I am looking for is allowing the importing of shipping weights and dimensions that the Commerce Physical Product (http://drupal.org/project/commerce_physical) which uses Physical Fields (http://drupal.org/project/physical) requires. I have tried mapping the field, but the field is not available to map to. This would be a great and helpful feature, I hope it is possible with the current structure. Thanks.
Comments
Comment #1
Ollie222 CreditAttribution: Ollie222 commentedI too would find this useful functionality.
Comment #2
msamavi CreditAttribution: msamavi commentedAs it is not possible to import weight into the physical field, I have imported weights into a custom temporary field, now I am looking for a way to copy the contents of that field to Weight field and delete the custom temporary field. Any advise please?
Comment #3
Patricec CreditAttribution: Patricec commentedI had a go at exposing enabling the mapping of physical weights by Commerce Feeds in the attached patch.
Some limitations of the patch though :
I hope this patch will help build a robust solution to this issue.
Comment #4
pcambraMarking as needs review
Comment #5
msamavi CreditAttribution: msamavi commentedI applied the patch #3 and now when I want to got to mapping page, I get the following error message:
Fatal error: Call to undefined function _commerce_physical_feeds_processor_targets_alter() in /foo/sites/all/modules/commerce_feeds/commerce_feeds.module on line 63
Any advise to fix, please?
Comment #6
msamavi CreditAttribution: msamavi commentedIn the file commerce_feeds.module I changed the lines:
function commerce_physical_feeds_processor_targets_alter(&$targets, $entity_type, $bundle_name) {
module_load_include('inc', 'commerce_feeds', 'mappers/commerce_physical');
_commerce_physical_feeds_processor_targets_alter($targets, $entity_type, $bundle_name);
}
into
function commerce_physical_feeds_processor_targets_alter(&$targets, $entity_type, $bundle_name) {
module_load_include('inc', 'commerce_feeds', 'commerce_physical');
_commerce_physical_feeds_processor_targets_alter($targets, $entity_type, $bundle_name);
}
that solved my problem.
Comment #7
Patricec CreditAttribution: Patricec commentedYes, the file commerce_physical.inc is supposed to be stored in the mappers directory, but the patch at #3 does not take this into account.
Sorry for the inconvenience.
Comment #8
bmx269 CreditAttribution: bmx269 commentedThis is looking like great action is taking place. Can this be made as a proper patch to allow testing please?
Comment #9
pcambraI don't see anything wrong with #3, it applies and works fine for me out of the box.
However, I'd like dimensions support to be included prior to committing this into commerce feeds.
Comment #10
travisc CreditAttribution: travisc commentedapplying the patch in #3 I get
patch unexpectedly ends in middle of line
patch: **** malformed patch at line 96:
Comment #11
bmx269 CreditAttribution: bmx269 commentedI have added the mapper, and it does not put csv the value into the field. Hmm
Comment #12
bmx269 CreditAttribution: bmx269 commentedJust to clarify the previous post, I had a csv already pulling in products, just added the weight field mapping. The feed is not updating the products with the weights to the Physical Weight field.
-Thanks
Comment #13
Summit CreditAttribution: Summit commentedHi, Yes please for dimensions support! Greetings, Martijn
Comment #14
nrackleff CreditAttribution: nrackleff commentedSubscribing. We have over 2000 products that we need to import from a client's previous propriety CMS. The commerce feeds works great for this except for the problem of not being able to import weight and dimensions. The weights are in pounds too, so the default to kg is not good for us either.
Comment #15
rtdean93 CreditAttribution: rtdean93 commentedLove this - but one question. If I replace 'kg' with 'lbs' as the default unit - will this work? Is it 'lbs' or 'lb'?
$field[LANGUAGE_NONE][$i]['unit'] = 'lbs';
Comment #16
Masala CreditAttribution: Masala commented#3 work for me. Thanks Patricec!
very strange that it is not done initially ..
Comment #17
pcambraJust noting that #1356462: Feeds Support for Commerce Physical Product has been marked as duplicated in favor of this one and has a very useful patch that may be merged with the one here.
Comment #18
andyg5000I've created a patch based on @Patricec #3 patch above and the one that I initially created for
#1356462: Feeds Support for Commerce Physical Product. This patch allows you to import commerce physical product dimensions, weight, and their respective units. This is working great for our needs and will hopefully help some of you out.Note: I had trouble applying patch #3 so this patch is based off of commit: http://drupalcode.org/project/commerce_feeds.git/commit/cb2bcdc.
Comment #19
andyg5000Marking as needs review
Comment #20
andrewscullion CreditAttribution: andrewscullion commentedHi,
I just tried this patch 'commerce_feeds_physical_weight_and_dimensions-1293820-17.patch' on the latest dev release of commerce_feeds and it results in a white screen on the 'admin/structure/feeds/edit/update_products/mapping' page.
The MAMP php error log shows: Fatal error: Call to undefined function _commerce_physical_feeds_processor_targets_alter() in ../sites/all/modules/contrib/commerce_feeds/commerce_feeds.module on line 75
I am no feeds code expert so some help to solve this would be greatly appreciated as this is vital functionality if you calculate shipping by weight on thousands of products.
Comment #21
pcambraInteresting. The patch actually creates a mappers/commerce_physical.inc file, are you sure you've got that file?
Comment #22
andrewscullion CreditAttribution: andrewscullion commentedI worked this issue out, running the patch in terminal was putting the 'commerce_physical.inc' file in the 'commerce_feeds/' folder and not 'commerce_feeds/mappers/' I do not know why, is there something you have to add to run the patch to make it place it in the correct sub-folder?
The feeds mappings page now works, thought I was home and dry, however, running the import does not update the weights. The log confirms that products were imported, however the product view shows no change to the weights for each product.
Any ideas?
Comment #23
pcambraAre you doing this for the patch?
patch -p1 < commerce_feeds_physical_weight_and_dimensions-1293820-17.patch
I've just tried it and I get the file correctly in mappers directory
Comment #24
andrewscullion CreditAttribution: andrewscullion commentedI looked back through the terminal commands and I missed off the -p1, these things are usually my mistakes.
Much more importantly though, do you have any idea why the feed to the commerce product physical weight is not updating the stored weights?
Comment #25
andyg5000Hey @andrewscullion. Can you export your feed mapper and attach it to this thread so we can help you troubleshoot?
Comment #26
andrewscullion CreditAttribution: andrewscullion commentedThank you for the help.
Comment #27
andyg5000Hey Andrew,
I didn't realize that my patch required you to name your weight field commerce_physical_weight. I'm working on a revised patch and will have it up shortly. Thanks for catching this!
Andy
Comment #28
andyg5000@andrewscullion,
Give this patch a whirl. I tested with your feed importer and it appears to fix the problem. Roll back to the latest commit of the commerce_feeds module and then apply this patch. Let me know if you have any trouble.
Thanks for finding this!
Andy
Comment #29
andrewscullion CreditAttribution: andrewscullion commentedThanks for the rapid response, and it's nice to find out it is not me doing something stupid for a change. I will try the new one and let you know.
Andrew
Comment #30
andrewscullion CreditAttribution: andrewscullion commentedThat worked perfectly, thank you Andy.
Comment #31
p55mac CreditAttribution: p55mac commentedWorked perfectly for me. Thanks.
Comment #32
wgsimon CreditAttribution: wgsimon commentedIt works very well for me. Thank you.
I didn't want to have a column for the units in the csv file I was importing so I modified
commerce_physical_feeds_set_target( )
from the above patch. Additionaly it gives the correct defaults for empty cells. To do: Set numeric values to their defaults as well.Will
Comment #33
andyg5000@wgsimon,
Great idea about pulling in default values. I think I've got an idea to make this work based on what you've provided. It would include the numeric defaults as well. Hopefully, I can get an updated patch shortly.
Thanks,
Andy
Comment #34
andyg5000Here's a patch that loads numeric defaults (if they exist) as well as the default unit for both weight and dimensions. The numeric defaults would be set automatically if they wern't included in the feed, but I don't think it hurts to add them in the patch since their values are already loaded in the $info_instance array. This also allows you to set specific dimension fields in a feed while others will pull their default value, if for some reason you wanted to do that. Thanks to @wgsimon for finding the default unit feature and submitting the code above. Needs review.
NOTE: Do not use this patch
Comment #35
pcambraOk, a couple of thoughts on this, the patch looks really nice but after seeing this line:
I just realized that the Physical fields could be attached to anything, not just products, maybe after all this patch belongs in there if we can figure out how to know the entity type in the callback without hardcoding it.
Looking into this.
Comment #36
pcambraRelated #1372070: Integrate with Feeds (Patch Ready)
Comment #37
wgsimon CreditAttribution: wgsimon commentedThe entity type is not hardcoded in the suggestion in my last post (#32), although it may not be the best way of getting it.
Will
Comment #38
pcambraRight, I need to figure out if this is safe enough:
$entity_type = key($info['bundles']);
Comment #39
andyg5000Ahh... good catch. I was following the conventions in the commerce_price.inc mapper. Is it possible that it needs to be updated as well, as to not limit price to 'commerce_product'? It looks like we can use $entity->feeds_item->entity_type instead. I realize today that the patch in #34 is crap. I thought I tested it thoroughly, but apparently not. Here is an updated patch that fixes a few problems in #34 and swaps the hard coded 'commerce_product' with $entity->feeds_item->entity_type. Its confusing to me that $entity->type references the bundle name instead of the entity type, but that's beside the point here.
Comment #40
wgsimon CreditAttribution: wgsimon commentedIf we leave out some but not all of the numeric values in the mapping then the defaults are not set correctly.
If Dimensions:Units doesn't come last in the mapping order then it will be overwritten with the default.
I suggest replacing
with
With this modification we can have any combination of missing mappings and missing import fields.
It may be more elegant if the defaults could to be initialised in a function higher up the call stack. This will avoid checking to see if the defaults have been set each time.
Will
Comment #41
andyg5000Awesome Will. I've updated the patch with your suggestion. I tested adding length in the mapper and leaving the rest blank and it works like a charm.
Comment #42
wgsimon CreditAttribution: wgsimon commentedRelated: #1600818: Price:Currency mapping before Price:Amount mapping overwrites currency with default value
Comment #43
pcambraAs discussed, the patch belongs to Physical module as you could add weight and dimensions to nodes, users or whatever entity you'd like to.
I've reviewed the patch, adapted it to physical and fixed the entity_type getting method.
Patch proposed in #1372070: Integrate with Feeds (Patch Ready)
Many many thanks to everyone here for the effort, patches and testing!!!
Comment #44
caco13 CreditAttribution: caco13 commented#41 worked for me.
Comment #45
frederico CreditAttribution: frederico commented#41 worked for me as well. Thanks to both andyg5000 and Will!!! -Frederico
Comment #46
Marvin Daugherty CreditAttribution: Marvin Daugherty commented#41 worked for me too. It updated the weights for ALL product variation types, even though I had specified the "Bundle" and "Product type". It was what I wanted to do, and I expected to need to specify quite a few "Bundles" and "Product Types". I was both shocked and happy. Thanks for the hard work.
Comment #47
philsward CreditAttribution: philsward commentedFor anyone needing to import 0 (zero) to the physical, install feeds tamper (if you aren't using it already) and make sure to add a plugin for "Format a Number" and set the decimals to 1 or more places.
Otherwise, if you have a 0 (zero) in your import data, this does not get carried through to the site and is instead left blank on required fields.
Comment #48
brandonc503 CreditAttribution: brandonc503 commentedhave commerce_feeds (7.x-1.x-dev)
Comment #49
philsward CreditAttribution: philsward commented@brandonc503 are you patching against the stable or dev version?
Comment #50
manglanis6@gmail.com CreditAttribution: manglanis6@gmail.com commented@brandonc503 you were able to find a solution? Even I am getting the same error
Comment #51
philsward CreditAttribution: philsward commented@manglanis6 I found the ultimate "solution".
1) Don't apply the patch from #41. If you have, delete commerce_feeds and re-download it.
2) Download and use any version of the physical module that is released on or after November 26, 2016. As of right now, that means you need to use the dev version of physical because 1.0 does not contain the code for it.
#43 points out this functionality was removed from commerce_feeds module and placed within the physical module, making the patch in #41, unnecessary.
So, install the physical module to get this functionality, as long as the physical module is newer than 1.0.