X-Cart: shopping cart software

X-Cart forums (https://forum.x-cart.com/index.php)
-   Dev Questions (https://forum.x-cart.com/forumdisplay.php?f=20)
-   -   My solution to product imports using column names (https://forum.x-cart.com/showthread.php?t=16870)

Don L 09-26-2005 07:10 AM

My solution to product imports using column names
 
My Problem:
My product database has some extra fields not used by x-cart, and lacks some fields that are used by x-cart. The "Get column names from the first row of the CSV file" option was not working for me and I received an error complaining about the format of my field name header. It's not convenient for me to create a separate feed just for xcart because I have other needs for the feed, and prefer working with the same file for all applications.

My feed's layout (\t used to indicate a tab; truncated to simplify example):
product \t desc \t productcode \t field_not_used_by_xcart \t price

X-cart's import facility seems to be extremely picky, and doesn't like the feed's format. I commented out the section of the code that checks the header for correct column names. I believe their code would require you to have every column included and none extra, which is why it was killing my feed. Since the code is not checking your columns for correctness, it's important that you do so! Here's the code to comment out:

Code:

/*
                if (!is_array($first_row) || count(array_diff($first_row, $fields_to_compare)) > 0) {
                        #
                        # Error: cvs header error (wrong list of fields)
                        #
                        $top_message["content"] = func_get_langvar_by_name("msg_err_csv_header");
                        $top_message["type"] = "E";

                        if ($import_file["uploaded"]) @unlink($import_file["location"]);
                        x_session_unregister("import_file");
                       
                        func_header_location("import.php");
                }
*/


the /* ... */ pair is how you comment out the code.

Creating the header:
For nulls, don't actually type NULL, just leave a blank field. For example, my header for my example looks like

product \t desc \t productcode \t \t price

Notice I just left an extra tab where my extra field was.

This worked fine for me, but as with all code-hacks, I'd be careful using this on a live site. Test it out on a test install first if you can.

balinor 10-11-2005 08:09 AM

Moving to Custom Mods...or else this will just get lost in the Product Management forum. Thanks for contributing!


All times are GMT -8. The time now is 02:50 AM.

Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.