Export All Products - Import CSV Messes Up Shop

  • Posts: 31
  • Thank you received: 0
10 years 5 months ago #130315

-- url of the page with the problem -- : drc144k.com/jup
-- HikaShop version -- : 2.2.2
-- Joomla version -- : 2.5.14
-- PHP version -- : Tried on 5.2.x thru 5.4.x ... same problem.
-- Browser(s) name and version -- : Firefox, Chrome, Opera
-- Error-message(debug-mod must be tuned on) -- : NONE

The CSV export/import seemed great for the number of products and variants we'll need in our store. It wasn't working properly, so I dug into the problem a little deeper.

I export the entire product list. Then reimport the resulting CSV file with NO edits and it still screws up our store! The problem seems to be categories and/or characteristics with the same name messes up the import.

For example, we have categories Men -> Tops -> T-Shirts. We also have Womens -> Tops -> T-Shirts. ALL the shirts imported will go to either Mens or Womens and the other category will now be empty. The same thing happens with characteristics. We have Size and Color ... but for Mens, we have Size/Color combos for T-Shirts which are different than the Size/Color combos for Womens T-Shirts. Once we import the CSV, ALL the products will get either the Size/Color combo for mens or womens.

I've read the documentation for the CSV import, but I don't see stated anywhere that the categories have to be uniquely named? Has anyone else noticed this issue? Or point me to the doc where it says no subcategories and/or unique category and characteristics must be used?

Another fluky thing is we get up to 8 columns at the end of the file with no heading. These columns just repeat our size/color combos over and over and over and over and over and over and over???

Thanks.

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

  • Posts: 13201
  • Thank you received: 2322
10 years 5 months ago #130482

Hi,

This problem has been solved recently and will be in the next release of HikaShop.
There was duplicated columns at the end of the csv file.

You can correct it by replacing the content of the view "product / export' in the backend template via the menu Display > Views by this content:

<?php
while(ob_get_level() > 1)
	ob_end_clean();

$config =& hikashop_config();
$format = $config->get('export_format','csv');
$separator = $config->get('csv_separator',';');
$force_quote = $config->get('csv_force_quote',1);

$export = hikashop_get('helper.spreadsheet');
$export->init($format, 'hikashopexport', $separator, $force_quote);

$characteristic = hikashop_get('class.characteristic');
$classProduct = hikashop_get('class.product');
$characteristic->loadConversionTables($this);

$db = JFactory::getDBO();
if(version_compare(JVERSION,'3.0','<')){
	$columnsTable = $db->getTableFields(hikashop_table('product'));
	$columnsArray = reset($columnsTable);
} else {
	$columnsArray = $db->getTableColumns(hikashop_table('product'));
}
$columnsArray['categories_ordering'] = 'categories_ordering';

$columns = $products_columns = array_keys($columnsArray);
$product_table_count = count($columns);

//
//
//
$columns = array_merge($columns, array(
	'parent_category' => 'parent_category',
	'categories_image' => 'categories_image',
	'categories' => 'categories',
	'price_value' => 'price_value',
	'price_currency_id' => 'price_currency_id',
	'price_min_quantity' => 'price_min_quantity',
	'price_access' => 'price_access',
	'files' => 'files',
	'images' => 'images',
	'related' => 'related',
	'options' => 'options'
));

$characteristicsColumns = array();
if(!empty($this->characteristics)) {
	foreach($this->characteristics as $characteristic) {
		if(empty($characteristic->characteristic_parent_id)) {
			if(!empty($characteristic->characteristic_alias)){
				$characteristic->characteristic_value = $characteristic->characteristic_alias;
			}
			$columns[$characteristic->characteristic_id] = $characteristic->characteristic_value;
			$characteristicsColumns[$characteristic->characteristic_id] = $characteristic->characteristic_value;
		}
	}
}
$after_category_count = count($columns)-($product_table_count+3);
$export->writeline($columns);

//
//
//
if(!empty($this->categories)) {
	foreach($this->categories as $category) {
		$data = array();
		for($i = 0; $i < $product_table_count; $i++)
			$data[] = '';
		if(!empty($category->category_parent_id) && isset($this->categories[$category->category_parent_id]))
			$data[] = $this->categories[$category->category_parent_id]->category_name;
		else
			$data[] = '';
		if(!empty($category->file_path))
			 $data[] = $category->file_path;
		else
			$data[] = '';

		$data[] = $category->category_name;
		for($i = 0; $i < $after_category_count; $i++)
			$data[] = '';
		$export->writeline($data);
	}
}

