X-Cart: shopping cart software

X-Cart forums (https://forum.x-cart.com/index.php)
-   Dev Questions (X-Cart 5) (https://forum.x-cart.com/forumdisplay.php?f=56)
-   -   Using API to add products AND attributes (https://forum.x-cart.com/showthread.php?t=72828)

cjipaygo 09-24-2015 05:29 AM

Using API to add products AND attributes
 
I've been integrating our retail solution to X-Cart 5 using the API.

I've found that this constructed URL creates a product for X-Cart:

https://mysite.com/xcart-5/xcart/admin.php?target=RESTAPI&_key=my-5-xcart-api&_path=product/0&_method=post&model[sku]=990e90e&model[enabled]=1&model[freeShip]=FALSE&model[price]=25&model[salePriceValue]=&model[participateSale]=0&model[inventory][amount]=6&model[translations][0][code]=en&model[translations][0][name]=A%20Tasty%20Merlot%20&model[translations][0][briefDescription]=One%20of%20the%20bests&model[translations][0][description]=It%27s%20really%20good%2E%20

But does anyone know how to construct a URL that also adds the attributes (Like different sizes and colors)?

Thanks,

Chris

qualiteam 09-24-2015 09:24 PM

Re: Using API to add products AND attributes
 
Hello Chris,

You may use the developer tools built into your browser to check what parameters are sent to the server when you add a product with options. The actual URL format depends on your attributes.

Also you may look into using the REST API module:
https://www.x-cart.com/extensions/addons/rest-api.html

cjipaygo 09-25-2015 04:54 AM

Re: Using API to add products AND attributes
 
Than you for answering. I am using the rest api and was hoping you had an example of how the url might be constructed WITH attributes. As you can see, my example is using the rest api and is constructed to add a product.

cjipaygo 10-07-2015 08:37 AM

Re: Using API to add products AND attributes
 
I tried using Chrome's developer tools but am not seeing any way to see what is being sent to X-Cart.

Do you know if anyone is using the API in 5 to add attributes to products?

qualiteam 10-07-2015 08:41 PM

Re: Using API to add products AND attributes
 
Hello,

I think it is impossible to construct a single URL that would add a product with attributes. You should use several API requests and a) add the product b) add attributes c) link attributes with the product.

cjipaygo 10-08-2015 12:48 PM

Re: Using API to add products AND attributes
 
Ok... I can accept that.

So, do you have any examples of what the URLs would have to look like to add an attribute for a product that has been uploaded?

Thanks.

qualiteam 10-08-2015 11:04 PM

Re: Using API to add products AND attributes
 
It depends on the attributes and whether you have these attributes in the database, or no.

Here are tables that X-Cart 5 uses to store attributes:
- xc_attributes - stores the list of all available attributes and their identifiers
- xc_attribute_translations - stores names of attributes, linked to the xc_attributes table
- xc_attribute_values_text - links products with values for their text attributes
- xc_attribute_values_text_translations - stores the actual values for text attributes, linked to xc_attribute_values_text
- xc_attribute_values_сheckbox - links products with values for their checkbox attributes
- xc_attribute_options - links regular attributes (the ones that look as a select box) with identifiers of possible values for these attributes
- xc_attribute_option_translations - stores actual text names for possible values of regular attributes, links to xc_attribute_options
- xc_attribute_values_select - links products with regular attributes and values selected for these attributes for these products (xc_attribute_options table)

If you use attribute groups, you may need to update extra tables.

So, you should update/create records in these tables by using a set of subsequent request.

You can find an example of doing a similar request to link an existing product with an existing category here:
http://kb.x-cart.com/display/XDD/REST+API+documentation#RESTAPIdocumentation-Assigningaproducttoacategory

It inserts a new link between xc_products and xc_categories table into the xc_product_categories table. You should do a similar thing for the tables that I listed above.


All times are GMT -8. The time now is 07:30 AM.

Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.