Jump to content

Add a sortable Latest Product checkbox on Admin Product Inventory

Claudia M

Recommended Posts

I am trying to add a sortable checkbox for latest products on the product inventory page in admin.  I change my latest products frequently and want to keep track of them.  I can get the checkbox to show up, I just can't get it to work. 


I've added this so the checkbox doesn't take up a lot of room on the product inventory page



               <th nowrap="nowrap">&nbsp;</th>

               <th nowrap="nowrap">{$THEAD.name}</th>

               <th nowrap="nowrap">LP</th>

               <th nowrap="nowrap">{$THEAD.image}</th>


A few lines later I put this

 <span class="light-category">{$product.category}</span>




                      <td style="text-align:center"><input type="hidden" name="latest" id="product_latest" class="toggle" value="{$PRODUCT.latest}"></td>


               <td style="text-align:center">

                  {if !empty($product.image_path_tiny)}


I know I need to put something like this in the source file to make it sortable but I need to get it to work first


 // Sorting

    $current_page = currentPage(array('sort'));

    if (!isset($_GET['sort']) || !is_array($_GET['sort'])) {

        $_GET['sort'] = array('updated' => 'DESC');


    $thead_sort = array(

        'status'   => $GLOBALS['db']->column_sort('status', $lang['common']['status'], 'sort', $current_page, $_GET['sort']),

        'digital'   => $GLOBALS['db']->column_sort('digital', $lang['common']['type'], 'sort', $current_page, $_GET['sort']),

'product_latest'   => $GLOBALS['db']->column_sort('product_latest', $lang['catalogue']['type'], 'sort', $current_page, $_GET['sort']),


The checkbox won't stay checked and I didn't want to go any further and mess everything up.


Thanks for any and all help


Link to comment
Share on other sites

In the $thead_sort array of the admin script, please try:

'product_latest' => $GLOBALS['db']->column_sort('latest', 'LP', 'sort', $current_page, $_GET['sort']),

Then, in the <thead> block of the admin skin template, use:

 <th nowrap="nowrap">{$THEAD.product_latest}</th>

In the corresponding slot in the group of <td> cells, use:

<td align="center"><input type="hidden" name="latest[{$product.product_id}]" id="latest_{$product.product_id}" value="{$product.latest}" class="toggle"></td>

Then, finally, back in the script, to process the checkboxes for being in the Latest Products group:


if (isset($_POST['status']) && is_array($_POST['status']) && Admin::getInstance()->permissions('products', CC_PERM_EDIT)) {
    // Update Status
    foreach ($_POST['status'] as $product_id => $status) {
        $GLOBALS['db']->update('CubeCart_inventory', array('status' => $status), array('product_id' => $product_id));

Add after:

    if (isset($_POST['latest']) && is_array($_POST['latest']) && Admin::getInstance()->permissions('products', CC_PERM_EDIT)) {
        // Update Latest Product state
        foreach ($_POST['latest'] as $product_id => $state) {
            $GLOBALS['db']->update('CubeCart_inventory', array('latest' => $state), array('product_id' => $product_id));


Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Create New...