Jump to content

Admin Inline Edit


Claudia M

Recommended Posts

  • Replies 51
  • Created
  • Last Reply

Stock Warnings tab? On the Dashboard?

Probably not. But then, anything is possible.

The general list in Products?

Yes and No.

In admin, Products, the general list, Stock column, the values shown include a range of stock levels that are comprised of the various values found in the Options Matrix Table (when used per product and when in Store Settings, Stock tab, "Main stock level as matrix stock level summary" is disabled).

So, updates coming from this general list may not show new values. Otherwise, sure.

Link to comment
Share on other sites

This will be an interesting project! The Stock level column is essentially informative. More data will need to be added to be able to identify the actual product_id (available on the Edit icon, so we already know that), but also the Option Matrix line option_id to deconstruct the Option Matrix distinct phrase (such as, "0 - Color: Black, Size: 4-Cell" vs. "0 - Color: Red, Size: 2-Cell" vs. "0 - Color: Black, Size: 2-Cell").

Link to comment
Share on other sites

The following edits will allow the admin, with "product edit" permissions (or super-admin), to click-edit the stock levels reported, which will update the respective database tables.

The stock levels reported come from the specific level from the Options Matrix Table for the specific matrix of the base product. (The Option Matrix Product Code is not used, but could be.)

If the Option Matrix Table entry is set to not require the use of its stock level, the reported stock level comes from the product's individual stock level.

The above is stock behavior.

Because the reported level shown can come from either of two locations, it is important to maintain this distinction and update only the appropriate table.

In the admin /sources/dashboard.index.inc.php, near line 334, find:

$fields = 'I.name, I.product_code, I.stock_level AS I_stock_level, I.stock_warning AS I_stock_warning, I.product_id, M.stock_level AS M_stock_level, M.use_stock as M_use_stock, M.cached_name';

Change to:

$fields = 'I.name, I.product_code, I.stock_level AS I_stock_level, I.stock_warning AS I_stock_warning, I.product_id, M.stock_level AS M_stock_level, M.use_stock as M_use_stock, M.cached_name, M.matrix_id';

Near line 21, find:

$GLOBALS['smarty']->assign('QUICK_TOUR', true);

After that, add the following:

if (isset($_POST['warn_m_stock_level']) && is_array($_POST['warn_m_stock_level']) && Admin::getInstance()->permissions('products', CC_PERM_EDIT)) {
    foreach ($_POST['warn_m_stock_level'] as $matrix_id => $matrix_new_stock_level) {
        $om_update = array('stock_level' => $matrix_new_stock_level);
        $om_where = array('matrix_id' => $matrix_id);
        $GLOBALS['db']->update('CubeCart_option_matrix',$om_update,$om_where);
    }
    unset($matrix_id,$matrix_new_stock_level);
}

if (isset($_POST['warn_i_stock_level']) && is_array($_POST['warn_i_stock_level']) && Admin::getInstance()->permissions('products', CC_PERM_EDIT)) {
    foreach ($_POST['warn_i_stock_level'] as $product_id => $product_new_stock_level) {
        $inv_update = array('stock_level' => $product_new_stock_level);
        $inv_where = array('product_id' => $product_id);
        $GLOBALS['db']->update('CubeCart_inventory',$inv_update,$inv_where);
    }
    unset($product_id,$product_new_stock_level);
}


In the admin skin template dashboard.index.php, near line 290, find:

<div>{$STOCK_PAGINATION}</div>

After that, add the following:

<div><br /><input class="submit" type="submit" value="{$LANG.common.update}"></div>
</form>

Near line 278, find:

<td>{$warn.product_code}</td>
<td align="center"  width="65" nowrap="nowrap">{if $warn.M_use_stock==1}{$warn.M_stock_level}{else}{$warn.I_stock_level}{/if}{if $warn.cached_name}
 - {$warn.cached_name}
{/if}
</td>

Change to:

<td>{$warn.product_code}{if $warn.cached_name} - {$warn.cached_name}{/if}</td>
<td align="center"  width="65" nowrap="nowrap">
{if $warn.M_use_stock==1}
  <span class="editable number" name="warn_m_stock_level[{$warn.matrix_id}]">{$warn.M_stock_level}</span>
{else}
  <span class="editable number" name="warn_i_stock_level[{$warn.product_id}]">{$warn.I_stock_level}</span>
{/if}
</td>

Near line 264, find:

<h3>{$LANG.dashboard.title_stock_warnings}</h3>

After that, add the following:

<form action="?#stock_warnings" method="post" enctype="multipart/form-data">

Have fun!

Edit: Didn't get the second table name correct. Fixed

Link to comment
Share on other sites

Darn it! (I didn't have an item that didn't have an Options Matrix that was out of stock.)

Find this:

        $GLOBALS['db']->update('CubeCart_option_matrix',$inv_update,$inv_where);
    }
    unset($product_id,$product_new_stock_level);
}

Change to:

        $GLOBALS['db']->update('CubeCart_inventory',$inv_update,$inv_where);
    }
    unset($product_id,$product_new_stock_level);
}

Sorry, I didn't test that specific condition.

Link to comment
Share on other sites

I made sure it worked for me.

In admin, Store Settings, Advanced tab, enable the debug mode and enter you local IP address in the adjacent field (www.whatismyip.com).

Change a stock level value and then click Update.

On the next page, at the bottom, examine the debug section and observe the POST section. There should be:
warn_m_stock_level and/or warn_i_stock_level

Within each group, if present, there should be at least one key=>value pair.

Then, look through the SQL queries to find one or more UPDATE statements. Check those for validity.

Finally, make sure you are either a Super Admin, or a regular Admin with product edit permission.

