Jump to content

Customer Groups


Claudia M

Recommended Posts

I have 3 group memberships - ClaudiasBargains (I haven't created that one yet) -   Etsy Shop at ClaudiasBargains and Ebay at claudias_bargains.  This is so I can bring the orders from those sites into CC and have one central hub I guess you'd call it.  The only way a customer could be in 2, or even 3, groups is if for instance they purchased something from my Etsy shop,  then from 1 0r 2 of the other groups.  Come to think of it I did have that happen.   They bought an item from ebay, about a year later the same item from etsy, and then later from my store.  I just referenced the offsite orders in the store order.

What if someone buys something from etsy and I set them up in the etsy group.  Later they buy something from the store (or ebay).  What if I just create another group to reflect this.  CB/Etsy for instance.  And then change that customers group.  It would still be nice if the Group showed in the Orders list, but if it's too much trouble that's ok.

Link to comment
Share on other sites

Please try this:

In the admin skin template orders.index.php, near line 43, find:

{else}
    {$order.name}
{/if}
   </td>

On a new blank line after that, add:

<td>{$order.cust_groups}</td>

Near line 23, find:

   <td>{$THEAD.customer}</td>

On a new blank line after that, add:

<td>{$THEAD.membership}</td>


In the admin file /sources/order.index.inc.php, near line 801, find:

$orders  = $GLOBALS['db']->select(sprintf('`%1$sCubeCart_order_summary` LEFT JOIN `%1$sCubeCart_customer` ON %1$sCubeCart_order_summary.customer_id = %1$sCubeCart_customer.customer_id', $GLOBALS['config']->get('config', 'dbprefix')), sprintf('%1$sCubeCart_order_summary.*, %1$sCubeCart_customer.type, CONCAT(%1$sCubeCart_order_summary.last_name, %1$sCubeCart_order_summary.first_name) AS `customer`, %1$sCubeCart_order_summary.status', $GLOBALS['config']->get('config', 'dbprefix')), $where, $order_by, $per_page, $page);

Change to:

// $orders  = $GLOBALS['db']->select(sprintf('`%1$sCubeCart_order_summary` LEFT JOIN `%1$sCubeCart_customer` ON %1$sCubeCart_order_summary.customer_id = %1$sCubeCart_customer.customer_id', $GLOBALS['config']->get('config', 'dbprefix')), sprintf('%1$sCubeCart_order_summary.*, %1$sCubeCart_customer.type, CONCAT(%1$sCubeCart_order_summary.last_name, %1$sCubeCart_order_summary.first_name) AS `customer`, %1$sCubeCart_order_summary.status', $GLOBALS['config']->get('config', 'dbprefix')), $where, $order_by, $per_page, $page);

On a new blank line after that, add:

if ($key[0] == "member_groups") { $order_by = " ORDER BY `group_name` ".$_GET['sort'][$key[0]].", `cart_order_id` DESC"; }
$orders = $GLOBALS['db']->select(
sprintf('`%1$sCubeCart_order_summary` LEFT JOIN `%1$sCubeCart_customer` ON %1$sCubeCart_order_summary.customer_id = %1$sCubeCart_customer.customer_id LEFT JOIN %1$sCubeCart_customer_membership ON %1$sCubeCart_order_summary.customer_id = %1$sCubeCart_customer_membership.customer_id LEFT JOIN %1$sCubeCart_customer_group ON CubeCart_customer_membership.group_id = %1$sCubeCart_customer_group.group_id', $GLOBALS['config']->get('config', 'dbprefix')),
sprintf('%1$sCubeCart_order_summary.*, %1$sCubeCart_customer.type, CONCAT(%1$sCubeCart_order_summary.last_name, %1$sCubeCart_order_summary.first_name) AS `customer`, %1$sCubeCart_order_summary.status, %1$sCubeCart_customer_group.group_name AS `cust_groups`', $GLOBALS['config']->get('config', 'dbprefix')),
$where, $order_by, $per_page, $page);

Near line 783, find:

    $thead_sort = array(

On a new blank line after that, add:

'membership'   => $GLOBALS['db']->column_sort('member_groups', $lang['customer']['title_groups_membership'], 'sort', $current_page, $_GET['sort']),

Take note  of this new line:

if ($key[0] == "member_groups") { $order_by = " ORDER BY `group_name` ".$_GET['sort'][$key[0]].", `cart_order_id` DESC"; }

This is the command that sets up sorting by member group name. For those orders (customers) that have the same group name,  there is a secondary sort on the standard Cart_Order_Id number from most recent to older. If you wish to have this secondary sort be something else (like customer last name), this is where you will give that column name.

Link to comment
Share on other sites

I got this error in my admin:

File: [snippet_216e9674db4630b722e7937e095a8141.php] Line: [2] "SELECT `group_name` FROM `CubeCart_customer_membership` AS M INNER JOIN `CubeCart_customer_group` AS G WHERE G.`group_id` = M.`group_id` AND M.`customer_id` = ;" - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1

Link to comment
Share on other sites

That is probably coming from the snippet created some time ago that acquired the names of the customer groups the customer belongs to, for each order shown in the list.

You do not need this snippet now. In admin, Manage Hooks, Code Snippets tab, click the Edit icon for "Adds Customer Group Name(s) to Admin Orders List" (uses 'admin.order.index.list' hook). Uncheck the Enabled box and Save. Have CubeCart clear it's internal cache.

There is actually nothing wrong with the database query in the code snippet, except two things: the data it supplies might interfere with the data acquired by previous means, and the database is complaining that the 'customer_id' is missing. This could be because there is a ghost customer showing up in this list that does not have a customer_id (as weird as that sounds).

Link to comment
Share on other sites

Hey Brian,

I unchecked the code snippet as you said but I got this error today:

File: [snippet_216e9674db4630b722e7937e095a8141.php] Line: [2] "SELECT `group_name` FROM `CubeCart_customer_membership` AS M INNER JOIN `CubeCart_customer_group` AS G WHERE G.`group_id` = M.`group_id` AND M.`customer_id` = ;" - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1

Link to comment
Share on other sites

Might be from a Code Snippet that provides a similar function: the group name on the individual Add/Edit Order Summary page.

I mentioned earlier that it may be the case where an order has no customer ID. I said that sounded strange.

However, when adding a new order, and there does not yet exist an associated customer for this order being created, then, of course, there is no customer_id.

So, perhaps the relevant Code Snippet should be corrected to test for whether this order is being added or edited.

Link to comment
Share on other sites

When I sell an item on eBay or Etsy I setup an "account" in Cubecart using some coding and databases I created.  I'll create a customer, save, then create an order from the orders tab in admin.   The above errors occurred when I created two eBay orders today.  I created a tab in orders to hold "special data" for these off site orders, and CC orders.  Here's part of it that auto populates when I put the customer in the order.  Could this cause the error?

<div> <label for="customer_id"><strong>Store Customer ID</strong></label><span>{$SUMMARY.customer_id}</span></div>

Link to comment
Share on other sites

I think the error gets logged when the admin clicks the Create Order tab. At that moment, there is no customer data that was fetched from the database to populate the form -- as the form, when first being shown to the admin, is supposed to be empty anyway.

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...