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

#   Create a product in PHP code

##

- **[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
-
-

10 years 9 months ago [\#228476](#228476) by [jean-loup](/forum/user/40284-jean-loup "View jean-loup's Profile")  *[Create a product in PHP code](/forum/32-content-creation/882008-create-a-product-in-php-code#228476 "-- HikaShop version -- : 2.6.1 -- Joomla version -- : 3.4.8 -- PHP version -- : 5.6.10  I've create a module in joomla. This module work fine. I want to create a dynamic hikashop product in this module.  The code not create new product : $product = new stdClass(); $product-&gt;product&#95;name = 'Custom Watch'; $product-&gt;categories = array(46); $price = null; $price-&gt;price&#95;value = 246; $price-&gt;price&#95;currency&#95;id = 1; $product-&gt;prices = array($price);  $productClass = hikashop&#95;get('class.product'); $result = $productClass-&gt;save($product); $productClass-&gt;updateCategories($product, $result);  If i use this sample work fine (get the product 107 and add in cart): $productget=$productClass-&gt;get(107); $cartClass = hikashop&#95;get('class.cart'); $cartClass-&gt;update(107,2);  Why the product is not create ? In log file cannot error.  An idee ? Thanks you best regards")* was created by *[jean-loup](/forum/user/40284-jean-loup "View jean-loup's Profile")*

-- HikaShop version -- : 2.6.1
-- Joomla version -- : 3.4.8
-- PHP version -- : 5.6.10

I've create a module in joomla.
This module work fine.
I want to create a dynamic hikashop product in this module.

The code not create new product :
$product = new stdClass();
$product-&gt;product_name = 'Custom Watch';
$product-&gt;categories = array(46);
$price = null;
$price-&gt;price_value = 246;
$price-&gt;price_currency_id = 1;
$product-&gt;prices = array($price);

$productClass = hikashop_get('class.product');
$result = $productClass-&gt;save($product);
$productClass-&gt;updateCategories($product, $result);

If i use this sample work fine (get the product 107 and add in cart):
$productget=$productClass-&gt;get(107);
$cartClass = hikashop_get('class.cart');
$cartClass-&gt;update(107,2);

Why the product is not create ? In log file cannot error.

An idee ? Thanks you best regards

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzMyLWNvbnRlbnQtY3JlYXRpb24vODgyMDA4LWNyZWF0ZS1hLXByb2R1Y3QtaW4tcGhwLWNvZGU/dG1wbD1tYXJrZG93bg==) 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")
- [ Offline](/forum/user/63-nicolas)

Less More

- Posts: 86587
- Thank you received: 14325
-
-

10 years 9 months ago [\#228504](#228504) by [nicolas](/forum/user/63-nicolas "View nicolas's Profile")  Replied by *[nicolas](/forum/user/63-nicolas "View nicolas's Profile")* on topic *[Create a product in PHP code](/forum/32-content-creation/882008-create-a-product-in-php-code#228504 "-- HikaShop version -- : 2.6.1 -- Joomla version -- : 3.4.8 -- PHP version -- : 5.6.10  I've create a module in joomla. This module work fine. I want to create a dynamic hikashop product in this module.  The code not create new product : $product = new stdClass(); $product-&gt;product&#95;name = 'Custom Watch'; $product-&gt;categories = array(46); $price = null; $price-&gt;price&#95;value = 246; $price-&gt;price&#95;currency&#95;id = 1; $product-&gt;prices = array($price);  $productClass = hikashop&#95;get('class.product'); $result = $productClass-&gt;save($product); $productClass-&gt;updateCategories($product, $result);  If i use this sample work fine (get the product 107 and add in cart): $productget=$productClass-&gt;get(107); $cartClass = hikashop&#95;get('class.cart'); $cartClass-&gt;update(107,2);  Why the product is not create ? In log file cannot error.  An idee ? Thanks you best regards")*

Hi,

This will definitely create the product unless there is already a product with the code CustomWatch in your database. In that case, the saving of the product will fail as two products cannot have the same product code (which is generated out of the product name if you don't specify the product code).

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzMyLWNvbnRlbnQtY3JlYXRpb24vODgyMDA4LWNyZWF0ZS1hLXByb2R1Y3QtaW4tcGhwLWNvZGU/dG1wbD1tYXJrZG93bg==) 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
-
-

10 years 9 months ago [\#228608](#228608) 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 *[Create a product in PHP code](/forum/32-content-creation/882008-create-a-product-in-php-code#228608 "-- HikaShop version -- : 2.6.1 -- Joomla version -- : 3.4.8 -- PHP version -- : 5.6.10  I've create a module in joomla. This module work fine. I want to create a dynamic hikashop product in this module.  The code not create new product : $product = new stdClass(); $product-&gt;product&#95;name = 'Custom Watch'; $product-&gt;categories = array(46); $price = null; $price-&gt;price&#95;value = 246; $price-&gt;price&#95;currency&#95;id = 1; $product-&gt;prices = array($price);  $productClass = hikashop&#95;get('class.product'); $result = $productClass-&gt;save($product); $productClass-&gt;updateCategories($product, $result);  If i use this sample work fine (get the product 107 and add in cart): $productget=$productClass-&gt;get(107); $cartClass = hikashop&#95;get('class.cart'); $cartClass-&gt;update(107,2);  Why the product is not create ? In log file cannot error.  An idee ? Thanks you best regards")*

Bonjour,
Je suis conscient que je ne peux créer plusieurs produits avec les mêmes références.

Je n'arrive simplement pas a créer un nouveau produit directement en PHP en mode objet.
J'ai aussi ce genre de message dans les logs :
*PHP Warning: Creating default object from empty value in ...*
Qui correspond à ceci : **$product-&gt;product\_name = 'MyCustomWatch';**

Avez-vous un exemple ou les champs requis pour la création d'un produit en PHP ?

Merci

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzMyLWNvbnRlbnQtY3JlYXRpb24vODgyMDA4LWNyZWF0ZS1hLXByb2R1Y3QtaW4tcGhwLWNvZGU/dG1wbD1tYXJrZG93bg==) 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")
- [ Offline](/forum/user/63-nicolas)

Less More

- Posts: 86587
- Thank you received: 14325
-
-

10 years 9 months ago [\#228610](#228610) by [nicolas](/forum/user/63-nicolas "View nicolas's Profile")  Replied by *[nicolas](/forum/user/63-nicolas "View nicolas's Profile")* on topic *[Create a product in PHP code](/forum/32-content-creation/882008-create-a-product-in-php-code#228610 "-- HikaShop version -- : 2.6.1 -- Joomla version -- : 3.4.8 -- PHP version -- : 5.6.10  I've create a module in joomla. This module work fine. I want to create a dynamic hikashop product in this module.  The code not create new product : $product = new stdClass(); $product-&gt;product&#95;name = 'Custom Watch'; $product-&gt;categories = array(46); $price = null; $price-&gt;price&#95;value = 246; $price-&gt;price&#95;currency&#95;id = 1; $product-&gt;prices = array($price);  $productClass = hikashop&#95;get('class.product'); $result = $productClass-&gt;save($product); $productClass-&gt;updateCategories($product, $result);  If i use this sample work fine (get the product 107 and add in cart): $productget=$productClass-&gt;get(107); $cartClass = hikashop&#95;get('class.cart'); $cartClass-&gt;update(107,2);  Why the product is not create ? In log file cannot error.  An idee ? Thanks you best regards")*

Bonjour,

Il n'y a aucun champs requis.
Juste cela devrait fonctionner:
$productClass = hikashop_get('class.product');
$product = new stdClass();
$product-&gt;product_name = 'Mon produit';
$result = $productClass-&gt;save($product);

Peut être avez vous configuré des actions en masse sur votre site et l'une d'elle interfère avec la création du produit ?

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzMyLWNvbnRlbnQtY3JlYXRpb24vODgyMDA4LWNyZWF0ZS1hLXByb2R1Y3QtaW4tcGhwLWNvZGU/dG1wbD1tYXJrZG93bg==) 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.046 seconds

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