Welcome, Guest. Please login or register.
Login with username, password and session length


It's a release candidate! VirtueMart 2.0 RC - the next generation VirtueMart - is available! Read more....

  Advanced search

247038 Posts in 67506 Topics- by 258314 Members - Latest Member: aniketana
Pages: [1]   Go Down
Print
Author Topic: Free Shipping by Shopper Group  (Read 5750 times)
grwright
Newbie
*
Posts: 3


« on: July 30, 2008, 13:12:20 PM »

Allowing free shipping to a group of users seems to be a common question here. I'm surprised no one has posted a solution before now. It only took me about 30 minutes to figure it out.

Here is one way to allow free shipping to a group of users. This is for VM 1.1.

First, create a new shopper group called "Free Shipping". You could also use an existing group if you want. Add the users that you want to allow free shipping to this group.

Next, find the following line in ps_checkout.php:

Code:
                if( $vendor_freeshipping > 0 && $vars['order_subtotal_withtax'] >= $vendor_freeshipping) {

Change it to something similar to this:

Code:
                $db = new ps_DB;
                $q = "SELECT shopper_group_name " .
                     "FROM #__{vm}_shopper_group g, #__{vm}_shopper_vendor_xref x " .
                     "WHERE x.user_id = '" . $_SESSION['auth']["user_id"] . "' " .
                     "AND g.shopper_group_id = x.shopper_group_id";
                $db->query($q);
                if( $db->f("shopper_group_name") == "Free Shipping") {
                        $PSHOP_SHIPPING_MODULES = Array( "free_shipping" );
                        include_once( CLASSPATH. "shipping/free_shipping.php" );
                        $this->_SHIPPING = new free_shipping();
                }
                elseif( $vendor_freeshipping > 0 && $vars['order_subtotal_withtax'] >= $vendor_freeshipping) {

Note: If you used a group name different than "Free Shipping" then change the 8th line above to match.

I hope this helps.
Logged
Bob Bloom
News Team
Full Member
*
Posts: 134


WWW
« Reply #1 on: August 02, 2008, 21:12:27 PM »

I was responding to a post, and I saw this thread. So I thought I'd add my 2cents!

A client asked me about this, so I snuck it into my Shipping Bypass add-on for VM 1.1.0 (http://www.southlasalle.com/forum/viewtopic.php?f=5&t=9). I strongly recommend that you upgrade to VM 1.1.2, which has an adaptation of my Shipping Bypass add-on built right in.

This is what I have in my ps_checkout.php file. I figured most people want my Shipping Bypass code, not my Shopper Group code, so my code is commented out. I have comments explaining how to enable the code. So, it does look kinda confusing.

Mine is not exactly an elegant solution. You have to know the shopper id number -- no easy drop down boxes in VM's config. And my code is ready to go for one shopper code only. So, if don't mind fishing for the id, and you need just one shopper group, then you are in luck!

My client needed free shipping for Shopper Group "8". I think that means I've "optimized the code" -- is that what it is?!!


Quote
/* ======================================================================================================================================
   START: DISPLAY VM's FREE SHIPPING MODULE IF THE USER BELONGS TO SHOPPER GROUP 8 (OR WHATEVER shopper_group_id YOU SPECIFIY -BOB BLOOM
   ====================================================================================================================================== */
$auth = $_SESSION['auth'];
      

/* *************************************************************************************************
   ** ALERT! YOU MUST FIND THE FOLLOWING IF CONDITION NEAR HERE AND DELETE IT (OR COMMENT IT OUT) **
   ** IF YOU ARE COPY-PASTING CODE. THE ORIGINAL IF CONDITION IS:                                 **
   ** if( $vendor_freeshipping > 0 && $vars['order_subtotal_withtax'] >= $vendor_freeshipping ) { **
   *************************************************************************************************
      

   *************************************************************************************************
   ** NOW, WHAT I DID WAS TURN OFF THIS OPTIONAL FEATURE, BY KEEPING THE ORIGINAL IF CONDITION    **
   ** SO, IF YOU WANT TO ENABLE THIS FEATURE, YOU MUST COMMENT OUT THE FOLLOWING LINE             **
   *************************************************************************************************
   ** I TURNED IT OFF SO MY SHIPPING BYPASS AND PAYMENT BYPASS WORK SIMPLY BY OVERWRITING FILES   **
   *************************************************************************************************
   ** SO, IF YOU WANT TO ENABLE THIS SHOPPER GROUP FEATURE, YOU MUST COMMENT OUT THE NEXT LINE    **
   ************************************************************************************************* */
   if( $vendor_freeshipping > 0 && $vars['order_subtotal_withtax'] >= $vendor_freeshipping ) {

/* *************************************************************************************************
   ** THEN, YOU HAVE TO UN-COMMENT THE NEXT LINE, AND THEN SPECIFY THE APPLICABLE SHOPPER GROUP # **
   ************************************************************************************************* */
   //if( ($vendor_freeshipping > 0 && $vars['order_subtotal_withtax'] >= $vendor_freeshipping) || ($auth['shopper_group_id'] == Cool ) {

/* ======================================================================================================================================
   END: DISPLAY VM's FREE SHIPPING MODULE IF THE USER BELONGS TO SHOPPER GROUP 8 (OR WHATEVER shopper_group_id YOU SPECIFIY -BOB BLOOM
   ====================================================================================================================================== */


-Bob

P.S. My "8" turned into a happy face. If PHP would just parse happy faces, my clients would be a whole lot happier! Dear Zend...
« Last Edit: August 02, 2008, 21:16:50 PM by Bob Bloom » Logged

Bob Bloom
freelance Joomla specialist
http://southlasalle.com
osmosisinc
Newbie
*
Posts: 12


« Reply #2 on: November 07, 2008, 15:42:03 PM »

I wonder if I can use this for multiple groups? For example, I need not only group 8, but groups 3 and 6...?

Logged
osmosisinc
Newbie
*
Posts: 12


« Reply #3 on: November 07, 2008, 15:48:16 PM »

After reading more carefully, I see not... Sad

hmm, a quandry.
Logged
Reincha
Jr. Member
**
Posts: 94


« Reply #4 on: November 27, 2009, 13:44:34 PM »

if anybody is still looking how to add multiple groups:

i took code from 1st post and repeated this part for each group right where first finishes:

if( $db->f("shopper_group_name") == "Free Shipping") {
$PSHOP_SHIPPING_MODULES = Array( "free_shipping" );
include_once( CLASSPATH. "shipping/free_shipping.php" );
$this->_SHIPPING = new free_shipping();
}

-------
now, maybe anybody knows if its possible to make a coupon for free shipping?
Logged
pzepernick
Newbie
*
Posts: 3


« Reply #5 on: February 14, 2010, 06:23:21 AM »

I just finished a solution that can do multiple shopper groups.  I have seen this asked quiet a few times so I thought I would find some posts trying to do it and post back.  The solution can be found here at my blog:

http://www.todayisearched.com/2010/02/virtuemart-free-shipping-for-shopper-group.html

Paul
Logged
building252
Newbie
*
Posts: 12


« Reply #6 on: August 03, 2010, 09:11:44 AM »

@pzepernick this hack works great!

Only one issue...anyone know how to implement Pauls hack so the "Minimum amount for free shipping" in the edit store section will still work?

The original hack will allow you to assign free shipping to whatever user group you choose...it just seems to override the setting I have in the store to only allow free shipping on orders over $50.

I'm trying to figure this out now...not really a php coder. If I come across a solution i'll post Smiley
Logged
building252
Newbie
*
Posts: 12


« Reply #7 on: August 03, 2010, 09:35:58 AM »

I think I've got it! This is a modification of the hack located here:

http://www.todayisearched.com/2010/02/virtuemart-free-shipping-for-shopper-group.html

in this line of the hack, I changed this:
//original line at 63
if(($vendor_freeshipping > 0 && $vars['order_subtotal_withtax'] >= $vendor_freeshipping) || $free_shoppergroup_shipping) {

to this:
//original line at 63
if(($vendor_freeshipping > 0 && $vars['order_subtotal_withtax'] >= $vendor_freeshipping) && $db->f(’shopper_group_freeshipping’) == “1″) {

Seems to be working for me on VM 1.1.4 - no errors or notices Smiley
Logged
plieka
Newbie
*
Posts: 19


« Reply #8 on: February 05, 2011, 11:04:11 AM »

Hi,

What I need is in line with the sollution only!

- Shopper_group:Resellers should always pay shipping and handling
- Shopper_group:Default customers get free shipping based on the setting in Virtuemart

Has anyone come across this?

thanks
Logged
plieka
Newbie
*
Posts: 19


« Reply #9 on: February 10, 2011, 09:57:58 AM »

Hi,

I solved the issue by using part of the solution at the top of the thread.

When you only want the Default shopper group to be able to get free shipping when they buy enough in the shop and all other shoppers need to pay shipping.
use the following.

Add code above the following line:
Code:
if( $vendor_freeshipping > 0 && $vars['order_subtotal_withtax'] >= $vendor_freeshipping) {

Add this:
Code:
$this->_subtotal = $this->get_order_subtotal($vars);
$db = new ps_DB;
                $q = "SELECT shopper_group_name " .
                     "FROM #__{vm}_shopper_group g, #__{vm}_shopper_vendor_xref x " .
                     "WHERE x.user_id = '" . $_SESSION['auth']["user_id"] . "' " .
                     "AND g.shopper_group_id = x.shopper_group_id";
                $db->query($q);
if( $db->f("shopper_group_name") == "-default-") {

then make sure you close the "IF" statement with a " } "

Full code:
Code:
$db = new ps_DB;
                $q = "SELECT shopper_group_name " .
                     "FROM #__{vm}_shopper_group g, #__{vm}_shopper_vendor_xref x " .
                     "WHERE x.user_id = '" . $_SESSION['auth']["user_id"] . "' " .
                     "AND g.shopper_group_id = x.shopper_group_id";
                $db->query($q);
if( $db->f("shopper_group_name") == "-default-") {
if( $vendor_freeshipping > 0 && $vars['order_subtotal_withtax'] >= $vendor_freeshipping) {
$PSHOP_SHIPPING_MODULES = Array( "free_shipping" );
include_once( CLASSPATH. "shipping/free_shipping.php" );
$this->_SHIPPING = new free_shipping();
}}
elseif( !empty( $_REQUEST['shipping_rate_id'] )) {

Checkout the double "}}" that closes the IF statement

hope this solves an issue for others as well, you can replace -default- by any other shopper_group
Logged
plieka
Newbie
*
Posts: 19


« Reply #10 on: April 08, 2011, 02:03:08 AM »

Hi,
just to show what you need to do to setup free shipping for different shopper groups and maybe different Purchase amounts to gain free shipping

- The [default] group free shipping amount is set in the store setting within VM
- The [Wholesale] group free shipping amount is set in the file ps_checkout.php in the code as below in my case 750 euro.

alter the free shipping section to what you see below and all works fine. If you have different names for the shopper groups replace the ones in the code.

Code:
$this->_subtotal = $this->get_order_subtotal($vars);

$db = new ps_DB;
$q = "SELECT shopper_group_name " .
"FROM #__{vm}_shopper_group g, #__{vm}_shopper_vendor_xref x " .
"WHERE x.user_id = '" . $_SESSION['auth']["user_id"] . "' " .
"AND g.shopper_group_id = x.shopper_group_id";
$db->query($q);
if( $db->f("shopper_group_name") == "-default-")
{
// start free shipping selection based on shopper group "DEFAULT"
if( $vendor_freeshipping > 0 && $vars['order_subtotal_withtax'] >= $vendor_freeshipping) {
$PSHOP_SHIPPING_MODULES = Array( "free_shipping" );
include_once( CLASSPATH. "shipping/free_shipping.php" );
$this->_SHIPPING = new free_shipping();
}
elseif( !empty( $_REQUEST['shipping_rate_id'] )) {

// Create a Shipping Object and assign it to the _SHIPPING attribute
// We take the first Part of the Shipping Rate Id String
// which holds the Class Name of the Shipping Module
$rate_array = explode( "|", urldecode(vmGet($_REQUEST,"shipping_rate_id")) );
$filename = basename( $rate_array[0] );
if( $filename != '' && file_exists(CLASSPATH. "shipping/".$filename.".php")) {
include_once( CLASSPATH. "shipping/".$filename.".php" );
if( class_exists($filename) ) {
$this->_SHIPPING = new $filename();
}
}
}
}
elseif( $db->f("shopper_group_name") == "Wholesale")
{
// start free shipping selection based on shopper group "DEFAULT"
if( $vendor_freeshipping > 0 && $vars['order_subtotal_withtax'] >= '750') {
$PSHOP_SHIPPING_MODULES = Array( "free_shipping" );
include_once( CLASSPATH. "shipping/free_shipping.php" );
$this->_SHIPPING = new free_shipping();
}
elseif( !empty( $_REQUEST['shipping_rate_id'] )) {

// Create a Shipping Object and assign it to the _SHIPPING attribute
// We take the first Part of the Shipping Rate Id String
// which holds the Class Name of the Shipping Module
$rate_array = explode( "|", urldecode(vmGet($_REQUEST,"shipping_rate_id")) );
$filename = basename( $rate_array[0] );
if( $filename != '' && file_exists(CLASSPATH. "shipping/".$filename.".php")) {
include_once( CLASSPATH. "shipping/".$filename.".php" );
if( class_exists($filename) ) {
$this->_SHIPPING = new $filename();
}
}
}
}


It would be great that in the future in VM this kind of functionality becomes standard.

Logged
spy_athens
Newbie
*
Posts: 1


« Reply #11 on: April 09, 2011, 05:35:58 AM »

I have just finished some tests of plieka's last solution in my site and I think it works fine.
Did anybody else tried this solution?
Logged
callumgilhooly
Newbie
*
Posts: 16


« Reply #12 on: June 07, 2011, 12:52:28 PM »

Hi Plieka, Great work and just what I'm looking for however I already have a hack in place for country code (to only allow free shipping to GBR) and when I try to modify it to include your hack and the original all I get is the delivery options no matter what combination I try.
As you may have guessed, I'm not a php coder (although trying to learn). Any tips as to how to get these to work together? My current code is below. Many thanks

Code:
$db = new ps_DB;
      $q = "SELECT country from #__{vm}_user_info WHERE user_info_id = '" . $vars["ship_to_info_id"] . "'";
      $db->query($q);

      if( $vendor_freeshipping > 0 && $vars['order_subtotal_withtax'] >= $vendor_freeshipping && $db->f("country") == "GBR") {
$PSHOP_SHIPPING_MODULES = Array( "free_shipping" );
include_once( CLASSPATH. "shipping/free_shipping.php" );
$this->_SHIPPING = new free_shipping();
}
elseif( !empty( $_REQUEST['shipping_rate_id'] )) {

Callum
Logged
Pages: [1]   Go Up
Print
Jump to: