Author Topic: Apply specific product discounts only for certain shopper group  (Read 26781 times)

marathoneer

  • Beginner
  • *
  • Posts: 12
Re: Apply specific product discounts only for certain shopper group
« Reply #15 on: July 09, 2010, 21:54:17 pm »
Wasn't specific in previous post.

I need custom discount for custom group for a custom product.

For instance: productxxx has 2 prices:

group1 (default): $100
group2 (wholesale): $90

I want group1 to have 20% discount on this product and group 2 - 30% on this product.

So having the ability to specify different discounts for each shopper group for every product is what I look for.

webgobe

  • Advanced
  • Full Member
  • *****
  • Posts: 535
  • Follow me on Twitter! http://twitter.com/webgobe
    • Internet craftsman carrying on the heritage of European manufacturing traditions through original Web designs.
Re: Apply specific product discounts only for certain shopper group
« Reply #16 on: July 12, 2010, 09:15:19 am »
Got it. But you don't need a custom modification (hack) for that.
It's allready there. When you create a Shopper Group, you can create a discount price on a product for that Shopper group.
As you are add or update a product, under Products -> Add Price you can add a specific discount price for a specific product for a specific Shopper Group.
Ant that's what you need, I guess. It's all there.
So, you need only to RTBM or search the forum, with a well formulated searchphrase you can find the solution in seconds.
Like a fine wine... Good from the start and getting better over time.
Donations are welcome!

marathoneer

  • Beginner
  • *
  • Posts: 12
Re: Apply specific product discounts only for certain shopper group
« Reply #17 on: July 12, 2010, 20:21:31 pm »
as far as I know you can specify discount for shopper group which will be applied to all products, not specific one.

once again, example of what do I need.

product1:
shopper1_group (default) price: 100 - discount 20%
shopper2_group (whosale) price: 100 - discount 25%

product2:
shopper1_group (default) price: 200 - discount 50%
shopper2_group (whosale) price: 200 - discount 45%


So different discount for different shopper group on every product.

webgobe

  • Advanced
  • Full Member
  • *****
  • Posts: 535
  • Follow me on Twitter! http://twitter.com/webgobe
    • Internet craftsman carrying on the heritage of European manufacturing traditions through original Web designs.
Re: Apply specific product discounts only for certain shopper group
« Reply #18 on: July 13, 2010, 08:46:34 am »
Aha. Humm, then indeed you need an extra hack for this. Can be done, need a little programming. None of hacks I know can do this, however I don't know (it's impossible) each solution published here, in the forums. and currently I'm overloaded enough (both with jobs and offline duties) to not have time to play with code here just for fun (I'd like to have :P ). Maybe in fall.
Like a fine wine... Good from the start and getting better over time.
Donations are welcome!

moonswolf

  • Beginner
  • *
  • Posts: 9
Re: Apply specific product discounts only for certain shopper group
« Reply #19 on: July 28, 2010, 13:51:30 pm »
@webgobe and @rb:

You are great...you save me ;)

Your hack works great.

I'm italian so sorry for my english. I'm new and i registered here cause you helped me with your hack and i would thanks you so much :)

Have a good day :)

bobysolo

  • Beginner
  • *
  • Posts: 47
  • Kiss my shiny metal ass!
    • Videosorveglianza
Re: Apply specific product discounts only for certain shopper group
« Reply #20 on: October 08, 2010, 22:36:31 pm »
Hello webgobe and rb!

I have only now had time for implementing this hack - works like a charm. I just love the VM community ;-)

ecopure

  • Beginner
  • *
  • Posts: 29
Re: Apply specific product discounts only for certain shopper group
« Reply #21 on: March 06, 2011, 20:06:02 pm »
brilliant! thank you!!

any other ideas for making the order process easier for our wholesaler buyers?

webgobe

  • Advanced
  • Full Member
  • *****
  • Posts: 535
  • Follow me on Twitter! http://twitter.com/webgobe
    • Internet craftsman carrying on the heritage of European manufacturing traditions through original Web designs.
Like a fine wine... Good from the start and getting better over time.
Donations are welcome!

leonpanjtar

  • Beginner
  • *
  • Posts: 2
    • Free Plans Archive
