VM Import - Import of products images is broken

  • Posts: 193
  • Thank you received: 76
9 years 10 months ago #184933

-- HikaShop version -- : 2.3.5
-- Joomla version -- : 3.3.6

Version 2.3.5 introduced 2 new bugs in import from Virtuemart.

1. no image is assigned to product as column file_path in table #__rbl_hikashop_file is NULL for all records from this table.
2. massive number of duplicated records in table #__rbl_hikashop_file. There is 111506 records for 4552 images from VM.
Screenshot of distinct values attached.

Attachments:

Please Log in or Create an account to join the conversation.

  • Posts: 193
  • Thank you received: 76
9 years 10 months ago #184970

I was wrong. It's broken since Hikashop 2.3.3(oldest version I have), but it worked partially and duplication of rows was much lower.

In 2.3.3 column #__virtuemart_medias.file_title were used to identify product's image.
It worked partially for first product's image as long as user didn't change title of image.
By default title of first product's image is file name.

In 2.3.4 it was changed and main column to identify product's image is #__virtuemart_medias.file_meta and this exposed the bug as file_meta (alt for image) is empty by default.

At first, because of limit in SQL query on line 1254 , not all images are copied and referenced in $meta_files array.

Next because condition at lines 1280-1283 is flawed, $meta_files is always empty.
It should be replaced with:

$meta_files[] = $this->db->Quote($file_name);

The line 1348 is where bug #1 come from.
Because vmm.file_meta and $meta_files are always empty, empty value is inserted in column #__hikashop_file.file_path for every row.

Duplication of rows come from line 1358 as it insert all images of not yet imported products.

Method importDownloads() is also flawed.

Because of missing file_url column in select on line 1999, no file is copied, otherwise all images will be copied to "uploadsecurefolder" as in Hikashop 2.3.3.
Also column #___virtuemart_medias.file_is_product_image is not used in VM and instead there should be `file_is_downloadable`

Here is fixed SQL query on lines 1999-2004
			$sql = 'SELECT vmm.virtuemart_media_id,vmm.file_meta,vmm.vmm.file_meta,vmm.file_is_downloadable '.
			'FROM `'.$this->vmprefix.'virtuemart_products` vmp ' .
			"INNER JOIN `".$this->vmprefix."virtuemart_product_medias` AS vmpm ON vmp.virtuemart_product_id = vmpm.virtuemart_product_id " .
			"INNER JOIN `".$this->vmprefix."virtuemart_medias` vmm ON vmpm.virtuemart_media_id = vmm.virtuemart_media_id " .
			'WHERE vmm.virtuemart_media_id > '.$offset.
            ' AND vmm.file_is_downloadable = 1'.
			' ORDER BY vmm.virtuemart_media_id ASC LIMIT '.$count.';';

Here is fied code from lines 2067-2079
			$data = array(
				'file_name' => 'vmm.file_title',
				'file_description' => 'vmm.file_description',
				'file_path' => "SUBSTRING_INDEX(SUBSTRING_INDEX(vmm.file_url, '/', -1), '\\\\', -1)",
				'file_type' => "'file'",
				'file_ref_id' => 'hkp.hk_id'
			);
			$sql = 'INSERT IGNORE INTO `#__hikashop_file` (`'.implode('`,`',array_keys($data)).'`) '.
				'SELECT '.implode(',',$data).' FROM `'.$this->vmprefix.'virtuemart_products` vmp '.
				"INNER JOIN `".$this->vmprefix."virtuemart_product_medias` AS vmpm ON vmp.virtuemart_product_id = vmpm.virtuemart_product_id ".
				"INNER JOIN `".$this->vmprefix."virtuemart_medias` vmm ON vmpm.virtuemart_media_id = vmm.virtuemart_media_id " .
				'INNER JOIN `#__hikashop_vm_prod` AS hkp ON vmm.virtuemart_media_id = hkp.vm_id '.
				'WHERE vmm.virtuemart_media_id > '.$this->options->last_vm_pfile.
                                ' AND vmm.file_is_downloadable = 1'.';';

Anyway method importDownloads() will also suffer the row duplication and missing records as importProducts().

I was trying to fix it, but because of lack of time I had to comment it out and run queries and copy files by hand.

Hope it helps.

Please Log in or Create an account to join the conversation.

  • Posts: 26158
  • Thank you received: 4028
  • MODERATOR
9 years 9 months ago #191628

Hi,

We made few modifications in the VM import system for the next release.
We will see if we can improve more the import of the images to handle the different cases of VM2 (which change between versions and we have to handle them all...)
I test your patches but they didn't work good on my VM2 test store so I can't keep them ; but thanks for the report, we will continue to improve the VM import (I started a split in the import in order to have one import for VM1 and another for VM2 ; it will be easier to maintain).

Regards,


Jerome - Obsidev.com
HikaMarket & HikaSerial developer / HikaShop core dev team.

Also helping the HikaShop support team when having some time or couldn't sleep.
By the way, do not send me private message, use the "contact us" form instead.

Please Log in or Create an account to join the conversation.

Time to create page: 0.056 seconds
Powered by Kunena Forum