Jump to content

  • You cannot start a new topic
  • You cannot reply to this topic

Ajax Re-Render Block Rate Topic   - - - - -

 
  • natewallis
  • Senior Member
  • Members
  • Join Date: 11-Jan 13
  • 197 posts

Posted 20 October 2015 - 01:15 PM #1

Hi there.. 

 

I am creating my own custom filters UI for the customer to interact with.  The <a> 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.. 

 

 



 
  • tbirnseth
  • CS Cart Expert
  • Authorized Reseller
  • Join Date: 08-Nov 08
  • 11425 posts

Posted 20 October 2015 - 10:38 PM #2

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.


EZ Merchant Solutions: Custom (USA based) B2B Development, Consulting, Development and Special Projects (get a quote here).
Commercial addons, payment methods and modifications to meet your business and operations needs.


 
  • natewallis
  • Senior Member
  • Members
  • Join Date: 11-Jan 13
  • 197 posts

Posted 21 October 2015 - 04:38 AM #3

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 <a> 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:

<div class="shop-by-item">     
<ul>
      {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}
    <li>  
          <a class="cm-ajax-full-render cm-ajax {$range_class}" rel="nofollow" rev="headerSearchFilters" href="index.php?dispatch=filters.select_single_filter&filter={$filter.filter_id}&range=R{$range.range_id}&filter_return_url={$config.current_url|fn_url|urlencode}">{$start}mm {if $end}-{/if} {$end|default:"+"}{if $end}mm{/if}</a>
              
              </li>
        {/foreach}
          
        {/if}
          
      {/foreach}
          
</ul>     
</div> 

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 <a> 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

 



 
  • eComLabs
  • CS-Cart Expert
  • Authorized Reseller
  • Join Date: 27-Jan 14
  • 19833 posts

Posted 21 October 2015 - 09:26 AM #4

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.

<a data-ca-target-id="my_block_content" class="cm-ajax-full-render cm-ajax {$range_class}" rel="nofollow" rev="headerSearchFilters" href="index.php?dispatch=filters.select_single_filter&filter={$filter.filter_id}&range=R{$range.range_id}&filter_return_url={$config.current_url|fn_url|urlencode}">{$start}mm {if $end}-{/if} {$end|default:"+"}{if $end}mm{/if}</a>

GET A FREE QUOTE | CS-Cart Add-ons | CS-Cart Licenses | CS-Cart Development | CS-Cart Design | Server Configuration | UniTheme and YOUPI
CS-Cart                USD 345     Multi-Vendor              USD 1250    CS-Cart RU                         24500 руб.
CS-Cart Ultimate  USD 775     CS-Cart + YOUPI      USD 545      CS-Cart RU + UniTheme    36000 руб.


 
  • natewallis
  • Senior Member
  • Members
  • Join Date: 11-Jan 13
  • 197 posts

Posted 21 October 2015 - 06:52 PM #5

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.