Bug Exporting products

  • Posts: 46
  • Thank you received: 0
11 years 5 months ago #108497

Hello,
I think there is a bug exporting all my product:

In the generated CSV file, the column with PARENT_CATEGORY is empty, but on the site, is populated..
I really neeed this to mass modify my producy, but actually is almost impossible export, modify and reimport the CSV...

Thanks
Giorgio

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

  • Posts: 82863
  • Thank you received: 13372
  • MODERATOR
11 years 5 months ago #108558

Hi,

There is no parent_category column "on the site".
Also, that column is not necessary for imports. I don't see why you need it ? It's an optional column which shouldn't change anything.

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

  • Posts: 46
  • Thank you received: 0
11 years 5 months ago #108721

I have used parent_category to import from a CSV my database!

Please look attached images:






Now I need to export the same structure, what I need to do?

thanks

Giorgio

Attachments:

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

  • Posts: 46
  • Thank you received: 0
11 years 5 months ago #108726

(as described in documentation)


"You could also mix both products and categories in the CSV:
product_code,parent_category,categories
,main category 1,sub category 2
my_product_1,main category 1,sub category 2"

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

  • Posts: 82863
  • Thank you received: 13372
  • MODERATOR
11 years 5 months ago #108728

The export already export the category structure. There is no need for the parent_category column to be filled for the products in the exported CSV. It work work like you want when you import it back.

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

  • Posts: 46
  • Thank you received: 0
11 years 5 months ago #108737

Hi,
I think that I'm doing some errors, because if I import the CSV exported from Hikashop, I lose the main category!
Exactly "CASSE AMPLIFICATE & ACCESSORI"

I can't find the words "CASSE AMPLIFICATE & ACCESSORI" in the CSV exported!

Initially I've create the main categories using "parent_category"!

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

  • Posts: 46
  • Thank you received: 0
11 years 5 months ago #108740

To see the problem, follow please this steps:


Import fromt text data this code:


parent_category,categories,product_code,product_name,price_value,price_currency_id,images
CASSE AMPLIFICATE & ACCESSORI,ACCESSORI PER CASSE AMPLIFICATE,BAG12,CUSTODIA IN TESSUTO PER PROSOUND 12,"19,97",EUR,BAG12.jpg
CASSE AMPLIFICATE & ACCESSORI,CASSE AMPLIFICATE,C6AN,"DIFF AMPL 2VIE NERO 60W WOOFER6.5"" CE ROHS","160,5",EUR,C6AN.jpg
CASSE AMPLIFICATE & ACCESSORI,CASSE AMPLIFICATE,C8AN,"DIFF AMPL 2VIE NERO 80W WOOFER8"" CE ROHS","213,5",EUR,C8AN.jpg
CASSE AMPLIFICATE & ACCESSORI,CASSE AMPLIFICATE,E5AB,"DIFF.AMPL2VIE-BIANCO-70W-2WOOFER6.5""CE ROHS","217,57",EUR,E5AB.jpg

As you can see you now have this structure:
Main Category:
CASSE AMPLIFICATE & ACCESSORI
Sub Category:
ACCESSORI PER CASSE AMPLIFICATE



Now if you try to export, in the CSV downloaded file, you lose the main category!!
In the CSV the are not "CASSE AMPLIFICATE & ACCESSORI" !!
(I have just tried on your demo site!)

Last edit: 11 years 5 months ago by giorgiofox.

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

  • Posts: 82863
  • Thank you received: 13372
  • MODERATOR
11 years 5 months ago #108744

That's great.
So the issue is that the categories lines are not added to the CSV anymore because of a refactor we did in a previous release.
Add the line:

$export->writeline($data);
after the code:
$data[] = $category->category_name;
		for($i = 0; $i < $after_category_count; $i++)
			$data[] = '';
in the file "export" of the view "product" for your backend template via the menu Display->Views and that will work.

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

  • Posts: 46
  • Thank you received: 0
11 years 5 months ago #108823

Thank'u!

Seem to not work:
If I use this code:



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);
}


It export only a empty product list,
maybe I'm doing something wrong?

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

  • Posts: 82863
  • Thank you received: 13372
  • MODERATOR
11 years 5 months ago #108923

It's working fine on my end like that.

Are you sure that you didn't add some wrong characters somewhere else in the file or removed some other code in the file ?

Can you try again with the debug mode and error reporting options of the joomla configuration turned on and then provide the generated CSV ?

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

  • Posts: 46
  • Thank you received: 0
11 years 5 months ago #108936

Hello, this is my code, and in attachment you can find the generated CSV.
Turned on also the debug mode, but nothing changed.

As you can see is empty :(

<?php
/**
 * @package  HikaShop for Joomla!
 * @version  2.1.3
 * @author  hikashop.com
 * @copyright  (C) 2010-2013 HIKARI SOFTWARE. All rights reserved.
 * @license  GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
 */
defined('_JEXEC') or die('Restricted access');
?><?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)) {
      $columns[$characteristic->characteristic_value] = $characteristic->characteristic_value;
      $characteristicsColumns[] = $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;
    }

    $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[] = '';

    $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);
    }

    $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);
    }

    $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);
    }

    $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);
    }

    $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);
    }

    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])) {
              $key = $this->characteristics[$char->characteristic_parent_id]->characteristic_value;
              $characteristics[$key] = str_replace('"','""',$char->characteristic_value);
            }
          }
        }
        foreach($characteristicsColumns as $characteristic){
          $data[] = @$characteristics[$characteristic];
        }
      }
    } elseif(!empty($characteristicsColumns)) {
      for($i = 0; $i < count($characteristicsColumns); $i++) {
        $data[] = '';
      }
    }
    $export->writeLine($data);
  }
}

$export->send();
exit;

Attachments:

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

  • Posts: 82863
  • Thank you received: 13372
  • MODERATOR
11 years 5 months ago #108939

I checked your CSV and it is now correct.

It is not empty at all but contains all the category structure at the beginning and then all the products data after it, as it should.

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

Time to create page: 0.084 seconds
Powered by Kunena Forum