Jump to content
st.ankit

Add Product using web-service with Product Features

Recommended Posts

Hello,

 

I’m trying to store Product with Feature using Prestashop Webservice API. I’m using following end-points for this process.

 

Product insert - http://localhost/prestashop_16/api/products?schema=synopsis

Feature Value- http://localhost/prestashop/api/product_feature_values?schema=synopsis

 

I tried following two ways:

 

Try 1

 

Step 1- First Add feature value with following request.

 

URL : http://localhost/prestashop/api/product_feature_values?schema=synopsis

 

Request Body :

<prestashop xmlns:xlink="http://www.w3.org/1999/xlink">
<product_feature_value>
<id_feature required="true" format="isUnsignedId">1</id_feature>
<custom format="isBool">1</custom>
<value required="true" maxSize="255" format="isGenericName">
<language id="1" xlink:href="http://localhost/prestashop_16/api/languages/1" format="isUnsignedId">My Feature from web service</language>
</value>
</product_feature_value>
</prestashop>

Result:

1. Entries are made in  'feature_value' and 'feature_value_lang' tables but not in feature_product

2. I got the returnid of id_feature_value.

 

STEP 2-

 

I use the return id of id_feature_value in this products API:

 

URL : http://localhost/prestashop_16/api/products?schema=synopsis

Request Body :

<?xml version="1.0" encoding="UTF-8"?>
<prestashop xmlns:xlink="http://www.w3.org/1999/xlink">
<product> 
<price required="true" format="isPrice">1100</price> 
<link_rewrite required="true" maxSize="128" format="isLinkRewrite"><language id="1" xlink:href="http://localhost/prestashop_16/api/languages/1" format="isUnsignedId" >www.ankit_100.com</language></link_rewrite>
<name required="true" maxSize="128" format="isCatalogName"><language id="1" xlink:href="http://localhost/prestashop_16/api/languages/1" format="isUnsignedId" >External Hard disk</language></name>
<associations>

<product_features node_type="product_features">
<product_features>
<id required="true">1</id>
<custom>1</custom>
<id_feature_value >1</id_feature_value>
</product_features>
</product_features>
</associations>
</product>
</prestashop>

Result- Entries are made in feature_product and feature_value, but not in feature_value_lang

 

Try 2

 

Add all the param in single request :

 

URL : http://localhost/prestashop_16/api/products?schema=synopsis

 

Request Body :

<?xml version="1.0" encoding="UTF-8"?>
<prestashop xmlns:xlink="http://www.w3.org/1999/xlink">
<product> 
<price required="true" format="isPrice">1100</price> 
<link_rewrite required="true" maxSize="128" format="isLinkRewrite"><language id="1" xlink:href="http://localhost/prestashop_16/api/languages/1" format="isUnsignedId" >www.ankit_100.com</language></link_rewrite>
<name required="true" maxSize="128" format="isCatalogName"><language id="1" xlink:href="http://localhost/prestashop_16/api/languages/1" format="isUnsignedId" >ankit_104</language></name>
<associations>
<product_features node_type="product_features">
<product_features>
<id required="true">1</id>
<custom>1</custom>
<id_feature_value xlink:href="http://localhost/prestashop_16/api/product_feature_values/" required="true">
<product_feature_values>
<product_feature_value>
<id_feature required="true" format="isUnsignedId">1</id_feature>
<custom format="isBool">1</custom>
<value required="true" maxSize="255" format="isGenericName">
<language id="1" xlink:href="http://localhost/prestashop_16/api/languages/1" format="isUnsignedId">Hello My Feature from web service</language>
</value>
</product_feature_value>
</product_feature_values>
</id_feature_value>
</product_features>
</product_features>
</associations>
</product>
</prestashop>

 

Result : Not getting any feature value in feature_value_lang table.

 

Can anyone pinpoint the mistake in any of above two approaches?

 

Share this post


Link to post
Share on other sites
Posted (edited)

I think the corect way is to fallow steps like this :

Step 1

First Add feature with following request.

url http://localhost/prestashop/api/product_features?schema=blank

Quote

