Export Products to CSV: Characteristics Issue

  • Posts: 37
  • Thank you received: 0
12 years 1 month ago #67599

When I export my products the column heading for characteristics don't line up. This is because I use "Size" and other names multiple times with different Aliases. I do this because it is what the end user sees. Putting "Itemname Size" for all my items with different sizes seems odd.






Similar to this threads issue, although he was importing.
www.hikashop.com/en/forum/4-how-to/58574...s-with-products.html

I used the file from that thread hoping it would export them properly but it did not. I can put everything in using the interface but would rather use CSV since it would be much quicker.

I will also have to associate multiple files for download for each size variant of each item and having to do it in the interface is going to take forever. If I could attach it to a characteristic then that would work out well as all 2x3 or whatever would show it, but that is not an option that I can see currently.

Being able to use CSV will a be a great time saver if I can get it to work with my shop setup.

I have another question, but want to search for an answer first and will start another thread for that one if needed.

Attachments:

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

  • Posts: 82818
  • Thank you received: 13361
  • MODERATOR
12 years 1 month ago #67879

Hi,

Ah yes, exporting products using several characteristics with the same name is not a good idea :)

I recommend you to edit the file "export" of the view "product" via the menu Display->Views and change all the "characteristic_value" to "characteristic_alias", except the last one of the file.

That will export the products in a proper CSV.
The import system should be able to handle that CSV and detect the characteristics based on the alias.

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

  • Posts: 37
  • Thank you received: 0
12 years 1 month ago #68296

Thank you I will give it a try this afternoon.

Should I be using the characteristics file from
www.hikashop.com/en/forum/4-how-to/58574...s-with-products.html

Or just the original. I just want to make sure I have everything lined up before doing this. I currently have the new characteristics file. I still have the original too.

I will try it with original first, then the new one if that doesn't work. I figure I can probably get my answer that way too.

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

  • Posts: 37
  • Thank you received: 0
12 years 1 month ago #68298

It does not appear to be working, assuming I did everything right. I changed the export file for my template.



There were five instances of characteristics_value, I changed the first four.

Two on line 40
One on line 41
One on line 164
Line 165 - I left characteristic_value.

Here is code that is currently in my export file.
<?php
/**
 * @package    HikaShop for Joomla!
 * @version    1.5.9
 * @author    hikashop.com
 * @copyright  (C) 2010-2012 HIKARI SOFTWARE. All rights reserved.
 * @license    GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
 */
