Reputation: 67
Is there any way to add many customers to one group at once on opencart? Its too much of a work to add 7500 customers to different groups by one by one.
Upvotes: 0
Views: 254
Reputation: 16055
If you need to add all customers to one group while you know the group ID, you can execute this SQL query in your preferred MySQL administration tool:
INSERT INTO <DB_PREFIX>customer_to_group (customer_id, group_id)
SELECT customer_id, <GROUP_ID>
FROM <DB_PREFIX>customer
Replace <DB_PREFIX>
with your DB table name prefix (or none if you are not using it).
Replace <GROUP_ID>
by the numeric representation of the group you want the customers to be assigned to.
You can use a similar approach if you want to insert only few customers - but again you need to know their ID's or email addresses (i.e. some unique value that could identify each customer):
INSERT INTO <DB_PREFIX>customer_to_group (customer_id, group_id)
SELECT customer_id, <GROUP_ID>
FROM <DB_PREFIX>customer
WHERE customer_id IN (<ID1>, <ID2>, <ID3>, '<ID...>')
or
INSERT INTO <DB_PREFIX>customer_to_group (customer_id, group_id)
SELECT customer_id, <GROUP_ID>
FROM <DB_PREFIX>customer
WHERE email IN ('[email protected]', '[email protected]', '[email protected]', '...')
Let's say you want to assign only those customers living in USA (where the country ID is <COUNTRY_ID>
):
INSERT INTO <DB_PREFIX>customer_to_group (customer_id, group_id)
SELECT c.customer_id, <GROUP_ID>
FROM <DB_PREFIX>customer c
LEFT JOIN <DB_PREFIX>customer_address ca ON ca.customer_id = c.customer_id
WHERE ca.country_id = <COUNTRY_ID>
GROUP BY c.customer_id
Upvotes: 1