- Posts: 7
- Thank you received: 0
How to add the products through API
15 years 9 months ago #3958
by chola
How to add the products through API was created by chola
Hi,
I have a requirement to call your api and insert the products and their details from the custom page.Can you please point me in the right direction.
Regards
Chola
I have a requirement to call your api and insert the products and their details from the custom page.Can you please point me in the right direction.
Regards
Chola
Please Log in or Create an account to join the conversation.
15 years 9 months ago #3959
by nicolas
Replied by nicolas on topic Re: How to add the products through API
We added a code sample for that in our developer's documentation:
www.hikashop.com/support/documentation/6...umentation.html#code
Please Log in or Create an account to join the conversation.
15 years 9 months ago #3969
by chola
Replied by chola on topic Re: How to add the products through API
Thanks for the code snippet.But I would be more interested in adding the product itself.
Idea is to allow the user to sell products and I would need an API to define the product itself from the front end.
Regards
Chola
Idea is to allow the user to sell products and I would need an API to define the product itself from the front end.
Regards
Chola
Please Log in or Create an account to join the conversation.
15 years 9 months ago #3970
by nicolas
Replied by nicolas on topic Re: How to add the products through API
To insert a product you can use something like this (after including the hikashop helper file as mentionned in my previous link):
Code:
$price=null;
$price->price_value = 10;
$price->price_currency_id = 1;
$price->price_price_min_quantity = 0;
$product = null;
$product->product_name = 'my product';
$product->prices = array($price);
$product->categories = array(1, 2); //where 1and 2 are the ids of two categories
$productClass = hikashop::get('class.product');
$productClass->save($product);
Please Log in or Create an account to join the conversation.
15 years 9 months ago #3973
by chola
Replied by chola on topic Re: How to add the products through API
Awesome Thanks..Can you please give and example for the prices array?
Example: I have something like below.
4 Hrs -- $4.99
24 Hrs -- $10.99
5 Days -- $24.99
Regards
Chola
Example: I have something like below.
4 Hrs -- $4.99
24 Hrs -- $10.99
5 Days -- $24.99
Regards
Chola
Please Log in or Create an account to join the conversation.
15 years 9 months ago #3974
by nicolas
Replied by nicolas on topic Re: How to add the products through API
You can't just add days to prices...
What do you want to do ?
I suppose that you want to have a product with a "delivery" characteristic and several variants, each with a price. That's way more that a few lines of code as you need to handle 5 tables data. Not something that we can provide in a forum. I invite you to read the code in administrator/components/com_hikashop/classes/product.php to look at our code and see our code handling the save of the product information.
You need:
either to create the characteristic (with the values 4hrs, 24hrs, 5days) or not based on your needs.
Then, add that characteristic to the product with the characteristics array.
Then, get the automatically generated variants product_id based on the product_id from the product you just saved.
Also, get the characteristic linked to the each variants via the variant table in order to know which one correspond to which value of your characteristic
Finally, add the corresponding price for each variant directly in the price table.
What do you want to do ?
I suppose that you want to have a product with a "delivery" characteristic and several variants, each with a price. That's way more that a few lines of code as you need to handle 5 tables data. Not something that we can provide in a forum. I invite you to read the code in administrator/components/com_hikashop/classes/product.php to look at our code and see our code handling the save of the product information.
You need:
either to create the characteristic (with the values 4hrs, 24hrs, 5days) or not based on your needs.
Then, add that characteristic to the product with the characteristics array.
Then, get the automatically generated variants product_id based on the product_id from the product you just saved.
Also, get the characteristic linked to the each variants via the variant table in order to know which one correspond to which value of your characteristic
Finally, add the corresponding price for each variant directly in the price table.
Please Log in or Create an account to join the conversation.
15 years 9 months ago #3975
by chola
Replied by chola on topic Re: How to add the products through API
Yeah Got it..I will look into the file and find out how the save happens with characteristics.
Thanks for helping me out..It is awesome support
Regards
Chola
Thanks for helping me out..It is awesome support
Regards
Chola
Please Log in or Create an account to join the conversation.
Time to create page: 0.185 seconds