API advice on creating digital product

  • Posts: 13
  • Thank you received: 0
8 years 6 months ago #256834

-- HikaShop version -- : 2.6.4
-- Joomla version -- : 3.6.4

So looking through the forum and reading the API docs, I think I understand how to create a new product with the API. Here's my code...

$price = new stdClass();
$price->price_value = 99.99;
$price->price_currency_id = 1;
$price->price_price_min_quantity = 0;

$product = new stdClass();
$product->product_name ='fileA';
$product->product_quantity = -1;
$product->product_published = 1;
$product->product_weight = 0;
$product->product_type = "main";
$product->product_msrp = 4.99;
$product->product_access = "all";
$product->prices = [$price];
$product->categories = [1];

$productClass = hikashop_get('class.product');
$productId = $productClass->save($product);

$productClass->updateCategories($product,$productId);

So while a new product is created (I can see it in the database), it is not displayed in the back end hikashop products listing. Also I note that there is a table "hikashop_file" that gets stuffed with some digital download info. Is there some API i should be calling to update that database table as well? Please tell me what I'm doing wrong.

Please Log in or Create an account to join the conversation.

  • Posts: 83993
  • Thank you received: 13605
  • MODERATOR
8 years 6 months ago #256843

Hi,

The fact that you see the product in the database but not in the backend indicates that there is a problem with the link between the category and the product.
For example, if the product is not added to a category, or is added to a non existent one, it won't display in the backend.

In your case, I guess that the problem comes from the line:

$product->categories = [1];
You use the category_id 1 which is the root category id. And when you arrive on the products listing in your backend, you're in the "product categories" category, so you're already under the root category and thus it's normal that you don't see the products directly under the root category.
You should use another id, like "2" which is the id of the "product categories" category, if you didn't modify your category tree structure too much.

For the files, you can do like that:
// add file entry to the hikashop_file table
$file = new stdClass();
$file->file_path = 'myfilename.jpg'; // make sure that your file is in the safe upload folder of HikaShop
$file->file_type= 'file';
$fileClass = hikashop_get('class.file');
$file_id = $fileClass->save($file);
$product->files= array($file_id);
$productClass->updateFiles($product,$productId,'files');
It's roughly the same process for product images.

Please Log in or Create an account to join the conversation.

  • Posts: 13
  • Thank you received: 0
8 years 6 months ago #256950

Thanks for the great support. I am now successfully adding products through the API. couple of wrinkles remain. Here's a screen shot of a product I have added.


I then use the following code to add the product to the customer's cart... but as the attached screen shot shows, the "product name" field is blank. Why is this happening? What am I doing wrong?

There's also an "#" column with a live link but when I click on that I get a couple of error messages and the error message... "You are not authorized to see this resource". This seems odd.

Would be grateful for your help.

Attachments:

Please Log in or Create an account to join the conversation.

  • Posts: 83993
  • Thank you received: 13605
  • MODERATOR
8 years 6 months ago #256955

Hi,

The empty name is normal as that's the name of your cart. You can see it in the cart_name column of the hikashop_cart table.
If you fill it in, you'll see it there.
You normally don't need a cart name for your carts since on 99% of websites, you only want one cart per user and thus you have the "multicart" setting turned off in the HikaShop configuration.

The cart page not displaying is probably a bug that we fixed last week. Download again the install package on our website and install it on yours and it should fix that.

The following user(s) said Thank You: boxcarmib

Please Log in or Create an account to join the conversation.

  • Posts: 13
  • Thank you received: 0
8 years 6 months ago #256996

Great support! The latest version fixed the problem I was having.

ONE LAST THING!.... the hikashop website seems to be blocking my IP.... I can access the site from a coffee shop or a friends house, but no luck at all when I'm at my office... can you unblock me? or am i imagining things?

This message contains confidential information

Please Log in or Create an account to join the conversation.

  • Posts: 26253
  • Thank you received: 4040
  • MODERATOR
8 years 6 months ago #257042

Hi,

You IP has been unban.
It looks like we found a little bug in the "preview" feature of Kunena which generate wrong 404 links and trigger our security rules.

Sorry for the inconvenient.

Regards,


Jerome - Obsidev.com
HikaMarket & HikaSerial developer / HikaShop core dev team.

Also helping the HikaShop support team when having some time or couldn't sleep.
By the way, do not send me private message, use the "contact us" form instead.

Please Log in or Create an account to join the conversation.

  • Posts: 13
  • Thank you received: 0
8 years 6 months ago #257081

Thanks for fixing it! :)

Please Log in or Create an account to join the conversation.

Time to create page: 0.084 seconds
Powered by Kunena Forum