Follow us on Twitter X-Cart on Facebook Wiki
Shopping cart software Solutions for online shops and malls

Using API to add products AND attributes

 
Reply
   X-Cart forums > X-Cart 5 > Dev Questions (X-Cart 5)
 
Thread Tools Search this Thread
  #1  
Old 09-24-2015, 05:29 AM
 
cjipaygo cjipaygo is offline
 

Newbie
  
Join Date: Apr 2009
Posts: 7
 

Default 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
Reply With Quote
  #2  
Old 09-24-2015, 09:24 PM
  qualiteam's Avatar 
qualiteam qualiteam is offline
 

X-Guru
  
Join Date: Dec 2010
Posts: 6,373
 

Default 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
__________________
Alex Solovev,
Qualiteam

---

User manual Video tutorials X-Cart FAQ

You are welcome to press "Thanks" button
if you find this post useful

Click here to learn how to apply patches

X-Cart Extensions
Reply With Quote
  #3  
Old 09-25-2015, 04:54 AM
 
cjipaygo cjipaygo is offline
 

Newbie
  
Join Date: Apr 2009
Posts: 7
 

Default 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.
Reply With Quote
  #4  
Old 10-07-2015, 08:37 AM
 
cjipaygo cjipaygo is offline
 

Newbie
  
Join Date: Apr 2009
Posts: 7
 

Default 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?
Reply With Quote
  #5  
Old 10-07-2015, 08:41 PM
  qualiteam's Avatar 
qualiteam qualiteam is offline
 

X-Guru
  
Join Date: Dec 2010
Posts: 6,373
 

Default 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.
__________________
Alex Solovev,
Qualiteam

---

User manual Video tutorials X-Cart FAQ

You are welcome to press "Thanks" button
if you find this post useful

Click here to learn how to apply patches

X-Cart Extensions
Reply With Quote
  #6  
Old 10-08-2015, 12:48 PM
 
cjipaygo cjipaygo is offline
 

Newbie
  
Join Date: Apr 2009
Posts: 7
 

Default 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.
Reply With Quote
  #7  
Old 10-08-2015, 11:04 PM
  qualiteam's Avatar 
qualiteam qualiteam is offline
 

X-Guru
  
Join Date: Dec 2010
Posts: 6,373
 

Default 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.
__________________
Alex Solovev,
Qualiteam

---

User manual Video tutorials X-Cart FAQ

You are welcome to press "Thanks" button
if you find this post useful

Click here to learn how to apply patches

X-Cart Extensions
Reply With Quote
Reply
   X-Cart forums > X-Cart 5 > Dev Questions (X-Cart 5)


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -8. The time now is 01:14 AM.

   

 
X-Cart forums © 2001-2020