<?xml version="1.0" encoding="UTF-8"?>
<prestashop xmlns:xlink="http://www.w3.org/1999/xlink">
    <product_feature>
        <id></id>
        <position></position>
        <name>
            <language id="1"></language>
        </name>
    </product_feature>
</prestashop>

 

Need to complet just <language> tag with Name of attribute i put a exemple :

Quote

<?xml version="1.0" encoding="UTF-8"?>
<prestashop xmlns:xlink="http://www.w3.org/1999/xlink">
    <product_feature>
        <id></id>
        <position></position>
        <name>
            <language id="1">Power</language>
        </name>
    </product_feature>
</prestashop>

 

response return :

Quote

<?xml version="1.0" encoding="UTF-8"?>
<prestashop xmlns:xlink="http://www.w3.org/1999/xlink">
    <product_feature>
        <id>
            <![CDATA[4]]>
        </id>
        <position>
            <![CDATA[3]]>
        </position>
        <name>
            <language id="1" xlink:href="http://ochelari7.local/api/languages/1">
                <![CDATA[Power]]>
            </language>
        </name>
    </product_feature>
</prestashop>

 

Pick id response => exemple 4 and use it in next step

 

Step 2

URL : http://localhost/prestashop/api/product_feature_values?schema=blank

Quote

<?xml version="1.0" encoding="UTF-8"?>
<prestashop xmlns:xlink="http://www.w3.org/1999/xlink">
    <product_feature_value>
        <id></id>
        <id_feature></id_feature>
        <custom></custom>
        <value>
            <language id="1"></language>
        </value>
    </product_feature_value>
</prestashop>

 

Need to complet <language> tag with value of attribute and id_feature with id from step 1 <custom> tag can be complet with 0 or 1.

0 means in back office will view in select field and can be easy reused

1 means can't be reuse in back office

 exemple :

Quote

<?xml version="1.0" encoding="UTF-8"?>
<prestashop xmlns:xlink="http://www.w3.org/1999/xlink">
    <product_feature_value>
        <id></id>
        <id_feature>4</id_feature>
        <custom>1</custom>
        <value>
            <language id="1">1000W</language>
        </value>
    </product_feature_value>
</prestashop>

 

response return :

Quote

<?xml version="1.0" encoding="UTF-8"?>
<prestashop xmlns:xlink="http://www.w3.org/1999/xlink">
    <product_feature_value>
        <id>
            <![CDATA[49]]>
        </id>
        <id_feature xlink:href="http://ochelari7.local/api/product_features/4">
            <![CDATA[4]]>
        </id_feature>
        <custom>
            <![CDATA[1]]>
        </custom>
        <value>
            <language id="1" xlink:href="http://ochelari7.local/api/languages/1">
                <![CDATA[1000 W]]>
            </language>
        </value>
    </product_feature_value>
</prestashop>

 

Pick id response => exemple 49 and use it in next step

Step 3

Create product with attribute selected

Have two id attribute from  

Step 1 : id feature attribute

Step 2  : id feature attribute value

I will pick requst demo from top of post and i will complet it with values for exemple :

Quote

<?xml version="1.0" encoding="UTF-8"?> <prestashop xmlns:xlink="http://www.w3.org/1999/xlink">

<product>

<price required="true" format="isPrice">1100</price>

<link_rewrite required="true" maxSize="128" format="isLinkRewrite">

    <language id="1" xlink:href="http://localhost/prestashop_16/api/languages/1" format="isUnsignedId" >www.ankit_100.com</language>

</link_rewrite>

<name required="true" maxSize="128" format="isCatalogName">

    <language id="1" xlink:href="http://localhost/prestashop_16/api/languages/1" format="isUnsignedId" >ankit_104</language>

</name>

<associations>

    <product_features nodeType="product_feature" api="product_features">
                <product_feature>
                    <id required="true">4</id>
                    <id_feature_value xlink:href="http://ochelari7.local/api/product_feature_values/" required="true">49</id_feature_value>
                </product_feature>
    </product_features>

</associations>

</product>

</prestashop>

 

Edited by rcopenhagen (see edit history)

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...

Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More