Claudia M Posted May 14, 2022 Share Posted May 14, 2022 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"> </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 Quote Link to comment Share on other sites More sharing options...
bsmither Posted May 14, 2022 Share Posted May 14, 2022 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)); } } Quote Link to comment Share on other sites More sharing options...
Claudia M Posted May 14, 2022 Author Share Posted May 14, 2022 Thank you Brian .... that did it! This should maybe be something that is stock in Cubecart? A lot of people don't really use this for the most current products Quote Link to comment Share on other sites More sharing options...
havenswift-hosting Posted May 14, 2022 Share Posted May 14, 2022 Hi Claudia You should be using our Enhanced Sorting plugin which adds this and a load of other sorting with no core file changes Ian Quote Link to comment Share on other sites More sharing options...
Claudia M Posted May 14, 2022 Author Share Posted May 14, 2022 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 Quote Link to comment Share on other sites More sharing options...
Claudia M Posted May 21, 2022 Author Share Posted May 21, 2022 Hi Brian, I implemented the code above and though I can put the checkmark in the box it does not stay there when I click save. Any suggestions. Quote Link to comment Share on other sites More sharing options...
Claudia M Posted May 21, 2022 Author Share Posted May 21, 2022 It works if I do it from the general information page for the product - but not from the added checkbox on the product inventory page Quote Link to comment Share on other sites More sharing options...
bsmither Posted May 21, 2022 Share Posted May 21, 2022 (edited) 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 May 21, 2022 by bsmither Quote Link to comment Share on other sites More sharing options...
Claudia M Posted May 21, 2022 Author Share Posted May 21, 2022 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)); } Quote Link to comment Share on other sites More sharing options...
bsmither Posted May 21, 2022 Share Posted May 21, 2022 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.