Jump to content

Make a field Inline editible in Customers List


Claudia M
 Share

Recommended Posts

Hi,

I have done this in the Products Inventory field and would now like to do it with one field in the customers.  I don't use Membership Groups ( See: https://forums.cubecart.com/topic/57357-customer-changed-price-on-order/#comment-249528)  I have instead created a field in the order summary database called site_full_address.  I have placed an input box for this under contact details on the first page of the customer form. This automatically populates in the Customer List page. After deleting my membership groups I find I have alot of empty fields on the Customer List page.  Instead of going into each customer and adding the site_full_address thru the contact details input box I would like to make it editible in the Customer List page.  How would I do this?

Thanks in advance for any help!

 

PS

In my lines 183-189 in the admin/skin/customers.index the spans are in the wrong place.

  {if !empty($CONFIG.w3w)}<div><label for="address_w3w">what3words</label><span><input type="text" name="address[w3w]" id="address_w3w" value="{$ADDRESS.w3w}" class="textbox"></span></div>{/if}
      <div><label for="billing">{$LANG.address.billing_address}</label><span><input type="hidden" name="address[billing]" id="billing" value="{$ADDRESS.billing}" class="toggle"></div>
      <div><label for="default">{$LANG.address.default_delivery_address}</label><span><input type="hidden" name="address[default]" id="default" value="{$ADDRESS.default}" class="toggle"></div>
      <input type="hidden" name="address[address_id]" value="{$ADDRESS.address_id}">
      </span></span>
      </fieldset>
      {/if}

 

Edited by Claudia M
more info
Link to comment
Share on other sites

Please compare your code above with the code in the GitHub repository (assuming you are running CC644).

Two steps to making a field editable on the Customer List: make the text editable, and process the data that was submitted.

Let's examine the customer's email -- ONLY  AS AN EXAMPLE.
In customers.index.php, near line 46, there is:
<td>{$customer.email}</td>

Change this to:
<td><span class="editable" name="email[{$customer.customer_id}]">{$customer.email}</span></td>

We are using for the name attribute an array variable of 'email'. So, for your purposes, the name attribute could be 'site_full_access'.

To process the data submitted:

Again, using the email -- ONLY AS AN EXAMPLE.
In customers.index.inc.php, near line 299, we find code to process the 'status' check boxes.
We will add our code to process the new email data just above it:

    if (isset($_POST['email']) && is_array($_POST['email']) && Admin::getInstance()->permissions('customers', CC_PERM_EDIT)) {
        foreach ($_POST['email'] as $customer_id => $email) {
            $result = $result || $GLOBALS['db']->update('CubeCart_customer', array('email' => $email), array('customer_id' => (int)$customer_id));
        }
        if ($result) {
            $GLOBALS['main']->successMessage("Some or all emails updated.");
        }
        $send_redirect = true;
    }

Again, for your purposes, instead of 'email', you could use 'site_full_access'.

Note the $result = $result || code. The update will either succeed or fail. Once $result goes true, it will stay true.

Link to comment
Share on other sites

Thanks Brian.  I'll implement it asap

I implemented the changes and I get the input box, it just won't save.  I get the red banner "failed to add customer"

Here's what I did:

admin.customer.skin:  Also tried it without the strike through

<td><span class="editable" name="customer[{$customer.customer_id}][site_full_address]">{$customer.site_full_address}</span></td>

<td><span class="editable" name="customer[{$customer.customer_id}][site_full_address]">{$customer.site_full_address}</span></td>

admin.customer.source:  Also tried putting my code under the "status code"

  $GLOBALS['main']->successMessage($lang['customer']['notify_groups_delete']);
        $send_redirect = true;
    }
    if (isset($_POST['site_full_address']) && is_array($_POST['site_full_address']) && Admin::getInstance()->permissions('customers', CC_PERM_EDIT)) {
        foreach ($_POST['site_full_address'] as $customer_id => $site_full_address) {
            $result = $result || $GLOBALS['db']->update('CubeCart_customer', array('site_full_address' => $site_full_address), array('customer_id' => (int)$customer_id));
        }
        if ($result) {
            $GLOBALS['main']->successMessage("Some or all sold sites updated.");
        }
        $send_redirect = true;
    }
    if (isset($_POST['status']) && is_array($_POST['status']) && Admin::getInstance()->permissions('customers', CC_PERM_EDIT)) {
        foreach ($_POST['status'] as $customer_id => $status) {
            // Delete any active session
            if((int)$status===0) $GLOBALS['db']->delete('CubeCart_sessions', array('customer_id' => (int)$customer_id));
            $result = $GLOBALS['db']->update('CubeCart_customer', array('status' => (int)$status), array('customer_id' => (int)$customer_id));
            if ($result) {
                $GLOBALS['main']->successMessage($lang['customer']['notify_customer_status']);
            }
        }
        $send_redirect = true;
    }

 

 

Edited by Claudia M
more info
Link to comment
Share on other sites

I made the change above but it still isn't saving it. I use to have ajax_site_full_address in the contact details page. Could that be a problem?

