Import products to categories with duplicate names

  • Posts: 14
  • Thank you received: 0
12 years 1 month ago #67639

Hello,

I am importing products from an external warehouse and billing system, and my customer use the same category names many places in the category tree.

The problem is that parent category and categories for a product is referenced by name. If you use the same parent-child naming more than one place in the category tree, it is not possible to ensure import to the correct category.

I would prefer a new custom_id field to the categories, much like product code for products, so that I can use parent_category_code when creating new categories to avoid this problem.

Is it possible to get this implemented as soon as possible?

Michael

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

  • Posts: 82868
  • Thank you received: 13376
  • MODERATOR
12 years 1 month ago #67893

Hi,

There is already a category_code field.
In fact, if your categories are already created, you can directly use the category_code or even the category_id in the categories field in order to specify the category of your products.

Note though that the category_code in an intern value and is not displayed on the interface.
You can see it in the hikashop_category table of the database.

Last edit: 12 years 1 month ago by nicolas.

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

  • Posts: 14
  • Thank you received: 0
12 years 1 month ago #67956

Hi Nicolas,

The thing is that my customer use an external system for managing their product catalogue and product categories, which is imported into Hikashop at regular intervals.

I cannot rely on existing categories in Hikashop since my customer may decide to reorganize their entire product catalogue into new categories.

Is it possible to set the category_code field for categories during CSV import, and reference this category_code when importing products?

CSV could look something like this:

parent_category,parent_category_code,categories
product category,,Coffee machines|cm;Spare parts|sp;Accessories|acc,Water Coolers|wc
Coffee machines,cm,Whole bean machines|cm_wb;Filter machines|cm_fm,Instant machines|cm_im
Spare parts,sp,Coffee machines|sp_wc;Water Coolers|sp_wc
Accessories,acc,Coffee machines|acc_wc;Water Coolers|acc_wc
Water Coolers,wc,Cold water|wc_cw;Cold and sparkling water|wc_cwsw


This is part of the actual categories that my customer use. Without the category code reference, the problem is that when creating categories from the last line the parent category could be either (product category->)Water Coolers, Accessories->Water Coolers or Spare parts->Water Coolers. I guess it will just choose the first one from the database lookup...

Michael

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

  • Posts: 82868
  • Thank you received: 13376
  • MODERATOR
12 years 1 month ago #68128

Hi,

In that case that's a problem.
The category codes are actually generated automatically.


You will have to add the line:
$obj->category_namekey = $namekey;

after the line:
$obj->category_name = $category;

the line:
$columns='categories_namekey';

after the line:
$columns='parent_category';

the line:
if($this->createCategories && !empty($product->categories_namekey)) $this->_separate($product->categories_namekey);

before the line:
if($this->createCategories && !empty($product->categories_image)){

and replace the line:
$id = $this->_createCategory($v,$pid,'product',@$product->categories_image[$k]);

by:
$id = $this->_createCategory($v,$pid,'product',@$product->categories_image[$k],@$product->categories_namekey[$k]);

and you should be able to import with a column categories_namekey like that:
parent_category;categories;categories_namekey;product_name
;main cat;mc;
;main cat2;mc2;
mc;sub cat;sb;
mc2;sub cat;sb2;
;sb,sb2;;my product

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

  • Posts: 36
  • Thank you received: 6
11 years 11 months ago #80116

This does not appear to be working in the current version and the changes noted above don't seem to fit into the current code. Or maybe I am looking in the wrong place.

Could you please clarify where these changes go and whether they apply to 2.0? I would really like to get this working.

Thanks!

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

  • Posts: 82868
  • Thank you received: 13376
  • MODERATOR
11 years 11 months ago #80167

These modifications are already included in HikaShop 2.0. You can directly use the column categories_namekey in your CSV without changing any code.

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

  • Posts: 36
  • Thank you received: 6
11 years 11 months ago #80270

Thanks. It is working. I discovered it is a different issue. Apparently importing categories that have numeric names causes problems. The following appears to do nothing.

parent_category,categories,categories_ordering,categories_namekey
Top,44,,catkey_44

Is there a work around? The goal is to get a new category named "44" under Top.

Thanks!

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

  • Posts: 13201
  • Thank you received: 2322
11 years 11 months ago #80350

Hi,

You can add it manually in the backend, or try to add quotes:

parent_category,categories,categories_ordering,categories_namekey
Top,'44',,catkey_44

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

  • Posts: 36
  • Thank you received: 6
11 years 11 months ago #80491

Unfortunately, neither single or double quotes work.

I have thousands of categories to import, so using the backend isn't a good option.

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

  • Posts: 82868
  • Thank you received: 13376
  • MODERATOR
11 years 11 months ago #80559

Unfotunately, if you put an integer in the categories column, the system thinks that you want to point to the category with the id 44 instead of creating a category with the name "44".


You will have to hack the file administrator/components/com_hikashop/helpers/import.php and change the code:
foreach($product->categories as $k => $v){
if(!is_numeric($v)){
to:
foreach($product->categories as $k => $v){
if(true){

in order to force the system to create the category.

The following user(s) said Thank You: mtense

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

  • Posts: 36
  • Thank you received: 6
11 years 11 months ago #80773

Thanks for the guidance. I made a slightly different change which might make sense to incorporate into the code base.

  if(!is_numeric($v) || !empty($product->categories_namekey)){

I think the only time a namekey is used is when creating a category. If we know we are creating a category, then we can ignore whether the category is numeric. Does this make sense or am I missing something?

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

  • Posts: 82868
  • Thank you received: 13376
  • MODERATOR
11 years 11 months ago #81042

that makes sense. We'll change that for next release.

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

  • Posts: 5
  • Thank you received: 0
10 years 3 weeks ago #178408

Hi,

I am using HikaShop 2.3.3. All the categories already exist in the database and I know the category namekey for each category. I would like to specify the namekey of the category in the import for the product to go into that category. The namekey is an integer value. Is there a way to do this?


Best regards,

Steffan Harris
Virtual Motorpix

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

  • Posts: 26158
  • Thank you received: 4028
  • MODERATOR
10 years 2 weeks ago #178411

Hi,

If you put a number, HikaShop will think that you specified the category_id ; not the category_namekey.

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.104 seconds
Powered by Kunena Forum