Forums / All Other Contributions/Addons / Here's a quick tutorial on how to add fields to easypopulate v1.2.5.4 or 1.2.5.5

Here's a quick tutorial on how to add fields to easypopulate v1.2.5.4 or 1.2.5.5

Started by lankeeyankee on 21 Dec 2008, 6:31 AM · Views: 83,717

Results 1 to 20 of 318
21 Dec 2008, 6:31 AM
#1
lankeeyankee avatar

lankeeyankee

Totally Zenned

Join Date:
Jan 2007
Posts:
1,514
Plugin Contributions:
1

Here's a quick tutorial on how to add fields to easypopulate v1.2.5.4 or 1.2.5.5

Warning: The supplied file is for showing examples only, do not use it in your store since it will cause errors if you don't have all of the add-on mods installed that this file includes. Make the changes shown here in your copy of easypopulate.php!

This is how you do it for easy populate v1.2.5.4 or 1.2.5.5, it's similar for other versions but there might be more or fewer additions of fields as described below.

Find the name of the field that you would like to add if you don't already know it. To do this, go to phpMyAdmin, click on the zen_products table, on the Structure tab you will see all of the fields that easy populate is able to use. If you don't use phpMyAdmin you can query the structure of the products table.

Now that you know what field names you need, open your copy of admin/easypoplulate.php in a text editor and search for v_products_weight. It will appear 7 times throughout this file. It's part of an array of fields that will be used, you can see that all of the one starting with v_ are in the database table zen_products.

The order of the fields in that array correspond to where in the csv file the field will appear. So copy the entire line including v_products_weight and paste it where you want in the array. Make sure you copy everything, if you forget a comma you'll cause an error. Replace v_products_weight to v_yourfield (the field name using underscores instead of spaces), as well as p.products_weight to p.yourfield when it's in the line(3 of the 7 lines).

After your first 5 alterations (around line 388, 455, 598, 1286, and 1434) you will come to the lines around line 1925. They look different, but still just copy and paste like the other 5 lines.

On around line 1959 copy only this part of the line:

'", products_weight="'.zen_db_input($v_products_weight) .

and paste it where you want, changing products_weight and v_products_weight. That is your last alteration. Save the file and upload to the admin folder on your server.

Navigate to easy populate in the tools drop down in the admin panel. Download a complete tab-delimited file and open in your spreadsheet app to see the new fields that you added.

You'll notice that I have added map_enabled to the included file. In the product creation page in the admin this is a radio button, so you can check boxes and select radio buttons, 0 is off and 1 is on.

The mods that are used in the included file are msrp, map price, auction sites attributes (ASA), and dual pricing.

The version that the included admin/easypopulate file is from is 1.2.5.4


Zen Cart and it's community are the best!!

2 Jan 2009, 1:13 AM
#2
artmuns avatar

artmuns

New Zenner

Join Date:
Dec 2008
Posts:
11
Plugin Contributions:
0

Re: Here's a quick tutorial on how to add fields to easypopulate v1.2.5.4 or 1.2.5.5

Hi,

Getting the below when trying to import after modifying the various lines per your instruction. The first record will update correctly but the others will not (the subsequent records were new items). I have triple checked the mods and they are correct. Downloading the file gives me the correct columns I want.
They are "products_sort_order" and "default_subcontractor" (from another mod). Tried it also with just "products_sort_order"
and same problem. Below is the error log.

Thanks for any help!

Art

MySQL error 1136: Column count doesn't match value count at row 1
When executing:
INSERT INTO zen_products (
products_image,
products_model,
products_price,
products_status,
products_last_modified,
products_date_added,
products_date_available,
products_tax_class_id,
products_weight,
products_quantity,
manufacturers_id)
VALUES (
'no_picture.gif','3R1919-14B-CW',
'349.99',
'1',
CURRENT_TIMESTAMP,
"2009-01-09 13:59",
NULL,
'1',
'28',
'20',
'',
'0',
'13')

2 Jan 2009, 1:28 AM
#3
artmuns avatar

artmuns

New Zenner

Join Date:
Dec 2008
Posts:
11
Plugin Contributions:
0

