Thread: Major Additions - microCART: Shopping System for vB4
View Single Post
  #758  
Old 12-24-2012, 09:23 AM
Christos Teriakis Christos Teriakis is offline
 
Join Date: Jul 2011
Location: Thessaloniki, Greece
Posts: 1,228
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by Ichigo88 View Post
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
Reply With Quote
Благодарность от:
Ichigo88
 
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01485 seconds
  • Memory Usage 1,807KB
  • Queries Executed 11 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD_SHOWPOST
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (6)bbcode_code
  • (1)bbcode_quote
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_box
  • (1)post_thanks_box_bit
  • (1)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (1)post_thanks_postbit
  • (1)post_thanks_postbit_info
  • (1)postbit
  • (1)postbit_onlinestatus
  • (1)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • reputationlevel
  • showthread
Included Files:
  • ./showpost.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_postinfo_query
  • fetch_postinfo
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showpost_start
  • bbcode_fetch_tags
  • bbcode_create
  • postbit_factory
  • showpost_post
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • fetch_musername
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • post_thanks_function_fetch_thanks_bit_start
  • post_thanks_function_show_thanks_date_start
  • post_thanks_function_show_thanks_date_end
  • post_thanks_function_fetch_thanks_bit_end
  • post_thanks_function_fetch_post_thanks_template_start
  • post_thanks_function_fetch_post_thanks_template_end
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • showpost_complete