Posted in

Cs-Cart admin pagination

Notes on how pagination is done in admin section of cs-cart.

In the controller:

if ($mode == 'under') {

    $params = $_REQUEST;
    $params['paginate'] = true;
    if (!empty($params['paginate'])) {
        $params['page'] = empty($params['page']) ? 1 : $params['page'];
        $params['total_items'] = db_get_field("HERE GOES THE TOTAL LINES COUNT QUERY", DESCR_SL
        );
        $params['items_per_page'] = $params['items_per_page'] ? $params['items_per_page'] : Registry::get('settings.Appearance.admin_elements_per_page');
        $limit = db_paginate(
            $params['page'], 
            $params['items_per_page']
            );
    }
    $rows = db_get_array("SELECT ...[HERE GOES THE ROW SELECTION QUERY AND limit IS ADDED ON THE END]... $limit", DESCR_SL
    );
    Registry::get('view')->assign('search', $params);
    Registry::get('view')->assign('rows', $rows);
}

In the corresponding view:

{capture name="mainbox"}

{include file="common/pagination.tpl" save_current_page=true save_current_url=true div_id=$smarty.request.content_id} {if $rows} {foreach from=$rows item="row"} {/foreach}
Product Cost Price
{$row.product} {$row.cost} {$row.price}
{else}

{__("no_data")}

{/if}
{include file="common/pagination.tpl" div_id=$smarty.request.content_id}
{/capture} {include file="common/mainbox.tpl" title=__("products_under_cost") buttons=$smarty.capture.buttons sidebar=$smarty.capture.sidebar content=$smarty.capture.mainbox}