Re: Here's a quick tutorial on how to add fields to easypopulate v1.2.5.4 or 1.2.5.5

One more thing: This is the message after trying to update:

UPDATED! - Model: 3R1919-14B-EW | | Roto Mil-S | Empty - Pu | | | | | 279.99 | 23 | 10 | | | 1/9/2009 1 | 0 | SKB | Shockmount | SKB - Mil | Roto Cases | 3R Series | | | | Taxable Go | 1 |
ADD NEW PRODUCT FAILED! - Model: 3R1919-14B-CW - SQL error. Check Easy Populate error log in uploads directory
ADD NEW PRODUCT FAILED! - Model: 3R2216-15B-E - SQL error. Check Easy Populate error log in uploads directory
ADD NEW PRODUCT FAILED! - Model: 3R2217-10B-EW - SQL error. Check Easy Populate error log in uploads directory

Thanks again.

Art

2 Jan 2009, 7:15 PM
#4
lankeeyankee avatar

lankeeyankee

Totally Zenned

Join Date:
Jan 2007
Posts:
1,514
Plugin Contributions:
1

Re: Here's a quick tutorial on how to add fields to easypopulate v1.2.5.4 or 1.2.5.5

Art,

It looks like, in your first post, that there are more VALUES being added than there are rows in the table, thus the error message you received:

MySQL error 1136: Column count doesn't match value count

In your second post, it looks like you don't have EOREOR at the end of your row which is why the only one added is the first record, or since the column count and value count don't match it is throwing it off.

This often happens with a quote ending up throwing things off. If you look at the VALUES you were trying to insert you will see after the weight and quantity values there is a '', followed by '0', '13'. I'd look at the spreadsheet file to make sure all values are in their correct columns and that you have EOREOR at the end of each row.

Please let me know if you are still having trouble. You can post your spreadsheet file and your easypopulate file so I can see what's going on.


Zen Cart and it's community are the best!!

3 Jan 2009, 5:17 AM
#5
artmuns avatar

artmuns

New Zenner

Join Date:
Dec 2008
Posts:
11
Plugin Contributions:
0

Re: Here's a quick tutorial on how to add fields to easypopulate v1.2.5.4 or 1.2.5.5

Thanks for the reply lankeeyankee. Everything imports correctly if the product already exists. It only throws the error if it is a new product in the import file. I can take an existing product code that imports properly, change it by one character and when I try to import it again it throws that error.

Thanks for the help!

Art

5 Jan 2009, 6:48 PM
#6
swamyg1 avatar

swamyg1

Zen Follower

Join Date:
Dec 2008
Location:
San Fran
Posts:
382
Plugin Contributions:
0

Re: Here's a quick tutorial on how to add fields to easypopulate v1.2.5.4 or 1.2.5.5

I assume this would work for adding meta tags for products?

7 Jan 2009, 12:10 AM
#7
lankeeyankee avatar

lankeeyankee

Totally Zenned

Join Date:
Jan 2007
Posts:
1,514
Plugin Contributions:
1

Re: Here's a quick tutorial on how to add fields to easypopulate v1.2.5.4 or 1.2.5.5

swamyg1:

I assume this would work for adding meta tags for products?

most likely, yes. but I haven't tried it so I can't say for sure. You might have to insert new db queries for other db tables, but again I'm not sure. sorry that I can't help further!


Zen Cart and it's community are the best!!

7 Jan 2009, 12:11 AM
#8
lankeeyankee avatar

lankeeyankee

Totally Zenned

Join Date:
Jan 2007
Posts:
1,514
Plugin Contributions:
1

Re: Here's a quick tutorial on how to add fields to easypopulate v1.2.5.4 or 1.2.5.5

artmuns:

Thanks for the reply lankeeyankee. Everything imports correctly if the product already exists. It only throws the error if it is a new product in the import file. I can take an existing product code that imports properly, change it by one character and when I try to import it again it throws that error.

Thanks for the help!

Art

was this working correctly with the default EP install? Or just since you made the changes that I outlined?


Zen Cart and it's community are the best!!

8 Jan 2009, 10:43 PM
#9
phazei avatar

phazei

