Evgene Karachevtsev
Posts: 12
Joined: Mon Apr 28, 2014 1:12 pm

Post Cart object/array into database

Jakub,

We are working on it and we'll get back to you with the update.

Alex GG
Posts: 0
Joined: Thu Nov 14, 2013 11:11 pm

Post Cart object/array into database

Hi Jakub
This is how I solved this...

But instead of saving the cart array to DB, Im sending this to my email (using sendgrid). In that way I dont need to check DB now and then, I just receive a notification from Gmail App...

Just do a loop in your cart and save every item to a string...then send it either your DB or an email...

Image

Jakub
Posts: 0
Joined: Fri Dec 05, 2014 10:53 pm

Post Cart object/array into database

Ok, Thanks. that is where I was heading too. But now how do you invoke the REST Service POST with the string?

Alex GG
Posts: 0
Joined: Thu Nov 14, 2013 11:11 pm

Post Cart object/array into database

Hi,

Are you using Create database service to post the cart on DB?

If this is the case, dont do any link, just click on JS and create the for loop to save everthing on the string,,,then type

return string_name;

Image

Jakub
Posts: 0
Joined: Fri Dec 05, 2014 10:53 pm

Post Cart object/array into database

I am not sure what you mean by "Create database". I have a REST service that posts into my DB (not Aperio db). In the screen capture above you are creating the loop on one of the REST service Request fields and saving all fields from the string?

In the image below is my service request. It is linked to the cart at the moment and inserts the first record only. Are you saying that I should select one of those fileds and loop through the cart array and post the string?
Image

Alex GG
Posts: 0
Joined: Thu Nov 14, 2013 11:11 pm

Post Cart object/array into database

Ok, I guess you where using appery DB.

Yes you are right, try removing all links...and select one field on the right side, and loop through the cart array, and the use "return"

when you use Apperyio.storage.cart.get() you dont need any link, because you are reading from storage...

Of course, you are going to receive all the cart items as an string in that particular field of your database,,,if this is not what you want, you should try other way,,,

Jakub
Posts: 0
Joined: Fri Dec 05, 2014 10:53 pm

Post Cart object/array into database

I understand that, but I am thinking that if I loop and return the entire cart string into one Request field of the Service, the entire string will get posted into THAT field in the database, no?
I need each field in the cart posted in the corresponding field in the service/database

Alex GG
Posts: 0
Joined: Thu Nov 14, 2013 11:11 pm

Post Cart object/array into database

you ́re right,,then you need to try the other way...

Hope Appery team help you with that..

Jakub
Posts: 0
Joined: Fri Dec 05, 2014 10:53 pm

Post Cart object/array into database

What is the "other way"? :)

I would suspect that this must be a very common scenario.
Have a shopping cart (list of items) and post them back to backend database.

Appery.io should be able to handle it "out of the box".

Is there a solution?

Thanks

Jakub
Posts: 0
Joined: Fri Dec 05, 2014 10:53 pm

Post Cart object/array into database

Ok, I am trying to address it from the "other way"
I am invoking the service from JS (see below)

But it throws error even when I hardcode the JSON data. What is the proper format to submit for a POST?

Code: Select all

// Get cart 
 var cart = Apperyio.storage.cart.get() || []; 
 var KitID= Apperyio.storage.KitID.get(); 
 var text=""; 

     //Loop through all cart items 
     for (var i = 0; i < cart.length; i++) 
     { 
         var currItem = cart[i]; 
         text='{"Kit_ID":' + KitID + ',"method_id":' + cart[i].id + ',"Matrix":' + cart[i].Matrix + '}'; 
         alert(text); 
                     svcPostKitdetail.execute({ 
             data:{"Kit_ID":19,"Method_ID":549},                                        
             headers:{} 
         }); 

       //       svcPostKitdetail.execute({ 
       //  data:{"'Kit_ID":KitID,"method_id":cart[i].id,"Matrix":cart[i].Matrix },       
       //  headers:{} 
    // }); 

     }

Return to “Issues”