Jump to content

Recommended Posts

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 post
Share on other sites

  • Replies 51
  • Created
  • Last Reply

Top Posters In This Topic

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.

Edited by bsmither
Link to post
Share on other sites

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 post
Share on other sites

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 post
Share on other sites

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 post
Share on other sites

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 post
Share on other sites

The core code file products.index.inc.php is in /admin_aBcDeF/sources/ folder. (where _aBcDeF is a random sequence of letters)

Edited by bsmither
Link to post
Share on other sites

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 post
Share on other sites

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.

Edited by bsmither
Link to post
Share on other sites

Ok, I forgot that the line number reported is from the templatecompilerbase file. Not so.

I will do some looking.

 

Edited by bsmither
Link to post
Share on other sites

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