[Skip to main content](#vessel-content)

#   category attribution when creating product on php script

##

- **[jean-loup](/forum/user/40284-jean-loup "View jean-loup's Profile")**
- [![jean-loup's Avatar](https://www.hikashop.com/media/kunena/core/svg/person.svg)](/forum/user/40284-jean-loup "View jean-loup's Profile") Topic Author
- [ Offline](/forum/user/40284-jean-loup)

Less More

- Posts: 176
- Thank you received: 8
-
-

7 years 11 months ago -  7 years 11 months ago [\#301138](#301138) by [jean-loup](/forum/user/40284-jean-loup "View jean-loup's Profile")  *[category attribution when creating product on php script](/forum/31-development/896365-category-attribution-when-creating-product-on-php-script#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&#95;get('class.product'); $product = new stdClass(); $product-&gt;product&#95;name = $watchName; $product-&gt;product&#95;code = $watchId; $product-&gt;product&#95;msrp = $watchPrice; $product-&gt;product&#95;published = 1; $product-&gt;product&#95;quantity = 1; $product-&gt;product&#95;tax&#95;id = 11; $product-&gt;product&#95;warehouse&#95;id = 1; $product-&gt;categories = array(47); $result = $productClass-&gt;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&#95;category)?  Thank you for your help  Jean-Loup")* was created by *[jean-loup](/forum/user/40284-jean-loup "View jean-loup's Profile")*

-- url of the page with the problem -- : [ www.121time.com](http://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-&gt;product_name = $watchName;
$product-&gt;product_code = $watchId;
$product-&gt;product_msrp = $watchPrice;
$product-&gt;product_published = 1;
$product-&gt;product_quantity = 1;
$product-&gt;product_tax_id = 11;
$product-&gt;product_warehouse_id = 1;
**$product-&gt;categories = array(47);**
$result = $productClass-&gt;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 11 months ago by [jean-loup](/forum/user/40284-jean-loup "View jean-loup's Profile").

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzMxLWRldmVsb3BtZW50Lzg5NjM2NS1jYXRlZ29yeS1hdHRyaWJ1dGlvbi13aGVuLWNyZWF0aW5nLXByb2R1Y3Qtb24tcGhwLXNjcmlwdD90bXBsPW1hcmtkb3du) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

- **[nicolas](/forum/user/63-nicolas "View nicolas's Profile")**
- [![nicolas's Avatar](https://www.hikashop.com/media/kunena/avatars/resized/size144/users/avatar63.png?1793428657)](/forum/user/63-nicolas "View nicolas's Profile")
- [ Away](/forum/user/63-nicolas)

Less More

- Posts: 86541
- Thank you received: 14304
-
-

7 years 11 months ago -  7 years 11 months ago [\#301160](#301160) by [nicolas](/forum/user/63-nicolas "View nicolas's Profile")  Replied by *[nicolas](/forum/user/63-nicolas "View nicolas's Profile")* on topic *[category attribution when creating product on php script](/forum/31-development/896365-category-attribution-when-creating-product-on-php-script#301160 "-- 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&#95;get('class.product'); $product = new stdClass(); $product-&gt;product&#95;name = $watchName; $product-&gt;product&#95;code = $watchId; $product-&gt;product&#95;msrp = $watchPrice; $product-&gt;product&#95;published = 1; $product-&gt;product&#95;quantity = 1; $product-&gt;product&#95;tax&#95;id = 11; $product-&gt;product&#95;warehouse&#95;id = 1; $product-&gt;categories = array(47); $result = $productClass-&gt;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&#95;category)?  Thank you for your help  Jean-Loup")*

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: Code:

$productClass-&gt;updateCategories($product, $result);

Last edit: 7 years 11 months ago by [nicolas](/forum/user/63-nicolas "View nicolas's Profile").

The following user(s) said Thank You: [jean-loup](/forum/user/40284-jean-loup "View jean-loup's Profile")

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzMxLWRldmVsb3BtZW50Lzg5NjM2NS1jYXRlZ29yeS1hdHRyaWJ1dGlvbi13aGVuLWNyZWF0aW5nLXByb2R1Y3Qtb24tcGhwLXNjcmlwdD90bXBsPW1hcmtkb3du) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

- **[jean-loup](/forum/user/40284-jean-loup "View jean-loup's Profile")**
- [![jean-loup's Avatar](https://www.hikashop.com/media/kunena/core/svg/person.svg)](/forum/user/40284-jean-loup "View jean-loup's Profile") Topic Author
- [ Offline](/forum/user/40284-jean-loup)

Less More

- Posts: 176
- Thank you received: 8
-
-

7 years 11 months ago [\#301196](#301196) by [jean-loup](/forum/user/40284-jean-loup "View jean-loup's Profile")  Replied by *[jean-loup](/forum/user/40284-jean-loup "View jean-loup's Profile")* on topic *[category attribution when creating product on php script](/forum/31-development/896365-category-attribution-when-creating-product-on-php-script#301196 "-- 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&#95;get('class.product'); $product = new stdClass(); $product-&gt;product&#95;name = $watchName; $product-&gt;product&#95;code = $watchId; $product-&gt;product&#95;msrp = $watchPrice; $product-&gt;product&#95;published = 1; $product-&gt;product&#95;quantity = 1; $product-&gt;product&#95;tax&#95;id = 11; $product-&gt;product&#95;warehouse&#95;id = 1; $product-&gt;categories = array(47); $result = $productClass-&gt;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&#95;category)?  Thank you for your help  Jean-Loup")*

Working first shot, brilliant thanks again, what a service

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzMxLWRldmVsb3BtZW50Lzg5NjM2NS1jYXRlZ29yeS1hdHRyaWJ1dGlvbi13aGVuLWNyZWF0aW5nLXByb2R1Y3Qtb24tcGhwLXNjcmlwdD90bXBsPW1hcmtkb3du) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

Board Categories HikaShop Install &amp; Update Product &amp; Category Display Content Creation Sales and Orders Orders management Reports &amp; Statistics Customers Checkout Payment Methods Shipping Methods Import &amp; Export (CSV, XLS…) Specific Features Affilation Taxes Wishlist Vote Carousel &amp; Slider Mass Actions Filters &amp; Search Discount &amp; Coupon Feature Request Integrations Showcase General Talk about HikaShop Development HikaShop 3.0 Beta Translation Commercial Jobs HikaShop Components HikaMarket Market: Feature requests Market: How to? Market: Bug Report HikaSerial General talk about HikaSerial Serial: Bug Report Serial: How to? Support en Français de HikaSerial (French Support) HikaSubscription HikaAuction Auction: Feature requests Auction: How to? Auction: Bug report Hikashop around the world Support en Français (French Support) Russian FAQ. Курс выживания с Hikashop. Частые вопросы и о Расширения Hikashop Наши сайты на Hikashop 日本語版サポート(Japanese Support) Thai German Archives Bug Report How to?

[](/forum/topics/feed/mode-topics?format=feed&type=rss)

Time to create page: 0.045 seconds

[Powered by](/forum/credits) [Kunena Forum](https://www.kunena.org)
