Ajax - load products in category page

hi
I changed some code for test ajax request load products in category page.

categories.php mode view 
....
  // New 2024
  if (defined('AJAX_REQUEST')) {

    [$products, $search] = fn_get_products($params, Registry::get('settings.Appearance.products_per_page'), CART_LANGUAGE);

    // New 2023 - validate page 
    $valid_page = db_get_valid_page($search['page'], $search['items_per_page'], $search['total_items']);

    if ($search['page'] > $valid_page) {
        $_REQUEST['page'] = $valid_page;

        return [CONTROLLER_STATUS_REDIRECT, Registry::get('config.current_url')];
    }

    /*if (isset($search['page']) && ($search['page'] > 1) && empty($products)) {
        return [CONTROLLER_STATUS_REDIRECT, Registry::get('config.current_url')];
    }*/

    fn_gather_additional_products_data($products, [
        'get_icon' => true,
        'get_detailed' => true,
        'get_additional' => true,
        'get_options' => true,
        'get_discounts' => true,
        'get_features' => false
    ]);

    $show_no_products_block = (!empty($params['features_hash']) && !$products);

    fn_filters_handle_search_result($params, $products, $search);

    Tygh::$app['view']->assign('show_no_products_block', $show_no_products_block);
    Tygh::$app['view']->assign('is_selected_filters', !empty($params['features_hash']));

    $selected_layout = fn_get_products_layout($_REQUEST);
    Tygh::$app['view']->assign('show_qty', true);
    Tygh::$app['view']->assign('products', $products);
    Tygh::$app['view']->assign('search', $search);
    Tygh::$app['view']->assign('selected_layout', $selected_layout);
  }
  // End New
....

category view.tpl page

....
<div id="products_block_{$block.snapping_id}">
{if !$products && $category_data.product_count > 0}
    <div class="preloading" style="height: 400px;"></div>
{/if}
{if ($products && $category_data.parent_id != 0) || ($products && $category_data.category_id == 332)}
    <h2 id="products"{* class="new-label"*}>
        <i class="icon-menu-three valign"></i>
		{__("products")} {__("cat")}: {$category_data.category nofilter}
	</h2>
    <hr />
    <div id="content_products">
        {if $smarty.request.advanced_filter}
			{include file="views/products/components/product_filters_advanced_form.tpl" separate_form=true}
        {/if}
        <div id="category_products_{$block.block_id}">
			{$layouts = ""|fn_get_products_views:false:0}
			{if $products}
			    {if $category_data.product_columns}
				    {$product_columns = $category_data.product_columns}
			    {else}
				    {$product_columns = $settings.Appearance.columns_in_products_list}
			    {/if}

			    {if $layouts.$selected_layout.template}
					{include file="`$layouts.$selected_layout.template`" columns=$product_columns}
				{/if}
			{elseif !$subcategories || $show_no_products_block}
				<p class="no-items cm-pagination-container">{__("text_no_products")}</p>
			{else}
				<div class="cm-pagination-container"></div>
			{/if}
            {hook name="categories:view_products"}{/hook}
        <!--category_products_{$block.block_id}--></div>
    </div>
{/if}
<!--products_block_{$block.snapping_id}--></div>
....
....
{$index_url = $create_url|fn_url}
<script>
(function (_, $) {
  $(_.doc).ready(function () {
    var indexUrl = '{$index_url}';
    $.ceAjax('request', indexUrl, {
      cache: false,
      result_ids: 'products_block_{$block.snapping_id}',
      full_render: 'Y',
      hidden: false
    });
  });
})(Tygh, Tygh.$);
</script>

This is working fine when users logged in, but return empty when users not logged in.
What is the cause of the problem?

Response with Auth

current_url	"/test"
is_theme_editor_allowed	false
html	Object { products_block_96: ' <h2 id="products"> <i class="icon-menu-three valign"></i>\n\t\t\n\t</h2> <hr /> <div id="content_products"> <div id="category_products_10"> <script src="/js/tygh/exceptions.js?v=1734192802" ></script><div class="pagination-container cm-pagination-container" id="pagination_contents"><div class="hidden"><a data-ca-scroll=".cm-pagination-container" href="" data-ca-page="" data-ca-target-id="pagination_contents" class="hidden"></a></div><div class="sort-container">…n-container" href="/test/page-153" data-ca-page="153" class="cm-history next cm-ajax" data-ca-target-id="pagination_contents" title="total pages">153</a><a data-ca-scroll=".cm-pagination-container" href="/test/page-2" data-ca-page="2" class="next cm-history cm-ajax" data-ca-target-id="pagination_contents" title="next"><i class="icon-arrow-right"></i></a></div></div><!--pagination_contents--></div> <!--category_products_10--></div> </div> ' }
title	"test category page"
notifications	[]

Response without Auth

current_url	"/test"
is_theme_editor_allowed	false
html	Object { products_block_96: '   ' }
title	"test category page"
notifications	[]

What could be the reason for receiving empty data from Ajax requests without user Auth?

@CS-Cart_team , Is this a system bug? Or is there a specific reason and I missed something?

I don’t think any issue generated by third party code can be called a “system bug” :slight_smile:

As for the issue, I’m afraid that this one requires debugging, without seeing the picture as a whole, I cannot say anything.