Active
Project:
Commerce Price Table
Version:
7.x-1.x-dev
Component:
Code
Priority:
Normal
Category:
Support request
Assigned:
Unassigned
Reporter:
Created:
9 Sep 2011 at 18:34 UTC
Updated:
9 Mar 2018 at 01:27 UTC
Jump to comment: Most recent
Comments
Comment #1
pcambraI have something worked out, but you need to set a separator for multiprice support into a single field with unlimited values, for the case below is pipe separated values, for importing a sample of data like this "2,56|1|19";"2,33|20|-1" where the first number is the price amount, then the min qty, next the max qty being -1 considered by price table as unlimited.
Code example:
Comment #2
thill_ commentedHere is the code i put at the end of the module file and it does what i need,
The feeds tamper module will take care of multivalue for my needs
Comment #3
chrisjlee commented@pcambra @thill_ Which patch has been successful? And what file are you patching it to?
Comment #4
bojanz commentedNote that since #1322714: Odd Pricing Table Issue landed the
part in #1 needs to be
otherwise you'll get very wrong amounts displayed afterwards (0.16 instead of 16.30, for example).
Comment #5
chrisjlee commentedThis works as advertised! I had to use feeds tamper for it to work as thill pointed out.
Comment #6
pcambraComment #7
rlnorthcuttFYI - I needed to add a closing curly bracket in hook_feeds_processor_targets_alter() to keep it from breaking the site. Will update after I test an import
Comment #8
rlnorthcuttWorking Code
Got this code to work (wonderfully!) with some minor adjustments and a careful setup:
1) Added the closing curly bracket per my last comment
2) Removed the lines to convert the comma to a decimal on prices (my prices ARE in decimal format)
3) Made the change in #4
My code is here:
Add this to an existing module, a new one, or your own "glue" module... be sure to change the MYMODULE to whatever your module is actually named. If you want to hack Commerce Price Table, you can replace MYMODULE_ with commerce_price_table_ like the example in comment #2... of course, this is inadvisable as you will just lose this code on your next update of the module
Format for data
This is actually pretty straightforward, but I will leave a note her for those that may come behind. Basically, you want to create a delimited group of values (price, min qty, max qty) that is further delimited within a single field. Confused? Its sort of like making a nested array. Basically we want a single slot in the CSV to hold information about each additional entry in the table price field... and each of those entries is in turn composed of 3 separate pieces of info.
Ok - real example. Each of the 3 items for the table entries are expected by code to be separated by a pipe (|). And assuming that you are using commas in your CSV, then we want some OTHER character to delimit within the entry.. so I will use a semicolon. If we want to end up with table prices like this:
Then we need a single CSV entry of something like this:
40.00|0|10;30.00|11|25;20.00|25|50;10.00|51|-1
So - a line in your CSV showing the title, sku, price and price table, would look something like this:
Product title,sku-12345,40.00,40.00|0|10;30.00|11|25;20.00|25|50;10.00|51|-1
Tamper settings
Now - the code above WILL take care of parsing through each entry for the 3 items (as delimited by the pipe), but it WON'T break the single field into an array. Thats what the Feeds Tamper is for. Once you create your Feeds importer settings and your mapping, just click the "Configure Feeds Tamper" on the mapping screen. Then, add a plugin for the field that pull sin the price table data. You wan to choose the "Explode" plugin and select your delimiter (in this case, a semicolon).
That should do it! If your CSV is properly formatted, then you should be able to "/import" and make it happen. You may have a slightly different setup, or be working with something other than a CSV... but this should get you started.
Comment #9
rlnorthcuttPerhaps this could be added as a submodule of Commer Price Table with a readme to explain how it works? I am sure there are LOTS of people using Feeds to import and update products, and if they are wanting to use this module, then this would be handy to have.
Comment #10
ari-meetai commented#8 - Wonderful post. Thanks!
Comment #11
kevster commentedrlnorthcutt - great post many thx, also many thx to the module creator. Ive just managed to import 3,200 qty price breaks of various types all done in about 2 hours including setting this up. It all worked first time as well!
One thing ive noticed is that when re-importing the prices dont get updated, even after setting skip hash check. I ended up truncating the field_revision_field_quantity_pricing table to clear out the data.
Comment #12
markconroy commentedHi Folks,
I've created a module for this piece of functionality here:
https://github.com/markconroy/commerce-price-table-feeds
I'd put it as a module on this site, but I don't know enough about feeds and don't feel in a comfortable position to maintain it.
If anyone thinks it should be a module here, I can create it and give them maintainer access, or you can create it from the module I have posted on github.
Just to note: from my testing, this works perfectly - just make sure you follow the instructions in #8 - well done rlnorthcutt, a credit to you.
Comment #13
mctwist commentedJust set this up today. Worked like a charm!
Comment #14
millionleaves commentedI'm using Feeds extensible parser to import an XML file via XPath.
Here's how I managed to use the patch here to import multiple prices and quantities, in case anyone else has the same challenge.
First, here's a sample of the pricing for one product:
In the XML Xpath parser settings, I set up multiple parsers like this:
I mapped each one to a temporary target. I also mapped a Blank Source to my Price Table field (field_price_table).
I then used Feeds Tamper PHP to rewrite the Price Table field like so:
This put the data for all prices and quantities in the format described in #8, including adding 1 to the maximum value for each band for use as the minimum in the next band.
0.38|1|1000;0.14|1001|3000;0.1|3001|5000;0.07|5001|10000;0.07|10001|20000Finally, I used an Explode tamper on the Price Table field, using ; as the delimiter to split it into the 5 price lines for my price table.
After an import, all prices and min/max prices matched the data in the source XML.