Stock levels + Attributes CSV Import

Downloads


This adds support for the Stock (uc_stock) and Attributes (uc_attribute) modules to the Node Import (node_import) product.

Supports importing attributes and stock levels via csv. See the CSV reference file for how to setup a CSV file for attribute import.

REQUIREMENTS

the following modules must be installed:

  • Stock (uc_stock)
  • Node Import (node_import)

INSTALL

Unzip and put the uc_stock.inc and attribute.inc files into your:

modules/node_import/supported/ubercart

Stock Levels

folder and you should get 3 new options to map CSV columns to: Active, Stock & Threshold.

Tip: if you name your column headers with these names they should auto map for you, see stock-example.csv in the zip file.

Attributes

Before you begin importing you must first create a Product Class with the attributes you want for the product. Each attribute must have all the options you could want for that attribute as the import does not create options that are missing, it will just skip them. Now creates the attributes as it encounters them.

This now creates a temp file, called 'node_import_uc_attribute_temp.txt' in your 'files' folder, with a list of all the Node IDs its encountered while processing the Attributes for them. If you have done an import before you will want to DELETE THIS FILE (but it still might work if you don't). There doesn't seem to be a nice way to do this programmatically unfortunately Sad

In the CSV you must have one row per combination of attributes for each product (see 'attribute-example.csv' in the zip file). You should have 2 SKU columns as well. One SKU column will be the parent product SKU and should be th same for all rows of the attribute combo rows (this is how all the different attribute combination rows are grouping into the same product). The second SKU (Sub. SKU) should be different for every row in the CSV and will be assigned to each combo of the attributes. This will fill in the "adjustments" form and will also be used by the Stock module for giving individual stock levels to each attribute combo.

On Step 4 of the Node Import process you should see a group of fields titled "Product Attributes", here you should be able to map all the attributes for the chosen Product Class/Type to columns in you CSV as well as choose which column will be used foe the Sub. SKU as discussed above.

Development Note

This module is in development so no guaranties or promises about its working.


PreviewAttachmentSize
node_import_supported_v5.zip11.15 KB
chrislynch's picture
Offline
Joined: 01/22/2010
Juice: 2
Having a mix of products with attributes and without

Hi there,

If you have two product classes, one that has attributes and one that does not, you can run into problems.

The version attached has been tweaked to work around this by checking to see if there are attributes on the product class and returning an empty array if not. It also has the _product_node_is_product --> _product_is_product() fix applied.

Good looking code otherwise, seems to do the trick.

Cheers,

Chris

AttachmentSize
uc_attribute.tar 8.5 KB
mikeloyst's picture
Offline
Joined: 02/14/2010
Juice: 6
File attachment broken

Hi there,

Would you be able to re-upload the patch? Cannot download the file, returns a 404 error.

Thanks,
Michael Loyst

equinox11's picture
Offline
Joined: 02/16/2010
Juice: 5
uc_product_node_is_product

If anyone else is getting the white screen of death when attempting an import, try replacing any instance of uc_product_node_is_product with uc_product_is_product. Hope that helps someone. Smiling

kevster's picture
Offline
Joined: 09/03/2008
Juice: 19
corrput tar file

When I download Im getting a corrupt file when I try and unpack - any chance of checking/reuploading please? Thx in advance

Thx equinox11 for the above fix..

dom_b's picture
Offline
Joined: 02/26/2010
Juice: 72
Re: uc_product_node_is_product

Looks like this doesn't actually import downloads from the features page as I had hoped! Any chance of getting Features added to products as well? THanks!

CpILL's picture
Offline
Early adopter... addicted to alphas.Getting busy with the Ubercode.
Joined: 08/08/2007
Juice: 550
sorry mate, no time or

sorry mate,
no time or incentive. Shouldn't be too hard I guess. Hassle the guy who wrote the Features... feature Eye-wink

freedjack's picture
Offline
Joined: 03/10/2010
Juice: 5
Re: Stock levels + Attributes CSV Import

Hi ive got this nearly working thanks to the tip from equinox11. However with attributes i only ever get 1 adjustment imported, the last one for each group of skus.
Any one got any ideas why this might be ive attached my csv so you can see what im doing.
Cheers

AttachmentSize
tester4.csv_.txt 1.23 KB
CpILL's picture
Offline
Early adopter... addicted to alphas.Getting busy with the Ubercode.
Joined: 08/08/2007
Juice: 550
Re: Re: Stock levels + Attributes CSV Import

try the Version 4 I just uploaded. Might work now.

freedjack's picture
Offline
Joined: 03/10/2010
Juice: 5
Re: Stock levels + Attributes CSV Import

It works. Ive only tried it with one test product with three attributes and stock but appears to work perfectly.
I believe this is currently the best solution for ubercart product importing.
Great work

CpILL's picture
Offline
Early adopter... addicted to alphas.Getting busy with the Ubercode.
Joined: 08/08/2007
Juice: 550
Thanks mate

Have been working on it for months and testing with a large complex data set. I nailed the last bug this week and should be pretty spot on, apart from having to delete that .txt file manually each time.

I'm going to start my own branch of the node_import module (as the own doesn't respond to emails anymore) so I can repeat imports with CRON (for stock updates from 3rd party software). Then I'll also have that file removed at the start/end of each import. Should happen in the next couple of month (no promises Eye-wink

