Post by aaron1988 » Sun Mar 20, 2011 7:30 pm

Hi wondered if someone could help me in CSV Import Pro i have customised it so much for additional images:

so instead of it looking like this:

Code: Select all

if (isset($data['product_image'])) {
			foreach ($data['product_image'] as $image) {
        		$this->db->query("INSERT INTO " . DB_PREFIX . "product_image SET product_id = '" . (int)$product_id . "', image = '" . $this->db->escape($image) . "'");
			}
		}
it looks like: - reason i have updated it to look like this as my additional images columns need to have .jpg at the end :). but i have an issue for all the blank fields in the additional images it add no_image.jpg which but i have realised i need skip the rows if they are empty? so does any one have any ideas of how to skip the rows in CSV please?

Code: Select all

if (isset($data['product_image'])) {
			foreach ($data['product_image'] as $image) {

			$image = $image.".jpg";
			$image = str_replace (" ", "", $image);
			
			$filename='%2Fhome%2Fpurchase%2Fpublic_html%2Ffancydresscostumesonline%26%2346%3Bco%26%2346%3Buk%2Fimage%2F'. $image;

			if (file_exists($filename)) {
			$this->db->query("INSERT INTO " . DB_PREFIX . "product_image SET product_id = '" . (int)$product_id . "', image = '" . $this->db->escape($image) . "'");	
			} else {
				$this->db->query("INSERT INTO " . DB_PREFIX . "product_image SET product_id = '" . (int)$product_id . "', image = 'no_image.jpg'");
			}
			
			}
		}
Hope someone can help me.

Regards,
Aaron
Last edited by aaron1988 on Tue Apr 05, 2011 1:00 am, edited 3 times in total.

Active Member

Posts

Joined
Thu Jan 27, 2011 10:03 am

Post by traceofwind » Mon Mar 21, 2011 2:02 am

Hi aaron1988,

Are you saying that CSV Import PRO *instead of skipping blank [Additional image] cells inserts the "no_image.jpg" value*(?) if so, then I too may have encountered a similar problem.

I have imported several hundred products, some of which had intentionally blank [Additional image] values which I presumed CSV Import PRO would skip; but it seems that every product imported has an 'additional image' on the website, which I hadn't until now investigated.

Interim fix;
For now, I propose that you, like I, break your CSV down into two imports; (1) with additional images and (2) without additional images. On the second import, do not specify [Additional images] on the import process and your products will be added correctly, with no 'blank' (no_image.jpg) additional images.

It would be nice if this could be fixed.

Regards,

Gary

(edit)
PS, I suggest you change 'blank rows' to blank cells -unless I am mistaken, you want CSVIP to skip 'cells' rather than 'rows' -this confused me when I first read your post! ;)

New member

Posts

Joined
Fri Jul 02, 2010 6:37 am

Post by aaron1988 » Mon Mar 21, 2011 2:29 am

Yes that is correct no_image.jpg is used is no additional image is in that cell etc but i need it to skip those ;).

I would do what you suggested except we are using an external CSV file :) and we dont really want to download it and break it down because as soon as we open CSV it breaks the barcode column lol and we have way too many products to do that lol.

Regards,
Aaron

Active Member

Posts

Joined
Thu Jan 27, 2011 10:03 am

Post by traceofwind » Mon Mar 21, 2011 2:55 am

Hi Aaron,

Hopefully the author will address the situation, it is such a wonderful extension -but with just a few tweaks it could be perfect!

For your case, I think you will have to persist with breaking down the CSV into two separate files -what program are using to work with the CSV file? It shouldn't be that hard for you to make the necessary changes? It saved me a lot of work fixing this with 2 imports rather than hacking the extension code -but then I am not a PHP wizard, ASP classic all the way for me lol! ;)

Best of luck, regards
Gary

New member

Posts

Joined
Fri Jul 02, 2010 6:37 am

Post by aaron1988 » Mon Mar 21, 2011 3:27 am

Yes hehe qwell i have already tweaked it to Add Size and Gender :) fields hehe and the code i posted here i added with a bit of friends help lmao as i not that good at php i am learning.

Hopefully if justin replies to this or anyone else to this matter :) it would be wonderful hehe as i no it can be done using a if empty statement lol and something but i am clueless.

Aaron

Active Member

Posts

Joined
Thu Jan 27, 2011 10:03 am

