Jump to content

Add a sortable Latest Product checkbox on Admin Product Inventory


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

  <thead>

            <tr>

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

                  {/if}

               </td>

              

                      <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

Claudia

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:

Find:

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

Hi Ian,

I looked at that and though it is a great plugin I think I have things the way I want now.  I did purchase the Automatic XML Sitemap Generator from you for my new site but it's showing pending.  Is there something I need to do?

Claudia

Link to comment
Share on other sites

Hmmm...

Where did you put this line?

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

And double check where you put the last edit.

Edited by bsmither
Link to comment
Share on other sites

It was where I placed the last code.  I had added other elements and placed this in the middle for some stupid reason.  But it's got my wondering if my other added code is correct.  Should I add foreach on all of them and have two } instead of the one?

 

Here's a partial sample of what I have now:

 // Update Status

    foreach ($_POST['status'] as $product_id => $status) {

        $GLOBALS['db']->update('CubeCart_inventory', array('status' => $status), array('product_id' => $product_id));

    }

      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));

        }

    }

if (isset($_POST['product']) && is_array($_POST['product'])) {

    // Update Product Code

        foreach ($_POST['product'] as $product_id => $product_detail_to_update) {

            if (isset($product_detail_to_update['product_code'])) {

                $GLOBALS['db']->update('CubeCart_inventory', array('product_code' => $product_detail_to_update['product_code']), array('product_id' => $product_id));

            }

         // Update Product Name

            if (isset($product_detail_to_update['product_name'])) {

                $GLOBALS['db']->update('CubeCart_inventory', array('name' => $product_detail_to_update['product_name']), array('product_id' => $product_id));

            }

   

          // Update Product Price

            if (isset($product_detail_to_update['product_price'])) {

                $GLOBALS['db']->update('CubeCart_inventory', array('price' => $product_detail_to_update['product_price']), array('product_id' => $product_id));

            }

                          

         // Update Cost Price

            if (isset($product_detail_to_update['cost_price'])) {

                $GLOBALS['db']->update('CubeCart_inventory', array('cost_price' => $product_detail_to_update['cost_price']), array('product_id' => $product_id));

            }

 

         // Update Item Location  

             if (isset($product_detail_to_update['item_location'])) {

               $GLOBALS['db']->update('CubeCart_inventory', array('item_location' => $product_detail_to_update['item_location']), array('product_id' => $product_id));

           }

Link to comment
Share on other sites

I see nothing wrong with the code you posted above, as long as you also have:

if (isset($_POST['status']) && is_array($_POST['status']) && Admin::getInstance()->permissions('products', CC_PERM_EDIT)) {

''' all the code you posted above ...

        } // finishes - foreach ($_POST['product'] ...
    } // finishes - if (isset($_POST['product']) ...
    httpredir(currentPage());
} // finishes - if (isset($_POST['status']) ...

As you hinted, because you are also updating a number of other data items from the list, with some name changes to the <input> elements, the 'latest' data item can be grouped into the $_POST['product'] array.

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.

Guest
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...