Problems, need help? Have a tip or advice? Post it here.
5 posts Page 1 of 1
EDIT #1: I forgot to mention, I am using Setting repeatable-regions data through cms:db_persist_form concept which mentions:
we can also explicitly set them through direct parameters of <cms:db_persist_form> (and its non-DBF counterpart <cms:db_persist>) tag

But I am unable to achieve the same with <cms:db_persist>

Good Evening to All and KK Sir.

I am trying to save data to repeatable region by an ajax call. The data gets saved else where (i have a textarea set to check if data is getting stored), but not in the repeatable region.

My AJAX code is:
Code: Select all
var cart_data = '[<cms:pp_cart_items>{"ordered_product":"<cms:show id />","ordered_quantity":"<cms:show quantity />","ordered_price":"<cms:number_format price />"}<cms:incr item_count/><cms:if item_count != "<cms:pp_count_unique_items/>">,</cms:if></cms:pp_cart_items>]';
    $.ajax({
        url: "<cms:show k_site_link />ajax/save-order.php",
        type: 'POST',
   dataType: 'json',
   data: {
       user_id: "<cms:show user_id_for_address />",
       product_in_cart: cart_data,
       order_price: "<cms:show order_price />",
       order_payment_status : "Pending"
   },
   success: function(data){
       window.location.href="<cms:link 'delivery-address.php' />?otid="+data+"&op=<cms:show cashout_amount />"
   },
   error: function(){
       console.log("The request failed");
   }
});


And the code for the save-order.php where the AJAX data is collected and saved to Database is:
Code: Select all
<?php require_once( '../couch/cms.php' ); ?>
   <cms:template title="Save Address at Checkout" parent="_users_" hidden="1" />
   
   <cms:set user_id_save = "<cms:gpc 'user_id' method='POST' />" "global" />
   <cms:set product_in_cart_save = "<cms:gpc 'product_in_cart' method='POST' />" "global" />
   <cms:set order_price_save = "<cms:gpc 'order_price' method='POST' />" "global" />
   <cms:set order_payment_status_save = "<cms:gpc 'order_payment_status' method='POST' />" "global" />

   <cms:if product_in_cart_save ne ''>
   <cms:db_persist
      _masterpage='order.php'
      _mode='create'
                _invalidate_cache='0'
                _auto_title='0'

      k_page_title = "<cms:pages masterpage='users/index.php' id=user_id_save limit='1'><cms:show user_fname /> <cms:show user_lname />-<cms:show user_mobile />-</cms:pages><cms:date format='Y-m-dTH:i:s' />"

      user_id = "<cms:show user_id_save />"      
      order_price = "<cms:show order_price_save />"
      order_payment_status = "<cms:show order_payment_status_save />"
      product_in_cart_json = "<cms:show product_in_cart_save as_json='1' />"
      product_in_cart = "<cms:capture into='my_data' is_json='1'><cms:show_repeatable 'product_in_cart' as_json='1' /></cms:capture ><cms:capture into='my_data.' is_json='1'><cms:show product_in_cart_save as_json='1' /></cms:capture>"
   >
      <cms:if k_error >
           <cms:abort><cms:show k_error /></cms:abort>
      <cms:else_if k_success />
         <cms:abort>
               <cms:show k_last_insert_id />
          </cms:abort>
       </cms:if>
   </cms:db_persist>
</cms:if>
   
<?php COUCH::invoke(); ?>


All data is sent in the ajax call and is saved except for the field data for the repeatable region field: product_in_cart.

My editable for repeatable region are defined as:
Code: Select all
<cms:editable name="shippable_product" label="Shippable Product" type="group" order="3" />
        <cms:editable name="product_in_cart_json" label="JSON" type="textarea" no_xss_check="1" order="1" group="shippable_product" />
        <cms:repeatable name="product_in_cart" label="Order Details" group="shippable_product" order="2" >
            <cms:editable name="ordered_product" label="Ordered Product" type="text" order="1" validator="non_negative_integer" />
            <cms:editable name="ordered_quantity" label="Ordered Quantity" type="text" order="2" />
            <cms:editable name="ordered_price" label="Ordered Price" type="text" order="3" />
        </cms:repeatable>


The data sent from ajax using "product_in_cart" is saved to the textarea "product_in_cart_json" but not in repeatable region "product_in_cart".

Can you please help me understand where is the issue?

Regards,
GenXCoders (Aashish)
Image
where innovation meets technology
Aashish, hope you are well and sound. It looks like you capture json into a variable (please double check that part on your side), but forgot to display it again (right past the two "cms:capture" blocks) for the db_persist part which expects a variable or a text value. Perhaps, a simple <cms:show my_data as_json='1' /> would resolve the saving problem?
@Bro Anton,
I am fine, thanks for asking.
I wish the same for you and your family.

I tried you suggestion:
Perhaps, a simple <cms:show my_data as_json='1' /> would resolve the saving problem?


Nevertheless, with your suggested code in place I could understand that the my_data is empty.

My setup is a bit different from the one in the example.

I have a template checkout.php. This checkout.php template has a button that creates an ajax call. My ajax template (save-order-address.php) takes the data sent and saves it to order.php. In order.php resides the repeatable region. So I checked that if i use the code (as in example):
Code: Select all
<cms:capture into='my_data' is_json='1'>
    <cms:show_repeatable 'my_repeatable' as_json='1' />
</cms:capture >

it doesnot work and my_data is empty.

Secondly, the data sent to save-order-address.php receives same data (ordered items) into two fields, defined as:
Code: Select all
<cms:editable name="shippable_product" label="Shippable Product" type="group" order="3" />
        <cms:editable name="product_in_cart_json" label="JSON" type="textarea" no_xss_check="1" order="1" group="shippable_product" />
        <cms:repeatable name="product_in_cart" label="Order Details" group="shippable_product" order="2" >
            <cms:editable name="ordered_product" label="Ordered Product" type="text" order="1" validator="non_negative_integer" />
            <cms:editable name="ordered_quantity" label="Ordered Quantity" type="text" order="2" />
            <cms:editable name="ordered_price" label="Ordered Price" type="text" order="3" />
        </cms:repeatable>


This in the ajax call is sent to save-order-address.php as:
Code: Select all
product_in_cart: cart_data,

and is collected in save-order-address.php in:
Code: Select all
<cms:set cart_data_save = "<cms:gpc 'product_in_cart' method='POST' />" scope="global" />


But when I try to save cart_data_save it gets saved in the product_in_cart_json editable but not in the repeatable region (defined as: product_in_cart, in the editable sited above).

So I tried the following code:
Code: Select all
<capture into="my_data" is_json="1">
    <cms:pages masterpage='order.php' id=order_temp_id_edit_save >
   <cms:show_repeatable 'product_in_cart' as_json='1' />
    </cms:pages>
</capture>

This code above returns a Blank Array as an output. And my_data with '.' (dot) operator does noting.

I was wondering, if it could be possible, where in, the editable product_in_cart_json value be saved in the my_data.. If yes, how could that be possible, or is there a better approach.

I have PMed you the code zip too. Just in case if you could find the time to go through the approach.

Regards,
Aashish
Image
where innovation meets technology
Bump!!!
Image
where innovation meets technology
Bump!!!
Image
where innovation meets technology
5 posts Page 1 of 1
cron