(Note: in my installation, I am finding extra records in CubeCart_option_matrix table. I'll check on that later.)

Ok, I'm seeing records being listed that shouldn't. I think there is a problem with the initial query that fetches the recordset from the database.

Do any of your products use the Options Matrix Table? You can quickly check by examining the database table CubeCart_option_matrix, for records where 'status'=1.

 

Link to comment
Share on other sites

So in the debug page I have good

POST:

'warn_i_stock_level' =>
'865' => 10
'token' => 05c69d22796dd758d4c48bcb6278098f
 
[21] UPDATE `CubeCart_option_matrix` SET `stock_level` = '10' WHERE CubeCart_option_matrix.product_id = '865'; -- (0.00057697296142578 sec) [NOT CACHED]
 
 
how to check this? Because I am the administrator of my shop but how can I be in super admin?
 
Super Admin, or a regular Admin with product edit permission
Link to comment
Share on other sites

The update statement is not correct. It is updating where on the product_id. It needs to be the matrix_id.

Verify that your code is:

if (isset($_POST['warn_m_stock_level']) && is_array($_POST['warn_m_stock_level']) && Admin::getInstance()->permissions('products', CC_PERM_EDIT)) {
    foreach ($_POST['warn_m_stock_level'] as $matrix_id => $matrix_new_stock_level) {
        $om_update = array('stock_level' => $matrix_new_stock_level);
        $om_where = array('matrix_id' => $matrix_id);
        $GLOBALS['db']->update('CubeCart_option_matrix',$om_update,$om_where);
    }
    unset($matrix_id,$matrix_new_stock_level);
}

In admin, Administrators, click the Edit icon for yourself. If there are no Edit icons, you are not a Super Admin. If, when editing yourself, if there is no Permissions tab, and the checkbox for Super User? is checked, then you are a Super Admin.

 

Link to comment
Share on other sites

Just so you know, there is something I don't like about how CubeCart deals with options that are get disabled from being included in the Options Matrix Table.

Their OMT status is disabled, and they then are not listed in the OMT, but they still show up on the Dashboard.

I'm writing a bug report now.

 

Link to comment
Share on other sites

  • 1 month later...

I tried to implement this for the product price and the column showed null for all products. I was able to input a price but it didn't save it. Can you tell me what I'm doing wrong.  Thanks in advance!

 

In the admin skin template products.index.php, near line 78, find:

 

Changed to:

 

 <td><span class="editable number" name="product[{$product.product_id}][product_code]">{$product.product_code}</span></td>

               <td align="center">{$product.cost_price}</td>

               <td><span class="editable number" name="product[{$product.product_id}][product_price]">{$product.product_price}</span></td>

               <td align="center">{$product.stock_level}</td>

 

In the admin source code products.index.inc.php, near line 489, find:

 

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

        }

    }

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

    // Update Product Price

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

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

        }

    }

 

    httpredir(currentPage());

}

Link to comment
Share on other sites

You do not have the correct name of the database table CubeCart_inventory column that holds the product's price. Try:

<td><span class="editable number" name="product[{$product.product_id}][product_price]">{$product.price}</span></td>

and

$GLOBALS['db']->update('CubeCart_inventory', array('price' => $product_price['product_price']), array('product_id' => $product_id));
Link to comment
Share on other sites

What am I doing wrong now!!!  I edit the price of an item, save, and the product code shows null. This is my code:

<td><span class="editable number" name="product[{$product.product_id}][product_code]">{$product.product_code}</span></td>               
               <td align="center">{$product.cost_price}</td>
               <td><span class="editable number" name="product[{$product.product_id}][product_price]">{$product.price}</span></td>               
               <td align="center">{$product.stock_level}</td>


---- and ---

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));
        }
    }
 if (isset($_POST['product']) && is_array($_POST['product'])) {
    // Update Product Price
        foreach ($_POST['product'] as $product_id => $product_price) {
             $GLOBALS['db']->update('CubeCart_inventory', array('price' => $product_price['product_price']), array('product_id' => $product_id));
        }
    }

    httpredir(currentPage());
}

 

Link to comment
Share on other sites

This is looking at each element of $_POST['product'] as a key/value pair, with the key being the product_id, but making no distinction as what the value represents. It could be either the product_code or the price. The name we give to the variable simply helps us read the code, but has no true relationship to what the variable actually holds.

In fact, it seems the value of each key/value pair is another array where the key is either 'product_code' or 'product_price', with the value being the text entered into the textbox. We are, in fact, using $product_code['product_code'] and $product_price['product_price'], but recall that the name we give the variable $product_code and $product_price does not truly indicate what the value actually is.

This is badly explained, and I could go on to elaborate, but instead, let's try to fix it.

Substitute the following:

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

    if (isset($_POST['product']) && is_array($_POST['product'])) {
    // Update Product Price
        foreach ($_POST['product'] as $product_id => $product_price) {
             $GLOBALS['db']->update('CubeCart_inventory', array('price' => $product_price['product_price']), array('product_id' => $product_id));
        }
    }

With:

    if (isset($_POST['product']) && is_array($_POST['product'])) {
    // Update Product Detail
        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));
            }
            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));
            }
        }
    }

What is happening now is that a test is made to make sure the detail to be changed actually has a value associated with it.

(Note: My development server crashed a few days ago, and I have yet to fix it. So, I can't actually test this code.)

 

Link to comment
Share on other sites

That seems to have worked.  I have some DB columns I created that I would like to do the same thing - make them editable.  One of them is item_location.  is this what I would do before the last 2 }

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

}

I created some  columns in the Order Summary DB that I'm not using.  Is it safe  to just go into myPHPadmin and drop them?  Do I have to empty them first?

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.




×
×
  • Create New...