Welcome to the MetaMod and Chameleon Support Forums.

Before posting, please check out the FAQs.

helpme

 

Need extra help with your Joomla site? Consider paid Joomla support by the developer of Chameleon and MetaMod.

 

show module when voucher entered in VirtueMart

show module when voucher entered in VirtueMart

Hi, I know this one could be very tricky or maybe it is not even possible...

I'm looking for a way to show a module only to people who enter a specific voucher code into VirtueMart. Can anyone write a recipe for this?

morktron
Beginner Modder
ranks
useravatar
Offline
11 Posts
User info in posts
Administrator has disabled public posting

Re: show module when voucher entered in VirtueMart

That's an excellent question, and at first I thought it couldn't be done. Fortunately I was wrong!

Try this:

Code:

$coupon = @$_SESSION['coupon_code'];

if ($coupon == 'MY_COUPON') return XXX;
// replace XXX with module ID to return

You can also get hold of the following attributes of the coupon (sample values given):

    [coupon_discount] => 6.00
    [coupon_redeemed] => 1
    [coupon_id] => 1
    [coupon_code] => MY_COUPON
    [coupon_type] => gift

So just replace @$_SESSION['coupon_code'] with @$_SESSION['coupon_discount'] or whatever you want.

Because these are part of the session, they last from the moment the user enters the code until the user logs out.

Hope that helps,
Stephen

Stephen Brandon
MetaMod / Chameleon developer
If you use MetaMod or Chameleon, please post a rating and a review at the Joomla! Extensions Directory: Chameleon | MetaMod

metamodguy
useravatar
Offline
3314 Posts
User info in posts
Administrator has disabled public posting

Re: show module when voucher entered in VirtueMart

Thanks Stephen, you are amazing! I really thought this would be impossible to do. Maybe it is worth adding to your VirtueMart recipes. Thanks again, I am very grateful smile

morktron
Beginner Modder
ranks
useravatar
Offline
11 Posts
User info in posts
Administrator has disabled public posting

Re: show module when voucher entered in VirtueMart

metamodguy wrote:

That's an excellent question, and at first I thought it couldn't be done. Fortunately I was wrong!

Try this:

Code:

$coupon = @$_SESSION['coupon_code'];

if ($coupon == 'MY_COUPON') return XXX;
// replace XXX with module ID to return

You can also get hold of the following attributes of the coupon (sample values given):

    [coupon_discount] => 6.00
    [coupon_redeemed] => 1
    [coupon_id] => 1
    [coupon_code] => MY_COUPON
    [coupon_type] => gift

So just replace @$_SESSION['coupon_code'] with @$_SESSION['coupon_discount'] or whatever you want.

Because these are part of the session, they last from the moment the user enters the code until the user logs out.

Hope that helps,
Stephen

i am sorry for my ignorance, roll

can you please show me how to actually do this as well?

i really need to show the *percentage*  that was discounted if possible, even if a dollar amount discount coupon was used, like so:

Subtotal:                                                                                           $100.00
Tax:                                                                                                          0.00
Coupon Discount:  Coupon Name:(xx50)  Discount: 50%        -$50.00
Total:                                                                                                   $50.

turnit
Beginner Modder
ranks
useravatar
Offline
1 Posts
Administrator has disabled public posting

Re: show module when voucher entered in VirtueMart

Hi and Happy New Year!

I've just spent a few hours working on this - it was a lot harder than I thought. I'm going to need to build this in to JomGenius, I think!

Anyway here's a function which will return the value of all the items in the cart. It uses the same calculation as the "mini cart" in the VirtueMart module except that it returns the total BEFORE any coupon discounts.

Code:

function mm_cart_total() {

    if( !isset( $mosConfig_absolute_path ) ) {
        $mosConfig_absolute_path = $GLOBALS['mosConfig_absolute_path']    = JPATH_SITE;
    }
    global $mosConfig_absolute_path;
    require_once( $mosConfig_absolute_path.'/components/com_virtuemart/virtuemart_parser.php' );
    require_once(CLASSPATH.'ps_product_category.php');
    require_once(CLASSPATH. 'ps_product.php' );
    $ps_product = new ps_product;

    global $CURRENCY_DISPLAY, $sess, $VM_LANG;
    $cart = $_SESSION['cart'];
    $saved_cart = @$_SESSION['savedcart'];
    $auth = $_SESSION['auth'];
    $empty_cart = false;
    if ($cart["idx"] == 0) {
        $empty_cart = true;
        $checkout = false;
        $total = 0;
    }
    else {
        $empty_cart = false;
        $checkout = True;
        $total = $order_taxable = $order_tax = 0;
        $amount = 0;
        $weight_total = 0;

        // Determiine the cart direction and set vars
        if (@$_SESSION['vmCartDirection']) {
            $i=0;
            $up_limit = $cart["idx"] ;
        }
        else {
            $i=$cart["idx"]-1;
            $up_limit = -1;
        }
        $ci = 0;

        //Start loop through cart
        do
        {
            $price = $ps_product->get_adjusted_attribute_price($cart[$i]["product_id"],$cart[$i]["description"]);
            $price["product_price"] = $GLOBALS['CURRENCY']->convert( $price["product_price"], $price["product_currency"] );
            $amount += $cart[$i]["quantity"];
            $product_parent_id=$ps_product->get_field($cart[$i]["product_id"],"product_parent_id");
            if (@$auth["show_price_including_tax"] == 1) {
                $my_taxrate = $ps_product->get_product_taxrate($cart[$i]["product_id"] );
                $price["product_price"] *= ($my_taxrate+1);
            }
            $subtotal = round( $price["product_price"], 2 ) * $cart[$i]["quantity"];
            $total += $subtotal;
            $flypage_id = $product_parent_id;
            if($flypage_id == 0) {
                $flypage_id = $cart[$i]["product_id"];
            }
            $flypage = $ps_product->get_flypage($flypage_id);
            $category_id = vmGet( $cart[$i], 'category_id', 0 );


            if(@$_SESSION['vmCartDirection']) {
                $i++;
            }
            else {
                $i--;
            }

            $ci++;
        } while ($i != $up_limit);
        //End loop through cart
    }
    return $total;
}


echo "total: " . mm_cart_total();

Now that you can get the total, you can calculate the percentage discount derived from the coupon discount:

$total = mm_cart_total();
if ($total > 0 and @$_SESSION['coupon_discount'] > 0 ) {
  $percentage_discount = round(@$_SESSION['coupon_discount'] / $total * 100, 2);
  echo "that was a percentage of {$percentage_discount}%";
}

Hope that helps,
Stephen

Stephen Brandon
MetaMod / Chameleon developer
If you use MetaMod or Chameleon, please post a rating and a review at the Joomla! Extensions Directory: Chameleon | MetaMod

metamodguy
useravatar
Offline
3314 Posts
User info in posts
Administrator has disabled public posting

Board Info

Board Stats:
 
Total Topics:
1691
Total Polls:
6
Total Posts:
5912
Total Posts Today:
6
User Info:
 
Total Users:
11515
Newest User:
velis415
Members Online:
0
Guests Online:
254

Online: 
There are no members online

Forum Legend:

 Topic
 New
 Locked
 Sticky
 Active
 New/Active
 New/Locked
 New Sticky
 Locked/Active
 Active/Sticky
 Sticky/Locked
 Sticky/Active/Locked