How to create a product category into hikashop programmatically

  • Posts: 252
  • Thank you received: 1
5 years 10 months ago #294016

-- HikaShop version -- : 3.4.0

Hi,
I am asking to create product category by program, Is there document for it ?

Thanks

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

  • Posts: 81515
  • Thank you received: 13069
  • MODERATOR
5 years 10 months ago #294017

Hi,

No, there is no documentation but it's quite easy:

$category = new stdClass();
$category->category_name = "My new category";
$category->category_parent_id = XX;
$categoryClass = hikashop_get('class.category');
$category_id = $categoryClass->save($category);
where XX is the id of the parent category.
Note that if you want to add an image you need also something like that:
$file = new stdClass();
$file->file_ref_id = $category_id;
$file->file_ref_type = 'category';
$file->file_path = 'YY'
$fileClass = hikashop_get('class.file');
$fileClass->save($file);
where YY is the relative path of the image from the upload folder (setting of the HikaShop configuration).

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

Time to create page: 0.054 seconds
Powered by Kunena Forum