//
//
//
if(!empty($this->products)) {
	foreach($this->products as $k => $product) {
		if($product->product_type == 'variant')
			$this->products[$k]->product_parent_id = $this->products[$product->product_parent_id]->product_code;
	}
	foreach($this->products as $product) {
		$data = array();

		foreach($products_columns as $column) {
			if(!empty($product->$column) && is_array($product->$column))
				$product->$column = implode($separator,$product->$column);
			$data[] = @$product->$column;
		}

		// display category info
		//
		$categories = array();
		if(!empty($product->categories)) {
			foreach($product->categories as $category) {
				if(!empty($this->categories[$category]))
					$categories[] = str_replace(array('"',',',';'), array('""','\\,','\\;'), $this->categories[$category]->category_name);
			}
		}
		$data[] = '';
		$data[] = '';

		if(!empty($categories))
			$data[] = implode($separator,$categories);
		else
			$data[] = '';

		// display price
		//
		$values = array();
		$codes = array();
		$qtys = array();
		$accesses = array();
		if(!empty($product->prices)) {
			foreach($product->prices as $price) {
				$values[] = $price->price_value;
				$codes[] = $this->currencies[$price->price_currency_id]->currency_code;
				$qtys[] = $price->price_min_quantity;
				$accesses[] = $price->price_access;
			}

		}
		if(empty($values)) {
			$data[] = '';
			$data[] = '';
			$data[] = '';
			$data[] = '';
		} else {
			$data[] = implode('|', $values);
			$data[] = implode('|', $codes);
			$data[] = implode('|', $qtys);
			$data[] = implode('|', $accesses);
		}

		// display files
		//
		$files = array();
		if(!empty($product->files)) {
			foreach($product->files as $file) {
				$files[] = str_replace(array('"',',',';'), array('""','\\,','\\;'), $file->file_path);
			}
		}
		if(empty($files)) {
			$data[] = '';
		} else {
			$data[] = implode($separator, $files);
		}

		// display images
		//
		$images = array();
		if(!empty($product->images)) {
			foreach($product->images as $image) {
				$images[] = str_replace(array('"',',',';'), array('""','\\,','\\;'), $image->file_path);
			}
		}
		if(empty($images)) {
			$data[] = '';
		} else {
			$data[] = implode($separator, $images);
		}

		// display related
		//
		$related = array();
		if(!empty($product->related)) {
			foreach($product->related as $rel) {
				if(!isset($this->products[$rel]->product_code)) $this->products[$rel] = $classProduct->get($rel);
				$related[] = str_replace(array('"',',',';'), array('""','\\,','\\;'), @$this->products[$rel]->product_code);
			}
		}
		if(empty($related)) {
			$data[] = '';
		} else {
			$data[] = implode($separator, $related);
		}

		// display options
		//
		$options = array();
		if(!empty($product->options)) {
			foreach($product->options as $rel) {
				if(!isset($this->products[$rel]->product_code)) $this->products[$rel] = $classProduct->get($rel);
				$options[] = str_replace(array('"',',',';'), array('""','\\,','\\;'), @$this->products[$rel]->product_code);
			}
		}
		if(empty($options)) {
			$data[] = '';
		} else {
			$data[] = implode($separator, $options);
		}

		// characteristics
		//
		if(!empty($product->variant_links)) {
			$characteristics = array();
			if(!empty($characteristicsColumns)) {
				foreach($product->variant_links as $char_id) {
					if(!empty($this->characteristics[$char_id])) {
						$char = $this->characteristics[$char_id];
						if(!empty($this->characteristics[$char->characteristic_parent_id])) {
							$characteristics[$char->characteristic_parent_id] = str_replace('"','""',$char->characteristic_value);
						}
					}
				}
				foreach($characteristicsColumns as $key => $characteristic){
					$data[] = @$characteristics[$key];
				}
			}
		} elseif(!empty($characteristicsColumns)) {
			for($i = 0; $i < count($characteristicsColumns); $i++) {
				$data[] = '';
			}
		}
		$export->writeLine($data);
	}
}

$export->send();
exit;

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

  • Posts: 31
  • Thank you received: 0
10 years 5 months ago #131075

I attached -orig and -fix for the before and after for our shop's export. The -fix is different than the -orig, but we still can't export our shop, and reimport the .csv without the results placing products in the wrong categories and mixing up the size/color combos.

Attachments:

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

  • Posts: 13201
  • Thank you received: 2322
10 years 5 months ago #131095

Hi,

The problem when importing is that you specify the category name for the product, but HikaShop don't know which category is required if many categories have the same name. And it's the same thing for the characteristics.

A solution could be to use the aliases, by this way the aliases are unique so each product is placed in the correct category, but, the categories and the characteristics will not be well named.
So it cause another problem... It's is very difficult to find a correct solution for that. We have this in our Todo list, improve the export/import.

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

  • Posts: 11
  • Thank you received: 0
  • Hikashop Business
9 years 5 months ago #177639

Hi I'm having the same problem, is it possible to use the IDs of the categories rather than the names?

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

  • Posts: 81540
  • Thank you received: 13069
  • MODERATOR
9 years 5 months ago #177717

Hi,

Yes of course. In the CSV you import, you can use the id of the categories instead of the name. It's useful if you have several categories with the same name.

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

Time to create page: 0.090 seconds
Powered by Kunena Forum