New Zenner

Join Date:
Jan 2009
Posts:
31
Plugin Contributions:
0

Re: Here's a quick tutorial on how to add fields to easypopulate v1.2.5.4 or 1.2.5.5

Just putting this here in case it's needed. I uploaded EP 1.2.5.5.csv to the Zen Cart Add-on section. Most everything is the same as the 1.2.5.4 version. If something isn't working right with the CSV's I'll try to help.

The CSV's created with this version will NOT work with the older versions. Just make sure your products are updated before upgrading. Then download a new backup.

Yes it works with 1.3.8, so did the 1.2.5.4 version.

I changed the temp directory to tempEP from temp so it's less generic and won't get in the way of any other temp directories. I also added a link to it and made the directory listing pretty. Remove the index.php file in the tempEP directory and replace it with an empty index.php if you don't want it to be seen.

For the majority of support, it works just the same as the 1.2.5.4/5 version so that thread should be useful to look at as well:
http://www.zen-cart.com/forum/showthread.php?t=34970

If you are using a MAC, then you need to uncomment one line in the main easypopulate.php file. This is because MACs use different end of line characters than win and linux. Same problem you have with text files.

9 Jan 2009, 12:13 PM
#10
patf avatar

patf

Zen Follower

Join Date:
May 2008
Posts:
200
Plugin Contributions:
0

Re: Here's a quick tutorial on how to add fields to easypopulate v1.2.5.4 or 1.2.5.5

Hi Phazei - did not realise you had started your own support thread so apologies for a double post.

trying to install the newer CSV version and got this error in the admin area ...

Fatal error: Call to undefined function: fputcsv() in xxxxxxxxxxxxxx(my root folder)( my admin folder )\easypopulate.php on line 1124

which is the line containing

//*******************************
		// PUT FILE IN TEMP DIR
		//*******************************
		$tmpfpath = DIR_FS_CATALOG . '' . $tempdir . "$EXPORT_TIME.$FILE_EXT";
		$fp = fopen( $tmpfpath, "w+");
		foreach ($filestring as $line) {
			fputcsv($fp, $line, $csv_deliminator, $csv_enclosure);
		}
		fclose($fp);
		$messageStack->add(sprintf(EASYPOPULATE_MSGSTACK_FILE_EXPORT_SUCCESS, $EXPORT_TIME.'.'.$FILE_EXT."    ", $tempdir), 'success');

Had a refresh and this error disappeared but my downloaded csv file only contains the following ..

<br /> <b>Fatal error</b>: Call to undefined function: fputcsv() in <b>xxxxxxxxxxxxxx\(my root folder)\( my admin folder )\easypopulate.php on line <b>1113</b><br />

Have checked and double checked all files are uploaded ( downloaded from contributions page here ) permissions are set on the tempEP folder and the tempEP folder is in my root folder ( even put it in the admin folder as well just in case )

I am reasonably certain I have done everything required but will glady hear I have not if it gets this sorted

Any ideas ??? :smile:

9 Jan 2009, 2:21 PM
#11
chadderuski avatar

chadderuski

Totally Zenned

Join Date:
Apr 2006
Location:
Dark Side of the Moon
Posts:
986
Plugin Contributions:
0

Re: Here's a quick tutorial on how to add fields to easypopulate v1.2.5.4 or 1.2.5.5

phazei,

2.0 is supposed to come with a db backup system built in, so it probably won't even need easy populate.

Actually, this is strictly a mysql backup tool for backing up and restoring your store.

Concerning Product Attribute: This feature does not work in 1.2.5.4. Langer fixed it and then marketed it as EP Advanced (along with a number of other features) for a cost. Personally, I've often found it easier to code a solution from scratch then to try and fix bad code.

Quantity Discounts: This does use it's own table. It's really quite simple although a bit of research needs to be done to identify each type of discount. Best to create a discount, then down load it to see how it's encoded. The code I uploaded handles all this.

-cj

10 Jan 2009, 2:38 AM
#12
phazei avatar

phazei

New Zenner

Join Date:
Jan 2009
Posts:
31
Plugin Contributions:
0

