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?