category attribution when creating product on php script

  • Posts: 163
  • Thank you received: 6
  • Hikashop Business
5 years 11 months ago #301138

-- url of the page with the problem -- : www.121time.com
-- HikaShop version -- : 4.0.1
-- Joomla version -- : 3.9.1

Good evening,

Our customer create custom and unique watches with an online configurator. We use the following code to pass a few attributes to the new product:

$productClass = hikashop_get('class.product');
$product = new stdClass();
$product->product_name = $watchName;
$product->product_code = $watchId;
$product->product_msrp = $watchPrice;
$product->product_published = 1;
$product->product_quantity = 1;
$product->product_tax_id = 11;
$product->product_warehouse_id = 1;
$product->categories = array(47);
$result = $productClass->save($product);



The creation of the product is correctly made, but we can't add to the new created products the same existing category, in our case the category id 47

Is there anyway to add a product in a category (table product_category)?

Thank you for your help

Jean-Loup

Last edit: 5 years 11 months ago by jean-loup.

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

  • Posts: 82868
  • Thank you received: 13375
  • MODERATOR
5 years 11 months ago #301160

Hi,

The save function will only save the product data.
You want to call that function in your code to also save the category link:

$productClass->updateCategories($product, $result);

Last edit: 5 years 11 months ago by nicolas.
The following user(s) said Thank You: jean-loup

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

  • Posts: 163
  • Thank you received: 6
  • Hikashop Business
5 years 11 months ago #301196

Working first shot, brilliant thanks again, what a service

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

Time to create page: 0.059 seconds
Powered by Kunena Forum