swilsondesign's picture
Offline
Joined: 03/01/2010
Juice: 35
Hi, Could you re-include

Hi,

Could you re-include attribute-example.csv in the zip archive please. It appears to be missing.

Thanks,

Steve

CpILL's picture
Offline
Early adopter... addicted to alphas.Getting busy with the Ubercode.
Joined: 08/08/2007
Juice: 550
opps

Sorry, examples are back Smiling

swilsondesign's picture
Offline
Joined: 03/01/2010
Juice: 35
Thanks S

Thanks Smiling S

nanopatch's picture
Offline
Joined: 03/31/2010
Juice: 12
error

CpILL, I get an error after pressing next on page 6 of the node import wizard.

I used a CSV that used to work, only the stock levels were unmatchable. So this addition would have been the solution I was looking for.

Everything went ok until I came at step 6.
I am using:
Drupal 6.16
Ubercart 2.2
Node Import 6.x-1.x-dev

Fatal error: Call to undefined function uc_attribute_get_product_by_sku() in /home/*****/public_html/site/sites/all/modules/node_import/supported/ubercart/uc_stock.inc on line 110

Please can you provide me a solution!

lostchord's picture
Offline
Joined: 03/06/2010
Juice: 15
It sure did!

http://www.ubercart.org/comment/49959

Yes...just got me onto the next step of my first attempt to import products Smiling

Many thanks!

CpILL's picture
Offline
Early adopter... addicted to alphas.Getting busy with the Ubercode.
Joined: 08/08/2007
Juice: 550
Re: error

Ya, I wasn't testing without the attributes module. v5 should fix this problem (not that I've tested it, I just copied the function over and renamed it for stock.inc).

Protean's picture
Offline
Joined: 04/30/2010
Juice: 5
Hi! There is a problem with

Hi!

There is a problem with node_import_supported_v5 if we don't use attributes.

The code in uc_stock_node_import_postprocess of uc_stock.inc:

if(module_exists('uc_attribute') && uc_attribute_has($node_type)) $data['sku'] = $values['sub_sku'];

if ($data['sku'] && $data['nid'] && !$preview) { ... }
else drupal_set_message('Stock data: '.print_r($data, true));

If we don't use uc_attribute module, then ($data['sku'] == null) and no stock values will be imported at all.

Protean's picture
Offline
Joined: 04/30/2010
Juice: 5
Re: Stock levels + Attributes CSV Import

Maybe I wrong, but code in uc_stock_node_import_postprocess

// NID is a PK in the {uc_product_stock} table.
if(!isset($values['nid']))
$data['nid'] = uc_stock_node_import_get_product_by_sku($values['model']);

means: if (isset($values['nid'])) then $data['nid'] = null and no stock or attribute values will be updated.

earle.b's picture
Offline
Joined: 05/06/2010
Juice: 17
No attributes showing

In Step 4 I do not get any options to map attributes. I am only getting the option to map Sub-SKU.

If I complete the rest of the steps it imports the products.

I have created Attributes with the same names as the CSV file and I have a long list of options already created.

Should I delete the Attributes and Options I already have created?

Any help would be greatly appreciated.

Thanks

Reichert's picture
Offline
Joined: 06/19/2010
Juice: 4
Bug in uc_stock.inc

There is a bug in uc_stock.inc. The "Active" value is not correctly parsed because of this line:

106:  $data['active'] = ($data[$key]) ? 1 : 0;        // just make sure.

The last value of $key is actually "Threshold" from the foreach loop at line 103, so the "Active" field ends up adopting the value for "Threshold". The fix:

106:  $data['active'] = ($data['active']) ? 1 : 0;        // just make sure.

sikocan's picture
Offline
Joined: 05/31/2010
Juice: 14
Updates & Stock Level & Attributes not working

Hi there,

I currently use node_import-patched-by-zeezhao.tgz located on http://drupal.org/node/349408#comment-2260858