Re: Apply specific product discounts only for certain shopper group
« Reply #23 on: November 07, 2011, 21:37:30 pm »
Hey all.

I too needed a similar solution for a client. My problem was that my client has 3 shopping groups with different discount ammounts. All product prices are set fo rdefault shopping group, and SG members have fixed discounts on all products. Each time a customer, that belongs to a certain SG, logged in all the products that were on special (e.g. had discount assigned)  were showing default SG discount (example: 5%), altough the discount amount on the product was for example 15%. My client wanted to give their clients that were registered in SG a chance to buy products on special for a normal discounted price if the discount was bigger than default SG discount. (I hope you understand :D)

So I took the code that was presented here and modified it a bit to fit my needs
in /components/com_virtuemart/classes/ps_product.php on line 1914 find
Code: [Select]
function getPriceByShopperGroup( $product_id, $shopper_group_id, $check_multiple_prices=false, $additionalSQL='' ) {
replace that function with
Code: [Select]
function getPriceByShopperGroup( $product_id, $shopper_group_id, $check_multiple_prices=false, $additionalSQL='' ) {
global $auth;
static $resultcache = array();
$db = new ps_DB;
$vendor_id = $_SESSION['ps_vendor_id'];
if( empty( $shopper_group_id )) {
ps_shopper_group::makeDefaultShopperGroupInfo();
$shopper_group_id = $GLOBALS['vendor_info'][$vendor_id]['default_shopper_group_id'];
}

$whereClause='WHERE product_id=%s AND shopper_group_id=%s ';
$whereClause = sprintf( $whereClause, intval($product_id), intval($shopper_group_id) );

$q = "SELECT `product_price`, `product_price_id`, `product_currency` FROM `#__{vm}_product_price` $whereClause $additionalSQL";

$sig = sprintf("%u\n", crc32($q));

if( !isset($resultcache[$sig])) {
$db->query($q);
if( !$db->next_record() ) return false;
            /* START - Product price by shopping group
            *  If product has discount and and no shopper group discount is applied then apply normal discount
            */
            //$price_info["product_price"]= $db->f("product_price") * ((100 - $auth["shopper_group_discount"])/100);
            $disc_info = $this->get_discount( $product_id );
            if (!empty($auth["shopper_group_discount"]) && $disc_info["amount"] > 0) {
              $price_info["product_price"]= $db->f("product_price");
            }else {
                if( $disc_info["amount"] > $auth["shopper_group_discount"] ){                   
                    $price_info["product_price"]= $db->f("product_price") * ((100 - $auth["shopper_group_discount"])/100);
                }else{
                    $price_info["product_price"]= $db->f("product_price");
                }             
            }
            /* END - Product price by shopping group */
                       
$price_info["product_currency"] = $db->f("product_currency");

$price_info["product_base_price"]= $db->f("product_price") * ((100 - $auth["shopper_group_discount"])/100);
$price_info["product_has_multiple_prices"] = $db->num_rows() > 1;

$price_info["product_price_id"] = $db->f("product_price_id");
$price_info["item"]=true;
$GLOBALS['product_info'][$product_id]['price'] = $price_info;
// Store the result for later
$resultcache[$sig] = $price_info;

return $GLOBALS['product_info'][$product_id]['price'];
}
else {
return $resultcache[$sig];
}

}

on line 2500 find (the same as in the start of this post)
Code: [Select]
            if ($no_discount) {
                $q = "SELECT product_parent_id FROM #__{vm}_product WHERE product_id=$product_id";
                $db->query($q);
                if($db->next_record()) {
                    $q = "SELECT amount,is_percent FROM #__{vm}_product,#__{vm}_product_discount ";
        $q .= "WHERE product_id='".$db->f("product_parent_id")."' AND (start_date<='$starttime' OR start_date=0) AND (end_date>='$endofday' OR end_date=0) ";
        $q .= "AND product_discount_id=discount_id";
        $db->query( $q );
        if( $db->next_record() ) {
        $discount_info["amount"] = $db->f("amount");
        $discount_info["is_percent"] = $db->f("is_percent");
        }
                }
            }

and add right below
Code: [Select]
            /* START -  Hack to fix product shopping group discount */
$shopper_group_id = $auth["shopper_group_id"];
$vmLogger->debug( 'The shopper group id is '.$shopper_group_id);
$vendor_id = $this->get_vendor_id($product_id);
$q = "SELECT shopper_group_id FROM #__{vm}_shopper_group WHERE `vendor_id`='$vendor_id' AND `default`='1'";
$db->setQuery($q); $db->query();
$db->next_record();
$default_shopper_group_id = $db->f("shopper_group_id");
if($shopper_group_id != $default_shopper_group_id){
    $vmLogger->debug( 'The default shopper group id is '.$default_shopper_group_id);
// $discount_info["amount"] = 0;
// $discount_info["is_percent"] = 0;
                if($discount_info["is_percent"]){
                    if($discount_info["amount"] > $auth["shopper_group_discount"]){
                       
                        $discount_info["amount"] = $discount_info["amount"];
                        $discount_info["is_percent"] = $discount_info["is_percent"];
                       
                    }else{
                       
                        $discount_info["amount"] = $auth["shopper_group_discount"];
                        $discount_info["is_percent"] = 1;
                       
                    }                   
                }else{
                        $discount_info["amount"] = 0;
                        $discount_info["is_percent"] = 0;
                }   
}
            /* END -  Hack to fix product shopping group discount */                     
$discount_info['create_time'] = time();
$_SESSION['product_sess'][$product_id]['discount_info'] = $discount_info;
return $discount_info;
}
else
    return $_SESSION['product_sess'][$product_id]['discount_info'];
}

