codefritz Posted October 21, 2013 Share Posted October 21, 2013 Following problem: For example if a customer has already made 5 orders and payed reliably I want to offer him aditional paying methods. This requires to create a customer group where you can distinguish the group by the amount of orders a customer has made. This is not possible by default prestashop (v 1.5.5.0) ... as it seems? Thanks, cf Link to comment Share on other sites More sharing options...
Qvixx Posted October 25, 2013 Share Posted October 25, 2013 (edited) Hi, I don't know if there is a module or something like that for your issue. You could probably solve it with a little php-script. something like that: <?php $host = "yourhost"; $user = "youruser"; $pass = "yourpass"; $db = "yourdb"; mysql_connect($host, $user, $pass); mysql_select_db($db); unset($host,$user,$pass,$db); $query = "SELECT * FROM ps_customer_group"; $result = mysql_query($query) or die ("MySQL-Error: " . mysql_error()); while ($row = mysql_fetch_array($result)) { $query2 = "SELECT sum(total_paid_real) as total FROM ps_orders WHERE id_customer =" . $row["id_customer"]; $result2 = mysql_query($query2) or die ("MySQL-Error: " . mysql_error()); while ($row2 = mysql_fetch_array($result2)) { if ($row2["total"] >= 1000) { $query3 = "UPDATE ps_customer_group SET id_group = 3 WHERE id_customer = " . $row["id_customer"]; mysql_query($query3) or die ("MySQL-Error: " . mysql_error()); } elseif ($row2["total"] > 100 && $row2["total"] < 1000) { $query3 = "UPDATE ps_customer_group SET id_group = 2 WHERE id_customer = " . $row["id_customer"]; mysql_query($query3) or die ("MySQL-Error: " . mysql_error()); } else { $query3 = "UPDATE ps_customer_group SET id_group = 1 WHERE id_customer = " . $row["id_customer"]; mysql_query($query3) or die ("MySQL-Error: " . mysql_error()); } } } echo "done!"; ?> Im not a programmer so the code won't be well written. But something like that should do the job. ATTENTION: I did NOT test the code so please don't copy-paste it without looking through!!! It goes through all the customers and checks their total order amount. Depending on their cumulated order amount it sets the group-value. You could create a CRON-Job which runs the script every x hours or just run it manually. Hope it helps Edited October 25, 2013 by Qvixx (see edit history) Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now