Ajax Re-Render Block

Hi there..

I am creating my own custom filters UI for the customer to interact with. The tags I am using are using cm-ajax to mark the filter as selected. The AJAX request is working, however, I think I am overlooking some part of the AJAX workflow and its not making sense.

When the AJAX request comes into my controller, I am handling it accordingly and using assignHtml to update the webpage. The template that I am rendering when the page first loads displays all the filters that the customer can select. However when I use assignHtml to render this same template again, I am not getting any filters displaying. The filters render initallialy as the template is part of my layout and receives a list of ALL filters as the filling type.

So I guess I want to know how I can re-render a block with its associated schema, rather than just the template file itself (which will not have any data from its filling method).

Is this possible..

Cheers..

Would have to see your code. Cs-cart doesn't use standard ajax actions/notification. They use their own JS that expects to see the id being updated as a comment just before the closing tag of the updated html. If it's not there, it won't be seen. Take a look at templates for other ajax requests and you'll see how they use both 'result_ids' and the commented id values. It's a bit hokey but it does make it simple to re-render existing pages that can use the new logic of assigned template variables.

Hi..

Thanks.. yep, I have been using result ids in the past and have no issues with them. This is the first time that I have triggered an ajax call from an tag. The controller is triggered from the ajax links in 'header_search_filters.tpl'.. so effectively I need it to update itself. here is my controller code:

    list($products, $params) = fn_get_products(array());
    Registry::get('ajax')->assign('productCount', count($products));
    Registry::get('ajax')->assignHtml('headerSearchFilters', Registry::get('view')->fetch('addons/my_changes/blocks/product_filters/header_search_filters.tpl'));

here is my template file:

    {foreach from=$items item="filter" name="filters"}
    {if $filter.filter_id == 26}    
  
    {math equation="floor(100/x)" x=$filter.ranges|@count assign="cell_width"}
  
    {foreach from=$filter.ranges item="range"}
  
      {assign var="info" value="_"|explode:$range.range_name }
      {assign var="start" value=$info[0]}
      {assign var="end" value=$info[1]}
      
      {if "R`$range.range_id`"|fn_my_changes_filter_range_selected}
        {assign var="range_class" value="shop-by-range-selected"} 
      {else}
        {assign var="range_class" value="shop-by-range-deselected"}
      {/if}
  • {$start}mm {if $end}-{/if} {$end|default:"+"}{if $end}mm{/if}
  • {/foreach} {/if} {/foreach}

    my template adds to the blocks schema with the following:

    $schema['product_filters']['templates']['addons/my_changes/blocks/product_filters/header_search_buttons.tpl'] = array ('fillings' => array ('filters','all'));
    

    The first time my template loads, it displays the filters. What I want to happen is that when a user selects one of the filters is that the ajax request is made to my controller which results in the filter being marked as selected on the server and the template renders again with a visual change by changing the CSS class on the tag for the respective filter..

    So it all works, expect when the controller renders the template the second time around, I get no filters assigned to it. So the result id's are working, but its more the block content that is not working..

    I hope that makes sense

    We suggest you to use standard behavior with the result_ids feature. To specify it for the simple link, please use the data-ca-target-id parameter. E.g.

    {$start}mm {if $end}-{/if} {$end|default:"+"}{if $end}mm{/if}
    

    oh - thank you..

    i must have been looking at old cs-cart docs when I saw the 'rev' approach. Works fine now. Although the docs you are point me at are 4.3.x and I am running 4.2.4. Anyway, I will not argue :)

    Thanks again... was tearing my hair out and I have none already..

    **UPDATE**

    It appears to be working because of cm-ajax-full-render. I am not sure why cm-ajax-full-render was not working in this manner when i was using the 'rev' approach. If I take out cm-ajax-full-render, it doesn't work . The block renders as before, but there is no block content (i.e. filters) being shown.

    I must be confused about this is meant to operate.

    My controller has no view associated with it, how are you meant to handle your return from the ajax request in this case?

    Anyway, at least it works for now.. thankyou.

    Where did you learn this tiny but very important thing?

    They use their own JS that expects to see the id being updated as a comment just before the closing tag of the updated html. If it's not there, it won't be seen. Take a look at templates for other ajax requests and you'll see how they use both 'result_ids' and the commented id values. It's a bit hokey but it does make it simple to re-render existing pages that can use the new logic of assigned template variables.

    Where did you learn this tiny but very important thing?

    Please take a look here

    https://docs.cs-cart.com/latest/developer_guide/core/front-end/ajax.html#reloading-containers-via-ajax

    Just wait till you try to extend the new checkout with all the undocumented attributes that are now used to generate ajax calls since there's no more posted update of data till you get to the submit.

    Thanks a lot

    Please take a look here

    https://docs.cs-cart.com/latest/developer_guide/core/front-end/ajax.html#reloading-containers-via-ajax

    You are welcome :)