Claudia M Posted April 11, 2020 Share Posted April 11, 2020 Hi, I want to be able to change the product code of an item from the product inventory page in admin without having to open the product and change it from there. Can this be done and if so how. Thanks in advance for any and all help. Claudia Link to comment Share on other sites More sharing options...
bsmither Posted April 11, 2020 Share Posted April 11, 2020 Interesting! I'll get right on it. Link to comment Share on other sites More sharing options...
bsmither Posted April 11, 2020 Share Posted April 11, 2020 The skin edit isn't easily coded into a code snippet, so keep in mind that an upgrade will overwrite it. In the admin skin template products.index.php, near line 78, find: <td>{$product.product_code}</td> Change to: <td><span class="editable number" name="product[{$product.product_id}][product_code]">{$product.product_code}</span></td> The core code edit can be put in a code snippet, but for the purpose of testing this and determining if it works for you, this will be an edit to the core code. In the admin source code products.index.inc.php, near line 627, find: foreach ($GLOBALS['hooks']->load('admin.product.pre_display') as $hook) { include $hook; } After that, add this: if (isset($_POST['product']) && is_array($_POST['product']) && Admin::getInstance()->permissions('products', CC_PERM_EDIT)) { // Update Product Code foreach ($_POST['product'] as $product_id => $product_code) { $GLOBALS['db']->update('CubeCart_inventory', array('product_code' => $product_code), array('product_id' => $product_id)); } httpredir(currentPage()); } When the mouse cursor hovers over the Product Code value, there should be a 'tooltip' that says "Click to Edit". When clicked on, the table cell should change to show a text entry field. Make your changes to the value(s). Click Save. The new value(s) should now be in use. Link to comment Share on other sites More sharing options...
Claudia M Posted April 11, 2020 Author Share Posted April 11, 2020 Thanks Brian I'll implement it asap. I don't mind having to change the skin/product.index ... I have to do it for other stuff anyway. I implemented the code, cleared the cache, and made a change to a product code. It let me change it but when I click on save the change isn't saved even after I clear the cache again. Link to comment Share on other sites More sharing options...
Claudia M Posted April 11, 2020 Author Share Posted April 11, 2020 Can I do something like this in the skin/product.index file without deleting all my current product codes? <td align="center"><input type="text" name="product[{$product.product_id}]" id="product_code_{$product.product_id}" value="{$product.code}" class="textbox" style="width: 50px;" /></td> Link to comment Share on other sites More sharing options...
bsmither Posted April 11, 2020 Share Posted April 11, 2020 The code is first dealing with surveying the Status checkboxes - which are always POSTed. After updating the status of each of the products, the code tells the web browser to reload the page. Thus, surveying POST for any updates to the Product Code, never happens. Since the status codes are always surveyed, we should put the new code inside that. So... Remove the added code from products.index.inc.php. Find near line 489: 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)); } httpredir(currentPage()); } Change to: 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)); } if (isset($_POST['product']) && is_array($_POST['product'])) { // Update Product Code foreach ($_POST['product'] as $product_id => $product_code) { $GLOBALS['db']->update('CubeCart_inventory', array('product_code' => $product_code['product_code']), array('product_id' => $product_id)); } } httpredir(currentPage()); } The nice thing about this "click to edit" is that there is only a database query to UPDATE only those values that changed. To make them a permanent text entry field, then there will be an UPDATE query made for each of the twenty list items. And it won't change the problem just now faced (bouncing after dealing with the Status setting). Practically speaking, there is a better way of processing a POST from the main list. Link to comment Share on other sites More sharing options...
Claudia M Posted April 11, 2020 Author Share Posted April 11, 2020 The changes worked! Thank you Brian Link to comment Share on other sites More sharing options...
Claudia M Posted April 11, 2020 Author Share Posted April 11, 2020 Could a person do basically the same thing with any column in the Product Inventory Admin page? Would it cause any problems? Link to comment Share on other sites More sharing options...
bsmither Posted April 12, 2020 Share Posted April 12, 2020 Basically, yes. As I mentioned earlier, doing any more than that would be a good reason to recode some of both files that were edited. Maybe make a feature request in the Github. Link to comment Share on other sites More sharing options...
havenswift-hosting Posted April 12, 2020 Share Posted April 12, 2020 I agree that this would be a very good addition to core code, so could somebody add a github issue referencing this thread so @Al Brookbanks can add it to a future version Link to comment Share on other sites More sharing options...
fabriceunko Posted April 12, 2020 Share Posted April 12, 2020 Hello, I wanted to make the modification to test but the problem is that I do not have ‘products.index.inc.php’, I just have the file 'products.index.php' Link to comment Share on other sites More sharing options...
Claudia M Posted April 12, 2020 Author Share Posted April 12, 2020 Is this where I would add it? https://features.cubecart.com/ Link to comment Share on other sites More sharing options...
fabriceunko Posted April 12, 2020 Share Posted April 12, 2020 yes Link to comment Share on other sites More sharing options...
Claudia M Posted April 12, 2020 Author Share Posted April 12, 2020 Done Link to comment Share on other sites More sharing options...
bsmither Posted April 12, 2020 Share Posted April 12, 2020 The core code file products.index.inc.php is in /admin_aBcDeF/sources/ folder. (where _aBcDeF is a random sequence of letters) Link to comment Share on other sites More sharing options...
fabriceunko Posted April 12, 2020 Share Posted April 12, 2020 thank you .. i found however when i go to ‘products‘ i have a blank page. I clear the cache of course. Link to comment Share on other sites More sharing options...
bsmither Posted April 12, 2020 Share Posted April 12, 2020 I would double-check the edits - both the core code and the admin skin template. Please check PHP's error log. Link to comment Share on other sites More sharing options...
fabriceunko Posted April 13, 2020 Share Posted April 13, 2020 Hello, here is the error message I got [<strong>Exception</strong>] /home/santonsp/www/boutique/santons-de-provence/peyron-campagna/includes/lib/smarty/sysplugins/smarty_internal_templatecompilerbase.php:619 - Syntax error in template "file:/home/santonsp/www/boutique/santons-de-provence/peyron-campagna/admin_xDG7xw/skins/default/templates/products.index.php" on line 619 "" unclosed {if} tag Link to comment Share on other sites More sharing options...
bsmither Posted April 13, 2020 Share Posted April 13, 2020 Must be a different problem. For this project, the edits to the skin template was up around line 78 and did not involve an {if} statement. Please post here line 619, along with the few lines above and the few lines following. Link to comment Share on other sites More sharing options...
fabriceunko Posted April 13, 2020 Share Posted April 13, 2020 In the file 'products.index.php I have no more lines than 617 And in this file I modified line 78 Link to comment Share on other sites More sharing options...
bsmither Posted April 13, 2020 Share Posted April 13, 2020 Ok, I forgot that the line number reported is from the templatecompilerbase file. Not so. I will do some looking. Link to comment Share on other sites More sharing options...
bsmither Posted April 13, 2020 Share Posted April 13, 2020 Hmm. I am not finding it. Link to comment Share on other sites More sharing options...
bsmither Posted April 13, 2020 Share Posted April 13, 2020 Nope. The file I downloaded from your site is pristine. No differences from the stock file. Link to comment Share on other sites More sharing options...
fabriceunko Posted April 13, 2020 Share Posted April 13, 2020 Is there anything I should do to help you? Link to comment Share on other sites More sharing options...
bsmither Posted April 13, 2020 Share Posted April 13, 2020 If the image above is correct, and there are no more lines beyond line 617, then a good chunk of the file has been deleted. That file actually has 719 lines of code. You must have recently replaced it with a fresh copy before I got to download it. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.