Quote:
Originally Posted by Ichigo88
Hi!
the product its work perfectly on mu vb 4.2.0 patch 3.
but i have a small question!
how to change the user in other primary usergruop?
now the usergroup upgrade its make in addizional.
thanks inadvance
|
Even if I advice you to avoid changing primary usergroup, follow the steps below:
1.- With a text editor (like Notepad) open the file: microcart/functions.php
2.- Search for:
Code:
function promoteUser($transid, $userid)
3.- Replace the whole function:
Code:
function promoteUser($transid, $userid)
{
global $vbulletin, $db;
$boughtdate = date("Y-m-d");
$orders = $db->query_read("SELECT * FROM ".TABLE_PREFIX."microcart_orders WHERE transid='$transid'");
while ($order = $db->fetch_array($orders)) {
$productid = $order["productid"];
$product = $db->query_first("SELECT * FROM ".TABLE_PREFIX."microcart_products WHERE id=$productid");
$leng = $product[dlperiod]/2;
$expiration = add_date($order[dend],$leng,0,0);
$dend = date("Y-m-d", strtotime($expiration));
$db->query_write("UPDATE ".TABLE_PREFIX."microcart_orders SET paiddate='$boughtdate', dend='$dend' WHERE transid='$transid'");
$promousergroup = $product["promousergroup"];
if ($promousergroup > 0)
{
$user = $db->query_first("SELECT membergroupids FROM ".TABLE_PREFIX."user WHERE userid=$userid");
$groups = $user["membergroupids"];
$groupids = explode(',', $groups);
if (!in_array($promousergroup, $groupids))
{
if (empty($groups))
{
$upgrade = $promousergroup;
} else {
$upgrade = $groups.','.$promousergroup;
}
$db->query_write("UPDATE ".TABLE_PREFIX."user SET membergroupids='$upgrade' WHERE userid=$userid");
}
}
}
return;
}
With this new code:
Code:
function promoteUser($transid, $userid)
{
global $vbulletin, $db;
$boughtdate = date("Y-m-d");
$orders = $db->query_read("SELECT * FROM ".TABLE_PREFIX."microcart_orders WHERE transid='$transid'");
while ($order = $db->fetch_array($orders)) {
$productid = $order["productid"];
$product = $db->query_first("SELECT * FROM ".TABLE_PREFIX."microcart_products WHERE id=$productid");
$leng = $product[dlperiod]/2;
$expiration = add_date($order[dend],$leng,0,0);
$dend = date("Y-m-d", strtotime($expiration));
$db->query_write("UPDATE ".TABLE_PREFIX."microcart_orders SET paiddate='$boughtdate', dend='$dend' WHERE transid='$transid'");
$promousergroup = $product["promousergroup"];
if ($promousergroup > 0)
{
$db->query_write("UPDATE ".TABLE_PREFIX."user SET usergroupid='$promousergroup' WHERE userid=$userid");
}
}
return;
}
4.- Search for:
Code:
function downgradeUser($transid, $userid)
5.- Replace the whole function:
Code:
function downgradeUser($transid, $userid)
{
global $vbulletin, $db;
$vbulletin->db->query_write("UPDATE ".TABLE_PREFIX."microcart_invoices SET invoicestatus=7 WHERE transid='$transid'");
$vbulletin->db->query_write("UPDATE ".TABLE_PREFIX."microcart_orders SET paid=0 WHERE transid='$transid'");
$orders = $vbulletin->db->query_read("SELECT * FROM ".TABLE_PREFIX."microcart_orders WHERE transid='$transid'");
while ($order = $vbulletin->db->fetch_array($orders)) {
$productid = $order["productid"];
$product = $vbulletin->db->query_first("SELECT * FROM ".TABLE_PREFIX."microcart_products WHERE id=$productid");
$promousergroup = $product["promousergroup"];
if ($promousergroup > 0)
{
$user = $vbulletin->db->query_first("SELECT membergroupids FROM ".TABLE_PREFIX."user WHERE userid=$userid");
$groups = $user["membergroupids"];
$groupids = explode(',', $groups);
if (in_array($promousergroup,$groupids))
{
$key = array_search($promousergroup, $groupids);
unset($groupids[$key]);
$downgrade = implode(',', $groupids);
$vbulletin->db->query_write("UPDATE ".TABLE_PREFIX."user SET membergroupids='$downgrade' WHERE userid=$userid");
}
}
}
return;
}
With...:
Code:
function downgradeUser($transid, $userid)
{
global $vbulletin, $db;
$vbulletin->db->query_write("UPDATE ".TABLE_PREFIX."microcart_invoices SET invoicestatus=7 WHERE transid='$transid'");
$vbulletin->db->query_write("UPDATE ".TABLE_PREFIX."microcart_orders SET paid=0 WHERE transid='$transid'");
$orders = $vbulletin->db->query_read("SELECT * FROM ".TABLE_PREFIX."microcart_orders WHERE transid='$transid'");
while ($order = $vbulletin->db->fetch_array($orders)) {
$productid = $order["productid"];
$product = $vbulletin->db->query_first("SELECT * FROM ".TABLE_PREFIX."microcart_products WHERE id=$productid");
$promousergroup = $product["promousergroup"];
if ($promousergroup > 0)
{
$vbulletin->db->query_write("UPDATE ".TABLE_PREFIX."user SET usergroupid='2' WHERE userid=$userid");
}
}
return;
}
6.- Save and upload the functions.php at: microcart/
*** ATTENTION ***
Downgrading the user means that he is going to usergroup 2 (Registered Members). So if you're selling another product which also promotes the user to a higher usergroup, then the user will LOSTS that promotion. That's why using the additional usergoups is the best choice.
Chris