It works perfectly and I can create new products and it also updates all fields as necessary.

I tried this module, I uploaded uc_stock.inc and attribute.inc files, however, it creates problems.

I can create new products fine.

But I can't update any fields as I was able to before.

The 3 options do appear, Active, Stock & Threshold. I have created values for these columns, once the import process finishes, no stock level gets created. However products are active.

Any ideas why products do not update or stock levels get created? I'm very frustrated as I can't seem to figure out.

I've tried creating a csv file for just Stock levels like the example in this module's folder, but no luck.

Do I need to select an option or change a setting etc... to use uc_stock.inc?

AttachmentSize
Apple.zip 453 bytes
thiokol's picture
Offline
Joined: 05/07/2009
Juice: 69
Re: Stock levels + Attributes CSV Import

"On Step 4 of the Node Import process you should see a group of fields titled "Product Attributes", here you should be able to map all the attributes for the chosen Product Class/Type to columns in you CSV as well as choose which column will be used foe the Sub. SKU as discussed above."

Doesnt work, these fields are not available, whether the attributes and options are all created beforehand or not, they're just not there, only the sub sku can be mapped.

Stock level also does not import, and theres not really much can go wrong there really :|

No idea how anyone has got this working, unless you're using different versions of node import and ubercart or something.

j0rd's picture
Offline
Getting busy with the Ubercode.
Joined: 07/16/2008
Juice: 453
Node Import and Ubercart File Download Integration

I've extended node_import_supported_v5.zip to add support for importing "Ubercart File Downloads". The only modification between my version and v5 is that I've added this patch to resolve an issue with node_import and PHP 5.3 http://drupal.org/node/763036.

