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

#   How to update product's data using API?

##

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

Less More

- Posts: 175
- Thank you received: 0
-
-

11 years 2 months ago -  11 years 2 months ago [\#212099](#212099) by [veeco](/forum/user/18501-veeco "View veeco's Profile")  *[How to update product's data using API?](/forum/32-content-creation/878870-how-to-update-products-data-using-api#212099 "-- url of the page with the problem -- : localhost -- HikaShop version -- : 2.4.0 -- Joomla version -- : - -- PHP version -- : - -- Browser(s) name and version -- : - -- Error-message(debug-mod must be tuned on) -- : -  //EO Price $product = null;  $product-&gt;product&#95;name = $name;  $product-&gt;product&#95;quantity = -1; $product-&gt;product&#95;code = $code; $product-&gt;product&#95;published = $prod&#95;pub; $product-&gt;product&#95;tax&#95;id = 11; $product-&gt;product&#95;weight = 1; $product-&gt;product&#95;weight&#95;unit = &quot;kg&quot;; $product-&gt;product&#95;min&#95;per&#95;order = $min&#95;order; $product-&gt;product&#95;type = &quot;main&quot;; $product-&gt;product&#95;access = &quot;all&quot;; $product-&gt;product&#95;manufacturer&#95;id = $id&#95;merek; $product-&gt;grup = $grup; $product-&gt;tipe = $tipe; $product-&gt;unit = $unit;   $product-&gt;product&#95;quantity = $stock; $product-&gt;stockstatus = $stockstatus;  $product-&gt;prices = array($price); $product-&gt;categories = array($child); //where 1 and 2 are the ids of two categories &#91;currenlty: string - &quot;24&quot;&#93; //EO product $productClass = hikashop::get('class.product'); $productClass-&gt;save($product);  //load product id $query = $db-&gt;getQuery(true); $query-&gt;select('product&#95;id') -&gt;from('#&#95;&#95;hikashop&#95;product') -&gt;where('product&#95;code = &quot;'.$code.'&quot;'); $db-&gt;setQuery($query); $results = $db-&gt;loadObjectList();  $product&#95;id = $results&#91;0&#93;-&gt;product&#95;id;  $productClass-&gt;save($product);  hi, i used this code to insert product into hikashop, however it's restrictly only for insert &#91;new product&#93;, if product exists then it skipped the product  is there anyway to make it update the product if it's exists? &#91;name, quantity, description, etc&#93;  i have tried $productClass-&gt;refreshQuantities(); but it doesnt do anything")* was created by *[veeco](/forum/user/18501-veeco "View veeco's Profile")*

-- url of the page with the problem -- : localhost
-- HikaShop version -- : 2.4.0
-- Joomla version -- : -
-- PHP version -- : -
-- Browser(s) name and version -- : -
-- Error-message(debug-mod must be tuned on) -- : -

//EO Price
$product = null;
**$product-&gt;product\_name = $name;**  $product-&gt;product_quantity = -1;
$product-&gt;product_code = $code;
$product-&gt;product_published = $prod_pub;
$product-&gt;product_tax_id = 11;
$product-&gt;product_weight = 1;
$product-&gt;product_weight_unit = "kg";
$product-&gt;product_min_per_order = $min_order;
$product-&gt;product_type = "main";
$product-&gt;product_access = "all";
$product-&gt;product_manufacturer_id = $id_merek;
$product-&gt;grup = $grup;
$product-&gt;tipe = $tipe;
$product-&gt;unit = $unit;

**$product-&gt;product\_quantity = $stock;
$product-&gt;stockstatus = $stockstatus;**

$product-&gt;prices = array($price);
$product-&gt;categories = array($child); //where 1 and 2 are the ids of two categories [currenlty: string - "24"]
//EO product
**$productClass = hikashop::get('class.product');**
$productClass-&gt;save($product);

//load product id
$query = $db-&gt;getQuery(true);
$query-&gt;select('product_id')
-&gt;from('#__hikashop_product')
-&gt;where('product_code = "'.$code.'"');
$db-&gt;setQuery($query);
$results = $db-&gt;loadObjectList();

$product_id = $results[0]-&gt;product_id;

$productClass-&gt;save($product);

hi, i used this code to insert product into hikashop, however it's restrictly only for insert [new product], if product exists then it skipped the product

is there anyway to make it update the product if it's exists? [name, quantity, description, etc]

i have tried $productClass-&gt;refreshQuantities(); but it doesnt do anything

Last edit: 11 years 2 months ago by [veeco](/forum/user/18501-veeco "View veeco's Profile").

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

- **[Mohamed Thelji](/forum/user/6861-mohamed-thelji "View Mohamed Thelji's Profile")**
- [![Mohamed Thelji's Avatar](https://www.hikashop.com/media/kunena/avatars/resized/size144/users/avatar6861.png)](/forum/user/6861-mohamed-thelji "View Mohamed Thelji's Profile")
- [ Offline](/forum/user/6861-mohamed-thelji)

Less More

- Posts: 12953
- Thank you received: 1778
-
-
-

11 years 2 months ago [\#212110](#212110) by [Mohamed Thelji](/forum/user/6861-mohamed-thelji "View Mohamed Thelji's Profile")  Replied by *[Mohamed Thelji](/forum/user/6861-mohamed-thelji "View Mohamed Thelji's Profile")* on topic *[How to update product's data using API?](/forum/32-content-creation/878870-how-to-update-products-data-using-api#212110 "-- url of the page with the problem -- : localhost -- HikaShop version -- : 2.4.0 -- Joomla version -- : - -- PHP version -- : - -- Browser(s) name and version -- : - -- Error-message(debug-mod must be tuned on) -- : -  //EO Price $product = null;  $product-&gt;product&#95;name = $name;  $product-&gt;product&#95;quantity = -1; $product-&gt;product&#95;code = $code; $product-&gt;product&#95;published = $prod&#95;pub; $product-&gt;product&#95;tax&#95;id = 11; $product-&gt;product&#95;weight = 1; $product-&gt;product&#95;weight&#95;unit = &quot;kg&quot;; $product-&gt;product&#95;min&#95;per&#95;order = $min&#95;order; $product-&gt;product&#95;type = &quot;main&quot;; $product-&gt;product&#95;access = &quot;all&quot;; $product-&gt;product&#95;manufacturer&#95;id = $id&#95;merek; $product-&gt;grup = $grup; $product-&gt;tipe = $tipe; $product-&gt;unit = $unit;   $product-&gt;product&#95;quantity = $stock; $product-&gt;stockstatus = $stockstatus;  $product-&gt;prices = array($price); $product-&gt;categories = array($child); //where 1 and 2 are the ids of two categories &#91;currenlty: string - &quot;24&quot;&#93; //EO product $productClass = hikashop::get('class.product'); $productClass-&gt;save($product);  //load product id $query = $db-&gt;getQuery(true); $query-&gt;select('product&#95;id') -&gt;from('#&#95;&#95;hikashop&#95;product') -&gt;where('product&#95;code = &quot;'.$code.'&quot;'); $db-&gt;setQuery($query); $results = $db-&gt;loadObjectList();  $product&#95;id = $results&#91;0&#93;-&gt;product&#95;id;  $productClass-&gt;save($product);  hi, i used this code to insert product into hikashop, however it's restrictly only for insert &#91;new product&#93;, if product exists then it skipped the product  is there anyway to make it update the product if it's exists? &#91;name, quantity, description, etc&#93;  i have tried $productClass-&gt;refreshQuantities(); but it doesnt do anything")*

Hello,
To do what you want you'll just have to check through the "product" hikashop table &lt;==&gt; hikashop_table('product') that the products actually exists, and if it does, then you'll just have to update your product quantity for example.

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

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

Less More

- Posts: 175
- Thank you received: 0
-
-

11 years 2 months ago -  11 years 2 months ago [\#212293](#212293) by [veeco](/forum/user/18501-veeco "View veeco's Profile")  Replied by *[veeco](/forum/user/18501-veeco "View veeco's Profile")* on topic *[How to update product's data using API?](/forum/32-content-creation/878870-how-to-update-products-data-using-api#212293 "-- url of the page with the problem -- : localhost -- HikaShop version -- : 2.4.0 -- Joomla version -- : - -- PHP version -- : - -- Browser(s) name and version -- : - -- Error-message(debug-mod must be tuned on) -- : -  //EO Price $product = null;  $product-&gt;product&#95;name = $name;  $product-&gt;product&#95;quantity = -1; $product-&gt;product&#95;code = $code; $product-&gt;product&#95;published = $prod&#95;pub; $product-&gt;product&#95;tax&#95;id = 11; $product-&gt;product&#95;weight = 1; $product-&gt;product&#95;weight&#95;unit = &quot;kg&quot;; $product-&gt;product&#95;min&#95;per&#95;order = $min&#95;order; $product-&gt;product&#95;type = &quot;main&quot;; $product-&gt;product&#95;access = &quot;all&quot;; $product-&gt;product&#95;manufacturer&#95;id = $id&#95;merek; $product-&gt;grup = $grup; $product-&gt;tipe = $tipe; $product-&gt;unit = $unit;   $product-&gt;product&#95;quantity = $stock; $product-&gt;stockstatus = $stockstatus;  $product-&gt;prices = array($price); $product-&gt;categories = array($child); //where 1 and 2 are the ids of two categories &#91;currenlty: string - &quot;24&quot;&#93; //EO product $productClass = hikashop::get('class.product'); $productClass-&gt;save($product);  //load product id $query = $db-&gt;getQuery(true); $query-&gt;select('product&#95;id') -&gt;from('#&#95;&#95;hikashop&#95;product') -&gt;where('product&#95;code = &quot;'.$code.'&quot;'); $db-&gt;setQuery($query); $results = $db-&gt;loadObjectList();  $product&#95;id = $results&#91;0&#93;-&gt;product&#95;id;  $productClass-&gt;save($product);  hi, i used this code to insert product into hikashop, however it's restrictly only for insert &#91;new product&#93;, if product exists then it skipped the product  is there anyway to make it update the product if it's exists? &#91;name, quantity, description, etc&#93;  i have tried $productClass-&gt;refreshQuantities(); but it doesnt do anything")*

> Mohamed Thelji wrote: Hello,
> To do what you want you'll just have to check through the "product" hikashop table &lt;==&gt; hikashop\_table('product') that the products actually exists, and if it does, then you'll just have to update your product quantity for example.

hi

Is it through manual SQL query with jdbo? or it could be done using hikashop API like this? could you provide sample code?

the
//EO product
$productClass = hikashop::get('class.product');
$productClass-&gt;save($product);

part only save if it's a new product, i need it to save if not exists and update the product's data if it does exists

is there any method to make it update instead of save?
$productClass-&gt;update($product); or something?

Last edit: 11 years 2 months ago by [veeco](/forum/user/18501-veeco "View veeco's Profile").

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzMyLWNvbnRlbnQtY3JlYXRpb24vODc4ODcwLWhvdy10by11cGRhdGUtcHJvZHVjdHMtZGF0YS11c2luZy1hcGk/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)](/forum/user/63-nicolas "View nicolas's Profile")
- [ Away](/forum/user/63-nicolas)

Less More

- Posts: 86290
- Thank you received: 14268
-
-

11 years 2 months ago [\#212318](#212318) by [nicolas](/forum/user/63-nicolas "View nicolas's Profile")  Replied by *[nicolas](/forum/user/63-nicolas "View nicolas's Profile")* on topic *[How to update product's data using API?](/forum/32-content-creation/878870-how-to-update-products-data-using-api#212318 "-- url of the page with the problem -- : localhost -- HikaShop version -- : 2.4.0 -- Joomla version -- : - -- PHP version -- : - -- Browser(s) name and version -- : - -- Error-message(debug-mod must be tuned on) -- : -  //EO Price $product = null;  $product-&gt;product&#95;name = $name;  $product-&gt;product&#95;quantity = -1; $product-&gt;product&#95;code = $code; $product-&gt;product&#95;published = $prod&#95;pub; $product-&gt;product&#95;tax&#95;id = 11; $product-&gt;product&#95;weight = 1; $product-&gt;product&#95;weight&#95;unit = &quot;kg&quot;; $product-&gt;product&#95;min&#95;per&#95;order = $min&#95;order; $product-&gt;product&#95;type = &quot;main&quot;; $product-&gt;product&#95;access = &quot;all&quot;; $product-&gt;product&#95;manufacturer&#95;id = $id&#95;merek; $product-&gt;grup = $grup; $product-&gt;tipe = $tipe; $product-&gt;unit = $unit;   $product-&gt;product&#95;quantity = $stock; $product-&gt;stockstatus = $stockstatus;  $product-&gt;prices = array($price); $product-&gt;categories = array($child); //where 1 and 2 are the ids of two categories &#91;currenlty: string - &quot;24&quot;&#93; //EO product $productClass = hikashop::get('class.product'); $productClass-&gt;save($product);  //load product id $query = $db-&gt;getQuery(true); $query-&gt;select('product&#95;id') -&gt;from('#&#95;&#95;hikashop&#95;product') -&gt;where('product&#95;code = &quot;'.$code.'&quot;'); $db-&gt;setQuery($query); $results = $db-&gt;loadObjectList();  $product&#95;id = $results&#91;0&#93;-&gt;product&#95;id;  $productClass-&gt;save($product);  hi, i used this code to insert product into hikashop, however it's restrictly only for insert &#91;new product&#93;, if product exists then it skipped the product  is there anyway to make it update the product if it's exists? &#91;name, quantity, description, etc&#93;  i have tried $productClass-&gt;refreshQuantities(); but it doesnt do anything")*

The system already handle automatically update/insert based on whether the product_id is provided.
With the code from your first message, you just need to add such line: Code:

$product-&gt;product_id = $product_id;

before the last save.

The following user(s) said Thank You: [veeco](/forum/user/18501-veeco "View veeco's Profile")

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzMyLWNvbnRlbnQtY3JlYXRpb24vODc4ODcwLWhvdy10by11cGRhdGUtcHJvZHVjdHMtZGF0YS11c2luZy1hcGk/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.185 seconds

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

[](#top)
