When order_details are being inserted from teh REST API, Sunrise API validates that the product_id exists, 


if not , the API will create the product automatically using hte price and description comming from the order detail in the data source.


THis is basically to avoid the order details are lost while importing orders from different data sources.


However there are some advanced settings which allow you to define the rules to AUTO-GENERATE a product id:


These are the 4 settings :

 

PRODUCT_ID_PREFIX: This is the prefix to be used when inserting the product_id , need to be set as the Channel Attribute value, is an alphanumeric setting for example ‘KA’

 

PRODUCT_ID_COUNTER: This is an integer number that will be used to increase the product_id, this need to be set in the Channel Attrib counter field in the settings.

 

VALID_PRODUCTID_PREFIX: This is a comma separated list of valid prefixes to be used as SKU , The coma separated list for example ‘AA, BB, CCC’ needs to be set as the Channel Attribute value  if this setting is present, then the API validates that the prefix of the SKU should be in the list to be accepted, if not it will go to validate on EAN .

ALLOW_NUMERIC_PRODUCTIDWhen  = NO or channel setting is not existing, and SKU in data feed is only Numeric go to step 2 and validate on EAN code.


Internal Logic and validation of the function:


  1. Check on SKU: 


if VALID_PRODUCTID_PREFIX is available and not empty then we check if the provided SKU in the data feed has any of the valid prefixes set in the setting.


If yes;

Check if the SKU is known as a product.product_id in Sunrise >

YES Return product.product_id .

NO:  

        Insert product, set product.product_id = SKU , set ean_product = EAN in data feed (or 00000000000 if not in data feed) , set product_id_api = productID in data feed.

      Return product.product_id .


ELSE:


If channel setting “ALLOW_NUMERIC_PRODUCTID” = NO or channel setting is not existing, and SKU in data feed is only Numeric go to step 2.

             IF “ALLOW_NUMERIC_PRODUCTID” = YES

Check if the SKU is known as a product.product_id in Sunrise >

YES Return product.product_id .

NO:  

        Insert product, set product.product_id = SKU , set ean_product = EAN in data feed (or 00000000000 if not in data feed) , set product_id_api = productID in data feed.

      Return product.product_id .

                      2) Check on EAN 

                        Do we have EAN code in the data feed?

                       <

                        NO:  go to step 3.


                       YES:

                       

                             Check if EAN is known using product.ean_product ?

                            YES:  Return product.product_id .

                            NO:  

                                    Insert product, set product_id = AUTO-GENERATED product_id , set ean_product = EAN in data feed, set                                      product_id_api = productID in data feed.

                                    Return product.product_id .

                       >    


                    3) Check on productID = product_id_api

                           <

                             Is there  is a product with product_id_api = productID in data feed?

                               YES:  Return product.product_id .

                               NO: 

                               Insert product, set product_id = AUTO-GENERATED product_id , set ean_product = EAN in data feed (or                                        00000000000 if not in data feed) , set product_id_api = productID in data feed.

                           Return product.product_id .

                          >