Post by justinv » Wed Mar 23, 2011 8:04 am

Hi guys, sorry I didn't see this thread until another CSV Import PRO user pointed it out.

Here is a fix to the product images - it will ignore them if the field is empty:

Replace this line in admin/controller/tool/csv_import.php:

Code: Select all

if (isset($raw_prod[$this->field_names['product_image'][$i]])) {
With this:

Code: Select all

if (isset($raw_prod[$this->field_names['product_image'][$i]]) && $raw_prod[$this->field_names['product_image'][$i]] != '') {
I will roll this change into the latest version when I next publish changes to the module. I may have to make a similar change to categories/subcategories I suspect.

Thanks!

Documentation: OpenCart User Guide
Mods: Total Import PRO | CSV Import PRO | Ecom Tracking | Any Feed | Autosuggest | OpenCart CDN
Image


Active Member

Posts

Joined
Tue Oct 12, 2010 1:24 pm

Post by aaron1988 » Wed Mar 23, 2011 4:26 pm

Hi Justin, that is no worries :) and cheers for the update i am going to test it now and come back with the outcome :)

Regards,
Aaron

Active Member

Posts

Joined
Thu Jan 27, 2011 10:03 am

Post by aaron1988 » Wed Mar 23, 2011 4:44 pm

Hi justin in my additional image columns it just has: say the prodoct number instead of 6155.jpg so i edited this code in admin/model/catalog/product.php:

Code: Select all

if (isset($data['product_image'])) {
			foreach ($data['product_image'] as $image) {

			$image = $image.".jpg";
			$image = str_replace (" ", "", $image);
			
			$this->db->query("INSERT INTO " . DB_PREFIX . "product_image SET product_id = '" . (int)$product_id . "', image = '" . $this->db->escape($image) . "'");	
			
			}
		}
so it adds a .jpg at the end of the product code when inserted for the additional images.

and then i went into your code csv_import.php and change the line you said but it still inserts the columns which are empty for some reason.

EDIT: so in csv_import.php i edited this:

import to csv:

Code: Select all

//Additional Images
				for ($i=0; $i<sizeof($this->field_names['product_image']); $i++) {
					if (isset($raw_prod[$this->field_names['product_image'][$i]]) && $raw_prod[$this->field_names['product_image'][$i]] != '') {
						$product['product_image'][] = $raw_prod[$this->field_names['product_image'][$i]];
					}
				}
and update the product:

Code: Select all

				//Additional Images
				$product['product_image'] = array();
				for ($i=0; $i<sizeof($this->field_names['product_image']); $i++) {
					if (isset($raw_prod[$this->field_names['product_image'][$i]]) && $raw_prod[$this->field_names['product_image'][$i]] != '') {
						$product['product_image'][] = $raw_prod[$this->field_names['product_image'][$i]];
					}
				}

Regards,
Aaron

Active Member

Posts

Joined
Thu Jan 27, 2011 10:03 am

Post by aaron1988 » Fri Mar 25, 2011 4:20 pm

Anybody have any ideas why this is not working :( as its really bugging me

EDIT: i have renamed the thread as instead of skipping the rows, how could i do it so once in the database all the fields which only have .jpg in with no numbers it REMOVES THOSE fields from the database as i think that would be an easier and lazy way but if someone could help me with the code i be much appreciated.

Regards.
Aaron

Active Member

Posts

Joined
Thu Jan 27, 2011 10:03 am

Post by aaron1988 » Thu Apr 07, 2011 10:35 pm

Hi this post has been resolved now :) the code below is how i resolved it.

Code: Select all

if (isset($data['product_image'])) {
			foreach ($data['product_image'] as $image) {
		
				$image = $image.".jpg";
				$image = str_replace (" ", "", $image);
		
				$this->db->query("INSERT INTO " . DB_PREFIX . "product_image SET product_id = '" . (int)$product_id . "', image = '" . $this->db->escape($image) . "'");
		}
	
				$this->db->query("DELETE FROM " . DB_PREFIX . "product_image WHERE image='.jpg'");
		}
what i did was just add:

Code: Select all

$this->db->query("DELETE FROM " . DB_PREFIX . "product_image WHERE image='.jpg'");
Thanks
Aaron

Active Member

Posts

Joined
Thu Jan 27, 2011 10:03 am
Who is online

Users browsing this forum: Bing [Bot] and 1 guest