Re: Here's a quick tutorial on how to add fields to easypopulate v1.2.5.4 or 1.2.5.5

PatF:

Fatal error: Call to undefined function: fputcsv() in xxxxxxxxxxxxxx(my root folder)( my admin folder )\easypopulate.php on line 1124

Any ideas ??? :smile:

Unfortunately, I do have some ideas, but nothing that will help. Something I should have stated in my first post to this thread. I mentioned it in the other forum...

1.2.5.5.CSV will ONLY work with PHP > v5.1

fgetcsv existed in PHPv4, but fputcsv was only added in v5.1

There are custom fputcsv functions that could be put at the begining of the file that would make it work with PHP4.

I just did a quick google search and found this:

if (!function_exists('fputcsv')) {
	function fputcsv(&$handle, $fields = array(), $delimiter = ',', $enclosure = '"') {
		$str = '';
		$escape_char = '\\';
		foreach ($fields as $value) {
			settype($value, 'string');
			if (strpos($value, $delimiter) !== false ||
				strpos($value, $enclosure) !== false ||
				strpos($value, "\n") !== false ||
				strpos($value, "\r") !== false ||
				strpos($value, "  ") !== false ||
				strpos($value, ' ') !== false) {
				
				$str2 = $enclosure;
				$escaped = 0;
				$len = strlen($value);
				for ($i=0;$i<$len;$i++) {
					if ($value[$i] == $escape_char) {
						$escaped = 1;
					} else if (!$escaped && $value[$i] == $enclosure) {
						$str2 .= $enclosure;
					} else {
						$escaped = 0;
					}
					$str2 .= $value[$i];
				}
				$str2 .= $enclosure;
				$str .= $str2.$delimiter;
			} else {
				$str .= $value.$delimiter;
			}
		}
		$str = substr($str,0,-1);
		$str .= "\n";
		return fwrite($handle, $str);
	}
}

I don't know if it works, but I hope it does :D:D

chadderuski:

phazei,
Concerning Product Attribute: This feature does not work in 1.2.5.4. Langer fixed it and then marketed it as EP Advanced (along with a number of other features) for a cost. Personally, I've often found it easier to code a solution from scratch then to try and fix bad code.

Quantity Discounts: This does use it's own table. It's really quite simple although a bit of research needs to be done to identify each type of discount. Best to create a discount, then down load it to see how it's encoded. The code I uploaded handles all this.

-cj

Since most of the code for the attributes options is there it probably wouldn't be that hard to make it work.

I thought there was a column added to the db to get quantity discounts to work in that other version. I didn't want to add anything that would require someone to have to modify the db in any way. I wanted it to be as plug and play as possible.

10 Jan 2009, 3:44 PM
#13
patf avatar

patf

Zen Follower

Join Date:
May 2008
Posts:
200
Plugin Contributions:
0

Re: Here's a quick tutorial on how to add fields to easypopulate v1.2.5.4 or 1.2.5.5

That work around for PHP4 done the trick - many thanks :clap:

10 Jan 2009, 6:15 PM
#14
chadderuski avatar

chadderuski

Totally Zenned

Join Date:
Apr 2006
Location:
Dark Side of the Moon
Posts:
986
Plugin Contributions:
0

Re: Here's a quick tutorial on how to add fields to easypopulate v1.2.5.4 or 1.2.5.5

phazie,

Yes, there is some custom stuff in my code, but that is independant of quantity discounts. I wanted to be able to say how a product was priced, i.e. ea=each, cs=box, etc. So when you look at the page is says "3.95 ea". The basic quantity discounts is quite simple. I made a new download file type and added the code to automatically add discounts on upload.

Also, since zen 2.0 will be php 5.1 required, your csv mod will mature well with it. :)

I have not look closely at the Attributes code to see what is wrong. Partly cause I haven't had the need to use attributes like this. The 2.??? code at langer's modhole was his attempt to fix this, but it is quite buggy.
I would not trust the logic per say. The problem with attributes is that they can get quite complicated, and add language support and you have a LOT of columns.

I've been experimenting with your CSV version, chopping out a lot of the fluff. I like the trimmer code. It also runs much quicker. Nice to be able to open directly into Excel too!