Additionally I would recommend this patch for uc_product ( http://drupal.org/node/809318 ):
http://drupal.org/files/issues/ubercart_uc_product_feature_save-6.x-2.2-... as with out it, you will have much grief with duplicates when editing your File Downloads.

I've also included the additional doxygen generated API docs, so that hopefully others will be able to get a handle on the API and contribute improvements.

It would be best if we could get these ubercart extensions added into the core node_import, so that others will find and use it. I think in order for that to happen though, cpILL's code will need to properly provide "$values['nid']" in postprocess functions. Right now that'll mess up any other contrib modules which depend on that functionality.

--
Ubercart module development

AttachmentSize
node_import-ubercart-extensions_v6.tar.gz 164.45 KB
dom_b's picture
Offline
Joined: 02/26/2010
Juice: 72
Re: Node Import and Ubercart File Download Integration

Thanks this is perfect! I've been messing with a mixture of sell_cck_fields, views etc and now you've rendered all my work useless Smiling

This should be rolled in to node_import straight away.

j0rd's picture
Offline
Getting busy with the Ubercode.
Joined: 07/16/2008
Juice: 453
Re: Re: Node Import and Ubercart File Download Integration

I agree it should be merged into node_import, but I think someone needs to look into the issue where $values['nid'] gets removed when a product with multiple SKU's is imported. Otherwise I think this code will break other node_import features.

Someone correct me if I'm wrong.

joaogarin's picture
Offline
Joined: 07/14/2010
Juice: 21
Importing from class content type

Hello i am trying to import products with attributes and stock and i got to the point where my attributes where not appearing in step 4 of the import process. I have now created a product class for my products and added atrributes to it and it started rendering my attributes (color etc..).

I have a problem now that the sku,dimensions,width etc are not appearing to match with my csv columns...

Any idea on how to make them work for a content type that not the default "product" from ubercart ? To work on my product class that is..

Thanks in advance,
Joao Garin

joaogarin's picture
Offline
Joined: 07/14/2010
Juice: 21
Import product class

I have managed to fix my problem for now by telling in the uc_product.inc file to allow other content types than "product" by changing the code :

function uc_product_node_is_product($type) {
if (strpos($type, 'product') === 0) {
return TRUE;
}
return FALSE;
}

to

function uc_product_node_is_product($type) {
if (strpos($type, 'product') === 0 || strpos($type, 'jewelry') === 0) {
return TRUE;
}
return FALSE;
}

This is kind of a bad solution since i may want to create other product classes and i would allways have to edit this file for the Product information appear on the import..

If anyone know of a better solution for my problem would appreciate it.

Thanks,
Joao Garin

turtlekid86's picture
Offline
Joined: 07/26/2010
Juice: 5
Pickup Address import

Hey I'm trying to add an import option for the product pickup address. Does any one have a working example?

I'm not exactly sure how to add it myself, but what I did was to mimic how the uc_stock.inc looks and tweaked it to become uc_location.inc.

I couldn't find any other instances of "stock" throughout the import node module, so I assume all you have to do to make it work is add the .inc file.

The location fields aren't showing up, though.

Let me know what I'm doing wrong. Attached is the .inc file I created. This inc file only has the first name, last name, and company. I plan on adding the other fields once I figure out how to get these to work.

Please let me know if anyone can help. Its sort of urgent.

Thank you.

AttachmentSize
uc_location.inc_.zip 1.74 KB
j0rd's picture
Offline
Getting busy with the Ubercode.
Joined: 07/16/2008
Juice: 453
Re: Pickup Address import

Check out attribute and stock. They simply dump the information into the database. Your .inc will simply have to do the same unless a "update" hook puts it in there for you.

Not sure how else to explain it, but keep trying and you'll get it.

Make sure you install "devel module" and use "dpm($node)" in hook_nodeapi. Stick that into the $op = "insert" and "update" and put some information into the location area and save the node. This should give you information on how to format the information for node_import. Otherwise you'll need to stick it into the database manually...but I don't think this is the case as I think ubercart will do it for you if you format it properly.

Not sure if that will make sense to you, but try it out and hopefully you'll get it to work.

turtlekid86's picture
Offline
Joined: 07/26/2010
Juice: 5
Thanks

Awesome! Thanks for the tips. I think I figured it out. I just needed to rename all the hooks. The filename needed to be uc_shipping.inc and the hook functions needed to have "uc_shipping" instead of "stock"

myregistration's picture
Offline
Joined: 05/26/2010
Juice: 18
Why are attibutes imported for product classes only?

Why are attributes imported via Node Import for product classes only and not for regular products? Thanks!

j0rd's picture
Offline
Getting busy with the Ubercode.
Joined: 07/16/2008
Juice: 453
Re: Why are attibutes imported for product classes only?

@myregistration: I think that's just the way it was created, so that he could tell which attributes were to be imported.

In my opinion (and I assume yours) it should be re-factored to work with default product class.

Someone just needs to do the work.

xl_cheese's picture
Offline
Joined: 04/01/2010
Juice: 270
I'm not seeing anything for attributes.

I'm not seeing my color or size attributes I have in my csv file. I'm mapping the sub sku, but I'm not getting any attributes created.

In this screenshot, is this where I'm supposed to see options to configure attributes?

AttachmentSize
Screenshot.jpg 42.16 KB
xl_cheese's picture
Offline
Joined: 04/01/2010
Juice: 270
Re: I'm not seeing anything for attributes.

I finally got it to import with attributes, but it does not seem to work with the other modules I have such as Ajax Attribute Calculations.

j0rd's picture
Offline
Getting busy with the Ubercode.
Joined: 07/16/2008
Juice: 453
Re: Re: I'm not seeing anything for attributes.

It should work with Ajax Attribute Calculations, providing that module does not have any additional tables that need to be populated. I don't believe it does. From my experience with the attribute import, it seemed to populate all the appropriate attribute/option/stock tables...so you should be good to go.

Providing Ajax Attribute Calculations doesn't have any additional table, it would suspect that it's just not properly configured.

If you can hunt down the exact issue, I'm sure someone could assist you with resolving it.

xl_cheese's picture
Offline
Joined: 04/01/2010
Juice: 270
Re: Re: Re: I'm not seeing anything for attributes.

I'll keep digging into it, but I'm pretty novice at drupal programming.

Here's a product that was created with import. All the attributes were created and the correct sku numbers are in place. But when switching attributes on the product page ajax is not ajaxing.

http://www.pinkgorillacycles.com/hjc-cs-2n-metallics

Here's a product I created manually and ajax works fine. I also have a java script stock checker that doesn't work with imported nodes as well.

http://www.pinkgorillacycles.com/apparel/helmets/hjc-cs-r1-solids

faite's picture
Offline
Joined: 08/05/2010
Juice: 6
Importing Attribute Prices

Sorry if this is something that I am just not understanding, but how do you import the attributes pricing in addition to the attribute option name. What I mean in my case is that I am trying to price wine by the case and by the bottle and want to import the attribute options of 'Bottle' and 'Case' and Also import the price of either that Bottle of Case. I am leaving the main price 0.00 so that the two Attribute options act as the final price. Sorry if this is confusing so ill try to sum up...

Can this module import the Attribute pricing adjustments as well as the pricing options and if so how?

j0rd's picture
Offline
Getting busy with the Ubercode.
Joined: 07/16/2008
Juice: 453
Re: Re: Re: Re: I'm not seeing anything for attributes.

links don't work. "403 permission denied" errors.

xl_cheese's picture
Offline
Joined: 04/01/2010
Juice: 270
Re: Re: Re: Re: Re: I'm not seeing anything for attributes.

I may have inadvertently blocked your ip. My log file shows all these phpadmin calls coming from China and various other places so I blocked them.

artturi's picture
Offline
Joined: 08/16/2010
Juice: 18
same problem

Hello,

I have the same problem on step 4 : only subsku shows up. Could you please tell us how you solved this issue ?

I use drupal 6.19 with node_import 6.x-1.x-dev

Regards,

Mikael

xl_cheese's picture
Offline
Joined: 04/01/2010
Juice: 270
Re: same problem

You need to go into store -> products -> manage classes and add attributes to the product classes there. Once you add an attribute to the product the options for the attributes will be created during node import.

artturi's picture
Offline
Joined: 08/16/2010
Juice: 18
Re: Re: same problem

Thank you, works for me too ! Smiling

faite's picture
Offline
Joined: 08/05/2010
Juice: 6
Maybe I have wrong terminology

I am thinking that I am not getting my terminology right as I think what I am looking for must exist in this patch somewhere, but I am at a loss as to how or where.

Basically I can import Attribute Options successfully, but I cannot figure out for the life of me how to import the ATTRIBUTE OPTION PRICES . Alternatives SKU's work like a charm as-well.

Would the attribute option pricing just be the regular price field on the options import line (for instance with the default example if I changed the price on the BLUE shirts line to $5.00 would that change the ATTRIBUTE PRICE OPTION for the blue shirt to be $5.00)?

I feel like this is so simple that it isnt even worth mentioning in the description, but I am sure that there are others encountering this issue.

Thanks in Advance for any insights! You all rock the Caspar!

artturi's picture
Offline
Joined: 08/16/2010
Juice: 18
Re: Maybe I have wrong terminology

Yes, I second the question.

Ideally, it would be great if there could be a specific price per sub sku.

But even without that, I'm surprised to see the imported product's options all have their prices set to zero (I've configured the prices on the options in the "store admin-> Attribute" and "store admin -> products -> manage classes".

Could something be wrong with my setup ?

Regards,
Mikael

Florent's picture
Offline
Joined: 08/16/2010
Juice: 30
Thank U Jord ! small

Thank U Jord !

small question? do we have to cut and paste all the node import folder or can we just copy only supported/ubercart/ Files?

Florent

j0rd's picture
Offline
Getting busy with the Ubercode.
Joined: 07/16/2008
Juice: 453
Re: Thank U Jord ! small

I believe you just need my additional file. Nothing else in the module changed.

Do a diff to see if I'm lying though, but I think you just need my file.

Florent's picture
Offline
Joined: 08/16/2010
Juice: 30
Thanks for you answer.

Your script work fine to add a file ( thank again) but i'm lost for the second step.

if i add the file without any attribute. it's work, no problem.! But if i want to add attribute, i'm lost. In my case : i want to add file format. pdf or rtf choise.

so if user select PDF FORMAT (select list ) ....he will donwload a file.pdf,....

Node Import Step 4/8
Product Attributes
Select your format(rtf, pdf,...)

Sub-SKU
The SKU used for each combination of attributes. Product SKU will be used for grouping them together.

Question with your script, i see this new options (above), i have some bad comprehension with the jonction with node import and my csv. How to fill the import to give the two files?

Thanks for your help.

Florent

Florent's picture
Offline
Joined: 08/16/2010
Juice: 30
Hi Jord, Again me (, is your

Hi Jord,

Again me Shocked(, is your file download can work with sub sku for file?

SKU1= default.txt (with option for any)
-Sub SKU 1= fichier1.txt
-Sub SKU 2= fichier2.txt

Regards,
Florent

j0rd's picture
Offline
Getting busy with the Ubercode.
Joined: 07/16/2008
Juice: 453
Re: Hi Jord, Again me (, is your

SKU is not the file upload. SKU stands for "Stock Keeping Unit" and is a unique identifier for your product.

http://en.wikipedia.org/wiki/Stock-keeping_unit

Florent's picture
Offline
Joined: 08/16/2010
Juice: 30
Jord,

Yes, i understand the sku ( similar to upc, ean,..)

In my case i create a default SKU A001 with a default file donwload (i can import it with your addon) but if :

option
i created two options "select format".

adjustments
i created 2 SKU (sub SKU)
File download SKU: A001-PDF
File download SKU: A001-RTF

Features
I inked the subSKU with one file.
File download SKU: A001-RTF > File: A001.RTF
File download SKU: A001-PDF > File: A001-PDF

So that let us the ability to download selected file. I don't see (or understand) how i could import this informations with node import csv ?

Regards,
Florent