defined('_JEXEC') or die('Restricted access');
?>
<?php
ob_end_clean();
if(ob_get_level()>2) ob_end_clean();
ob_start();
$eol= "\r\n";
$characteristic = hikashop_get('class.characteristic');
$characteristic->loadConversionTables($this);
$config =& hikashop_config();
$separator = $config->get('csv_separator',";");
$db =& JFactory::getDBO();
$columnsTable = $db->getTableFields(hikashop_table('product'));
$columnsArray = reset($columnsTable);
$columns = $products_columns = array_keys($columnsArray);
$product_table_count = count($columns);
$columns['parent_category']='parent_category';
$columns['categories_image']='categories_image';
$columns['categories']='categories';
$columns['price_value']='price_value';
$columns['price_currency_id']='price_currency_id';
$columns['price_min_quantity']='price_min_quantity';
$columns['price_access']='price_access';
$columns['files']='files';
$columns['images']='images';
$columns['related']='related';
$columns['options']='options';
$characteristicsColumns = array();
if(!empty($this->characteristics)){
  foreach($this->characteristics as $characteristic){
    if(empty($characteristic->characteristic_parent_id)){
      $columns[$characteristic->characteristic_alias]=$characteristic->characteristic_alias;
      $characteristicsColumns[]=$characteristic->characteristic_alias;
    }
  }
}
$after_category_count = count($columns)-($product_table_count+3);
$output='';
foreach($columns as $column){
  if(!empty($column)){
    $output.= '"'.str_replace('"','\\'.'"',$column).'"';
  }
  $output.= $separator;
}
echo rtrim($output,$separator).$eol;
$output='';
if(!empty($this->categories)){
  foreach($this->categories as $category){
    echo '"'.str_repeat('"'.$separator.'"',$product_table_count-1).'"'.$separator;
    if(!empty($category->category_parent_id) && isset($this->categories[$category->category_parent_id])){
      echo '"'.str_replace('"','""',$this->categories[$category->category_parent_id]->category_name).'"'.$separator;
    }else{
      echo '""'.$separator;
    }
    if(!empty($category->file_path)){
      echo '"'.str_replace('"','""',$category->file_path).'"'.$separator;
    }else{
      echo '""'.$separator;
    }
    echo '"'.str_replace('"','""',$category->category_name).'"'.$separator.'"'.str_repeat('"'.$separator.'"',$after_category_count-1).'"'.$eol;
  }
}
if(!empty($this->products)){
  foreach($this->products as $k => $product){
    if($product->product_type=="variant"){
      $this->products[$k]->product_parent_id = str_replace('"','""',$this->products[$product->product_parent_id]->product_code);
    }
  }
  foreach($this->products as $product){
    foreach($products_columns as $column){
      echo '"'.str_replace('"','""',$product->$column).'"'.$separator;
    }
    $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);
        }
      }
    }
    echo '""'.$separator.'""'.$separator;
    if(!empty($categories)){
      echo '"'.implode($separator,$categories).'"'.$separator;
    }else{
      echo '""'.$separator;
    }
    $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)){
      echo '""'.$separator.'""'.$separator.'""'.$separator.'""'.$separator;
    }else{
      echo '"'.implode('|',$values).'"'.$separator.'"'.implode('|',$codes).'"'.$separator.'"'.implode('|',$qtys).'"'.$separator.'"'.implode('|',$accesses).'"'.$separator;
    }
    $files = array();
    if(!empty($product->files)){
      foreach($product->files as $file){
        $files[]=str_replace(array('"',',',';'),array('""','\\,','\\;'),$file->file_path);
      }
    }
    if(empty($files)){
      echo '""'.$separator;
    }else{
      echo '"'.implode($separator,$files).'"'.$separator;
    }
    $images = array();
    if(!empty($product->images)){
      foreach($product->images as $image){
        $images[]=str_replace(array('"',',',';'),array('""','\\,','\\;'),$image->file_path);
      }
    }
    if(empty($images)){
      echo '""'.$separator;
    }else{
      echo '"'.implode($separator,$images).'"'.$separator;
    }
    $related = array();
    if(!empty($product->related)){
      foreach($product->related as $rel){
        $related[]=str_replace(array('"',',',';'),array('""','\\,','\\;'),@$this->products[$rel]->product_code);
      }
    }
    if(empty($related)){
      echo '""'.$separator;
    }else{
      echo '"'.implode($separator,$related).'"'.$separator;
    }
    $options = array();
    if(!empty($product->options)){
      foreach($product->options as $rel){
        $options[]=str_replace(array('"',',',';'),array('""','\\,','\\;'),@$this->products[$rel]->product_code);
      }
    }
    if(empty($options)){
      echo '""';
    }else{
      echo '"'.implode($separator,$options).'"';
    }
    if(!empty($product->variant_links)){
      echo $separator;
      $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_alias;
              $characteristics[$key] = str_replace('"','""',$char->characteristic_value);
            }
          }
        }
        $chars = array();
        foreach($characteristicsColumns as $characteristic){
          $chars[] = '"'.@$characteristics[$characteristic].'"';
        }
        echo implode($separator,$chars);
      }
    }elseif(!empty($characteristicsColumns)){
      echo $separator;
      echo str_repeat('""'.$separator,count($characteristicsColumns)-1).'""';
    }
    echo $eol;
  }
}
$data = ob_get_clean();
header("Pragma: public");
header("Expires: 0"); // set expiration time
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Content-Type: application/force-download");
header("Content-Type: application/octet-stream");
header("Content-Type: application/download");
header("Content-Disposition: attachment; filename=hikashopexport.csv;");
header("Content-Transfer-Encoding: binary");
header('Content-Length: '.strlen($data));
echo $data;
exit;

The export works fine even before all of this if using different names vs just different aliases.


BAD EXPORT with Changed Export PHP



GOOD EXPORT when using different names.



So currently what I have is not working for same name but different aliases. Let me know if I did not do something right. I would prefer to use aliases for visual appeal. If not I can use different names.

Attachments:
Last edit: 12 years 1 month ago by blbeta.

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

  • Posts: 82818
  • Thank you received: 13361
  • MODERATOR
12 years 1 month ago #68498

Based on your screenshots it seems that you're using the default template of the backend.
That template is either Khepri (joomla 1.5) or Bluestork (joomla 2.5).

On your Views listing screenshot, I can see that you're editing your view for another template called skribullmain.

So that's why it's not working since your backend template is not seeing your modification.

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

  • Posts: 37
  • Thank you received: 0
12 years 1 month ago #68503

I knew I had to be doing something wrong. Let me try that.

EDIT: Export looks good tyvm.

I will now try updating a put a few new products into the spreadsheet.

Last edit: 12 years 1 month ago by blbeta.

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

  • Posts: 82818
  • Thank you received: 13361
  • MODERATOR
12 years 1 month ago #68516

Based on your screenshots it seems that you're using the default template of the backend.
That template is either Khepri (joomla 1.5) or Bluestork (joomla 2.5).

On your Views listing screenshot, I can see that you're editing your view for another template called skribullmain.

So that's why it's not working since your backend template is not seeing your modification.

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

  • Posts: 37
  • Thank you received: 0
12 years 1 month ago #70190

Ok, it exports and I get the right characteristics in the CSV.

Importing no longer works.

I even tried switching between orginal and new characteristics.php from this thread
www.hikashop.com/en/forum/4-how-to/58574...s-with-products.html



I made no changes to the file, just tried importing it. I then tried changing one price with the same error.

Attachments:
Last edit: 12 years 1 month ago by blbeta.

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

Time to create page: 0.100 seconds
Powered by Kunena Forum