If the code is mature enough, you may even get it included with 2.0! It's happened before, where a mod became core. This really is something that should have been in the core (IMOP). Just too important of a feature.

One Request: In your next code post, could you comment with your name "phazie" the sections you changed? There is so much errant garbage in the file that scanning through it for your work becomes cumbersome.

-cj

11 Jan 2009, 3:30 AM
#15
lstahlberg avatar

lstahlberg

New Zenner

Join Date:
Dec 2008
Posts:
8
Plugin Contributions:
0

Re: Here's a quick tutorial on how to add fields to easypopulate v1.2.5.4 or 1.2.5.5

I did not see there was a support thread started.

I have been having problems getting my file uploaded into the Langer's old version of Easy Pop. It is comma delineated, and then each text field is enclosed in quotes (since it may be "" inside of it).

Both OpenOffice Calc and Excel can parse this file without problems, so I assumed it would work with this upload tool, too. Can your update handle such a file?

11 Jan 2009, 4:52 AM
#16
lstahlberg avatar

lstahlberg

New Zenner

Join Date:
Dec 2008
Posts:
8
Plugin Contributions:
0

Re: Here's a quick tutorial on how to add fields to easypopulate v1.2.5.4 or 1.2.5.5

Okay... I just found the wiki on Easy Populate and I now realize that I made a very bad assumption.

I needed a tool that could upload a file, parse that file into columns, and assign an attribute to each column.

I thought that you could create any attribute you wanted on each product. My products have more attributes than just the ones in the required list.

Help? :unsure:

12 Jan 2009, 9:22 AM
#17
phazei avatar

phazei

New Zenner

Join Date:
Jan 2009
Posts:
31
Plugin Contributions:
0

Re: Here's a quick tutorial on how to add fields to easypopulate v1.2.5.4 or 1.2.5.5

I updated the version again. Added some stuff, cleaned up a bit of code. There is now a pretty file listing with import button next to each file.

lstahlberg:
:unsure: No clue, sorry.

chadderuski:
I started tagging things with phazei, but I've made so many changes all over that that failed quickly.

I suggest a program called WinMerge. It lets you compare 2 files and see the differences between them.

12 Jan 2009, 9:19 PM
#18
khopek avatar

khopek

Totally Zenned

Join Date:
Aug 2006
Location:
portlandish, oregon
Posts:
795
Plugin Contributions:
0

Re: Here's a quick tutorial on how to add fields to easypopulate v1.2.5.4 or 1.2.5.5

I'm getting the following error when trying to upload the CSV file:

Warning: array_flip() [function.array-flip]: The argument should be an array in xxxxx/public_html/store/admin/easypopulate.php on line 1245

12 Jan 2009, 11:33 PM
#19
phazei avatar

phazei

New Zenner

Join Date:
Jan 2009
Posts:
31
Plugin Contributions:
0

Re: Here's a quick tutorial on how to add fields to easypopulate v1.2.5.4 or 1.2.5.5

khopek:

I'm getting the following error when trying to upload the CSV file:

Warning: array_flip() [function.array-flip]: The argument should be an array in xxxxx/public_html/store/admin/easypopulate.php on line 1245

That doesn't reflect any line number in the file that uses array_flip. You must have modified it in some way.

The only place I see where that could be possible is by the while loop around line 1220.

Only if fgetcsv returns false on it's first call near line 1220 would you get that error. That reads the header line of the file.

You have to make sure it is a comma and quote deliminated file.

If you open it with a text editor, it should look like the one it exports. The first line needs to be identical.

I uploaded an updated one that should be approved soon. But it probably won't fix your problem.

Something you modified in easypopulate or someway you saved your csv is likely the problem.

13 Jan 2009, 1:08 AM
#20
khopek avatar

khopek

Totally Zenned

Join Date:
Aug 2006
Location:
portlandish, oregon
Posts:
795
Plugin Contributions:
0

Re: Here's a quick tutorial on how to add fields to easypopulate v1.2.5.4 or 1.2.5.5

I actually changed my PHP Engine to use PHP 5. It was set to use PHP 4, but when I changed it, I know longer got that error.