- Posts: 166
- Thank you received: 6
category attribution when creating product on php script
7 years 9 months ago - 7 years 9 months ago #301138
by jean-loup
-- 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
-- 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: 7 years 9 months ago by jean-loup.
Please Log in or Create an account to join the conversation.
7 years 9 months ago - 7 years 9 months ago #301160
by nicolas
Replied by nicolas on topic category attribution when creating product on php script
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:
The save function will only save the product data.
You want to call that function in your code to also save the category link:
Code:
$productClass->updateCategories($product, $result);
Last edit: 7 years 9 months ago by nicolas.
The following user(s) said Thank You: jean-loup
Please Log in or Create an account to join the conversation.
7 years 9 months ago #301196
by jean-loup
Replied by jean-loup on topic category attribution when creating product on php script
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.174 seconds