Hope this helps anyone. This can also be done with a extended classec method mentioned earlier in this post.
If you like my solutions please visit my site http://www.free-plans.com

vandusendesign

  • Beginner
  • *
  • Posts: 2
Re: Apply specific product discounts only for certain shopper group
« Reply #24 on: September 05, 2012, 21:36:53 pm »
I am using VM 1.1.8 with Joomla 1.5.26 and am having more issues regarding the discounts.  I have a client that has numerous products which all show a "per product" discount.  "You Save.....".  On top of this for everyone, they also have set up a group discount of 25% to certain registered users.  When they log in now, not only does it display the "You Save...." price but it takes 25% of the "Original" price and then subtracts that from the "Per Product" discount.  Not good!  ie......I have a product originally sold for $4.00 and is discounted to $1.25.  I log in as a discount holder for 25% and it gives me 25% of $4.00 not $1.25.  Ending with a price of $.25.  Again not good!  Any help would be greatly appreciated.

Thank you!

webgobe

  • Advanced
  • Full Member
  • *****
  • Posts: 535
  • Follow me on Twitter! http://twitter.com/webgobe
    • Internet craftsman carrying on the heritage of European manufacturing traditions through original Web designs.
Re: Apply specific product discounts only for certain shopper group
« Reply #25 on: September 06, 2012, 12:56:16 pm »
See this:
http://forum.virtuemart.net/index.php?topic=66765.msg227498#msg227498
The hack is published on my homepage, can be downloaded from there.
Like a fine wine... Good from the start and getting better over time.
Donations are welcome!

gap

  • Beginner
  • *
  • Posts: 18
Re: Apply specific product discounts only for certain shopper group
« Reply #26 on: May 20, 2014, 20:36:35 pm »
Hello webgobe,

I hope you get a notification about new replies. :)
I just found in this topic that the hack about discount I used is your code - thank you!
The hack generally works fine but unfortunately there is a case when it doesn't work. (on: VM: 1.1.9; Joomla 1.5.6)

If a guest adds products to the cart first and he logs in only later with a user login who is a member of an other shopper group then the cart content will be updated and the product prices will be recalculated.
Unfortunately VM applies the product discount on the shopper group price in this case and I cannot find which other function makes that. My question is which other function makes this recalculation that should be amended to get things work properly.

Example for the desc. of problem:
Product base price: 100
product discount: 20
default shopper group price: 100 - 20 = 80
wholesaler shopper group price = 50 (and shouldn't be amended, his discount is zero)
default behaviour of VM would be in case of wholesaler:
               wholesaler shopper group price = +50
               minus product discount: - 20
               wholesaler net end price = 30 = WRONG

Thanks
gap