<fieldset><legend>{$LANG.account.contact_details}</legend>
      <!-- <div><label for="ajax_site_full_address">Sold Site</label><span><input type="text" id="ajax_site_full_address" name="customer[site_full_address]" value="{$CUSTOMER.site_full_address}" class="textbox"></span></div> -->

         <div><label for="site_full_address">Sold Site</label><span><input type="text" id="site_full_address" name="customer[site_full_address]" value="{$CUSTOMER.site_full_address}" class="textbox"></span></div>
        <div><label for="cust-email">Store (created) eMail</label><span><input type="text" name="customer[email]" id="cust-email" value="{$CUSTOMER.email}" class="textbox"></span></div>
                    <div><label for="ajax_offsite_email">Offsite eMail</label><span><input type="text" id="ajax_offsite_email" name="customer[offsite_email]" value="{$CUSTOMER.offsite_email}" class="textbox"></span></div>
         <div><label for="ajax_site_phone">OffSite / PP Phone</label><span><input type="text" id="ajax_site_phone" name="customer[site_phone]" value="{$CUSTOMER.site_phone}" class="textbox"></span></div>
        <div><label for="cust-phone">{$LANG.address.phone}</label><span><input type="text" name="customer[phone]" id="cust-phone" value="{$CUSTOMER.phone}" class="textbox"></span></div>
        <div><label for="cust-mobile">{$LANG.address.mobile}</label><span><input type="text" name="customer[mobile]" id="cust-mobile" value="{$CUSTOMER.mobile}" class="textbox"></span></div>
        <div><label>{$LANG.newsletter.customer_subscribed}</label><span>

In customers.index.php
Link to comment
Share on other sites

The HTML to show the customer list vs. the HTML to show the form to add/edit a specific customer, even though in the same file, is controlled by Smarty {if} blocks. Thus, the two parts do not conflict with each other.

The code posted just above will not be present when viewing the Customer List.

You said: "I have instead created a field in the order summary database called site_full_address."

You didn't actually say that you created a new column 'site_full_address' in CubeCart_customer. I assume you did because where else would you put this data when entering it in that customer's details screens.

 

Link to comment
Share on other sites

It seems I have site_full_address in both order summary and customers.  So I created sold_locale for the customer and changed my code to match.  It worked.  I think I'm going to go thru everything and delete database fields I don't use.  Thanks Brian

the only thing is I have to save after I update each record.  I can't do a whole page at a time

Link to comment
Share on other sites

Are you saying that once you first click in the Customer List, in a table cell, which switches to a text entry field, to add/change the data there (if any data is there to begin with), you cannot click in another table cell (same column, different row) - which should switch to a text entry field just like the first time - and add/change the data this second time?

 

Link to comment
Share on other sites

The Sold Site (site_full-address) column is my old one (I also have site_full-address in Order Summary). I'm keeping it there for now to make it easier to update the Sold Locale column. (sold_locale in Customer)

Each time I update null to the actual info needed I have to click save.  If I try to do more than one null to info it will only save the first the othes stay at null. This also happens when I delete the info in Sold Site (then shows null)

Once I get all the Store Locales inputted I'm going to delete the Sold Site column

 

1571005326_soldlocale.PNG.695f68e138af9daa3bbf4d9ef6e97c66.PNG

Link to comment
Share on other sites

In the above reply, I see you are using the spelling "site_full-address" while all previous replies are using the spelling "site_full_address" (dash vs underscore).

Please verify the spelling of the database's column name.

Turn on CubeCart's Debug mode (and be sure your local IP address is in the adjacent field - www.showmyip.com). After clicking the Save button, the bottom of the returned page will show the POST contents and probably the SQL queries that updated the CubeCart_customer database table. (There will be two major sections of debug data: 1-processing the POST, and 2-gathering the data for the page display.)
 

 

Link to comment
Share on other sites

All are site_full_address

 

POST:

'status' =>
'883' => 0
'882' => 1
'881' => 1
'880' => 1
'879' => 1
'878' => 1
'877' => 1
'876' => 1
'875' => 1
'874' => 1
'873' => 1
'872' => 1
'871' => 1
'870' => 1
'869' => 1
'868' => 1
'867' => 1
'866' => 1
'865' => 1
'864' => 1
'sold_locale' =>
'865' => ClaudiasBargains.com
 
SQL queries"
12. Hack: 1639171895.09080 --- Duration: 5311 µs [ERROR - NOT CACHED]
INSERT INTO `CubeCart_system_error_log` (`message`,`url`,`backtrace`,`time`) VALUES ('[<strong>Notice</strong>] /home/claudias/public_html/admin_Gsvj4z/sources/customers.index.inc.php:313 - Undefined variable: result','https://www.claudiasbargains.com/admin_mUF32e.php?_g=customers','mutingErrorHandler() (customers.index.inc.php:313)\nrequire() (controller.admin.session.true.inc.php:110)\ninclude() (admin_mUF32e.php:41)\n','1639171895');
13. Hack: 1639171895.09130 --- Duration: 397 µs [NOT CACHED]
Link to comment
Share on other sites

There is 'sold_locale', an array of one element where the key is customer_id '865'. The key 865 is the 19th element in the 'status' array. (The screen grab earlier only shows 18 rows. Not a problem - just noticing.)

Did you try to also change - at the same time as 865 - the cell contents for customer 864 (the next row)?

If so, please post the edited line made in the admin template customers.index.php.

For the queries, #12 is the insertion into the error_log regarding the variable $result - which is expected.

Do queries #13-16 relate to CubeCart_customer?

Link to comment
Share on other sites

Brian I want to thank you for your help on this, but I can't really think to straight right now.  Knee is really hurting from physical therapy.  I do have one question though.  If I wanted to move all the records from the site_full_address table to the sold_locale table what would the query be?

Again thanks so much

Link to comment
Share on other sites

  • 2 weeks later...

"If I wanted to move all the records from the site_full_address table to the sold_locale table..."

Is these actual tables, or column names in one specific table?

Are you planning to keep 'site_full_address'? If not, think about just renaming the column name.

 

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.

 Share

×
×
  • Create New...