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

bobysolo

  • Beginner
  • *
  • Posts: 47
  • Kiss my shiny metal ass!
    • Videosorveglianza
Apply specific product discounts only for certain shopper group
« on: February 08, 2010, 00:15:07 am »
Hi.

Our wholesale shop runs on VM 1.1.4 and joomla 1.5.15. We have now a small nuisance as we want specific product discounts to be applied only for the default shopper group.

Explanation: we have 3 groups of users:
- default (normal prices)
- retail (discounted prices)
- distributor (even lower prices)

Each group has it's own prices set individually for every product. We also have some products, which are "on special" and have an extra discount applied to them (I know the two aren't related, but by us they are - I mean on special and the discounted products - so if a product is on special it means that it has an extra discount).

Now, how can we make that individual product discount be applied only for the default shopper group? Since the prices for the other two groups are already that low, that an extra discount cannot be possible.

Thanks for the help.

Nirm

  • Contributing Developer
  • Full Member
  • *
  • Posts: 919
    • Me, My Work and I
Re: Apply specific product discounts only for certain shopper group
« Reply #1 on: February 08, 2010, 08:13:48 am »
The way I would handle this is like this

Product which is on special - Go into List Prices and remove the default listing. This then effectively hides it from default users. Then create a new product with the same details but without the retail and distributor prices (i.e it only has a default price) and then apply  your discounts as required.

You would need to check whether this (default) product would show up when one of your retail or distributor customers logged in.
A lot of questions are answered in the VM 1.1 User Manual please read it before asking questions.
-------------------------------------
http://www.nirmoysomaia.com

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 #2 on: March 19, 2010, 18:49:19 pm »
I had recently a similar request from one of my clients. Here's his situation:
In the shop he has 2 shopper groups active: the default shoppers which may have discounts on some products (time limited promotions mostly) and the wholesalers group, wich have a permanent (and consistent) group discount on all products. His problem was, that the product specific discounts where added to wholesaler's group discount, so if product A has a promotion set to 50% and the wholesaler group has a general discount of 50%, then the wholesalers have got the price for product A at 25% of the original price (50% applied twice), something he definitively did not wanted.
So he needed somehow to prevent that the product specific discounts to be applied for other shoppers than those from shopper group designated as being the default group (if you did not tweaked that, this is the  -default- group, but the hack below locates the grup set actually as being the default - the group where new users are assigned by default).
The hack to fix this is relatively simple (done on VM 1.1.4).
1. Open /administrator/components/com_virtuemart/classes/ps_product.php.
2. Locate this function (line 2246)
Code: [Select]
function get_discount( $product_id ) {
global $mosConfig_lifetime;
3. Change second line to:
Code: [Select]
global $mosConfig_lifetime,$vmLogger,$auth;4. Locate this code (line 2277):
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");
        }
                }
            }
5. insert after the above code the following lines
Code: [Select]
$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;
}
Enjoy!. From now the product specific discounts will be added only to the shopper group designated as the default one.
Like a fine wine... Good from the start and getting better over time.
Donations are welcome!

rb

  • Advanced
  • Full Member
  • *****
  • Posts: 1503
Re: Apply specific product discounts only for certain shopper group
« Reply #3 on: March 21, 2010, 01:45:08 am »
webgobe, thanks for sharing this great solution!

Here's a little tweak to it.  VirtueMart 1.1.4 added "extended user classes" which allow you to make changes to core classes without modifying the actual class itself.  So if you implement your solution with this extension, then you won't have to re-apply this hack even if a new version of ps_product is released.

1. Copy the following code and save it into a file named "ps_product.php" (but don't overwrite your existing ps_product.php file).  Also, if you already have a ps_product.php in user_class, you'll have to edit and insert just the get_discount function within it.

Code: [Select]
<?php
if( !
defined'_VALID_MOS' ) && !defined'_JEXEC' ) ) die( 'Direct Access to '.basename(__FILE__).' is not allowed.' );

class ps_product extends vm_ps_product {

function get_discount$product_id ) {

$discount_info vm_ps_product::get_discount$product_id );  // invoke the existing function

global $vmLogger,$auth;
$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 = new ps_DB;
$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;

$discount_info['create_time'] = time();
$_SESSION['product_sess'][$product_id]['discount_info'] = $discount_info;

}
return $discount_info
} // end of get_discount
} // end of extended class
?>


2. Create a directory in
          components/com_virtuemart/themes/your_theme_name/
and call it user_class (unless you already have one)


3. Move the file from Step 1 into this new directory so the file path looks like this:
          components/com_virtuemart/themes/your_theme_name/user_class/ps_product.php

4. Admin->Configuration->Security tab->Security Settings box
          enable "Allow the inclusion of extended classes from the theme-directory"

Now you have the same effect as before (no Product Discounts for non-default Shopper Groups), but you haven't modified the core ps_product class.

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 #4 on: March 22, 2010, 12:15:52 pm »
Thanks! Great tip, will use it ;)
Like a fine wine... Good from the start and getting better over time.
Donations are welcome!

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 #5 on: March 22, 2010, 18:36:58 pm »
4. Admin->Configuration->Security tab->Security Settings box
          enable "Allow the inclusion of extended classes from the theme-directory"

I am missing here something?? I don't see that box in my 1.1.4...
Like a fine wine... Good from the start and getting better over time.
Donations are welcome!

rb

  • Advanced
  • Full Member
  • *****
  • Posts: 1503
Re: Apply specific product discounts only for certain shopper group
« Reply #6 on: March 22, 2010, 20:40:10 pm »
See red circled item in attached pic.


[attachment cleanup by admin]

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 #7 on: March 23, 2010, 09:13:23 am »
LOL, thanks, I managed somehow to hack that out from my playground install ;) thanks!
Like a fine wine... Good from the start and getting better over time.
Donations are welcome!

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 #8 on: March 23, 2010, 09:55:58 am »
Tested and works, thank you!
For those lazier out there ;) I packed everything - both versions - with detailed instructions and it's available for download on my homepage at http://www.webgobe.ro/en/downloads/joomla-1-5/component-hacks/no-discount-added-for-wholesalers.html
Like a fine wine... Good from the start and getting better over time.
Donations are welcome!

mvitos

  • Beginner
  • *
  • Posts: 28
    • LEDGloeilamp.nl - Bespaar op uw energierekening!
Re: Apply specific product discounts only for certain shopper group
« Reply #9 on: April 08, 2010, 21:30:45 pm »
Love it! I was looking for this solution and glad to see somebody already found it out and posted it!

Cheers.
LEDgloeilamp.nl - Bespaar op uw energierekening!

building252

  • Beginner
  • *
  • Posts: 15
Re: Apply specific product discounts only for certain shopper group
« Reply #10 on: June 15, 2010, 15:00:17 pm »
For those looking for a solution that does not require a core hack:

1. First thing you need to do is set up a shopper group with 0% as the savings.

2. Go to the product you want to apply the savings. At the top there is an icon with "List Prices" there should already be one published for the "default" shopper.

3. Click "New". Here you can choose your "shopper group" and add a price. Requires you to do a little math. (ex. you have a $100 product and want a 10% discount) just simply put $90 for both net & gross. For the quantity you can put 0 - 0 or 0 -1000 either should work.

4. Now if you login as that "shopper group" the discount will only be applied to the product you added the discount to.


Some, might be wondering. what if the product already has a discount applied or a coupon is used. Again this can be fixed with math. The discount you give in the "List Price" section is off the gross. So, think carefully when applying your discount.

BONUS: Looking to have more control over your coupons? I came across a great VM module for applying coupons. It's called AWO Coupons and its on the Joomla Extention Directory here:

http://extensions.joomla.org/extensions/extension-specific/virtuemart-extensions/virtuemart-coupons/11629

This module works great for shopper group, one time, timed or product specific coupons.

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 #11 on: June 15, 2010, 19:52:02 pm »
Interesting ideea, but I need to pinpoint 2 problems:
1. First of all, for those of you using 1.1.4 you have the option to avoid entirely doing a core hack, the non-invasive, non-hacking version based on "rb"-s tip is in the package.
2. For the shops with more than a couple of products may became a product management nightmare.
I developed it for use in a site with 50+ active products and 4 shopper groups, the default one and 3 types of different privileged groups, with group discounts applied to ALL products ranging from 20-50%.
The problem which was solved was the following: using native VM possibilities, a product sold for 50$ for the default group was sold with 25$ for the most discounted wholesalers group.
If the shop owner decided to put that product to a temporary discount of 50% to boost sales on (using the basic VM tools), the default shopper group got it indeed for the 25$ price, but for the shoppers with group discounts the two kind of discounts where cumulated, the top dogs had a price of 12,5$ for it something wasn't desired by the siteowner.
So he needed a simple solution, and to preserve VM's discount feature - you know, those tricks with price in red, etc, etc.
Your solution would involve in this case doing the math 50*4 = 200 times, with loosing the benefit of showing discounts, etc., versus this solution needing only one click - to apply the temporary discount to that product.
So I don't think that my solution is that bad ;)
Like a fine wine... Good from the start and getting better over time.
Donations are welcome!

jennygawl

  • Beginner
  • *
  • Posts: 2
Re: Apply specific product discounts only for certain shopper group
« Reply #12 on: June 17, 2010, 06:09:38 am »
Wow... Really a nice tips.. Actually I am looking for this.. Thank god I got the best tips.. Can you guys give me some more tips regarding this.. Thank you..



marathoneer

  • Beginner
  • *
  • Posts: 12
Re: Apply specific product discounts only for certain shopper group
« Reply #13 on: July 09, 2010, 20:21:27 pm »
is there any way to upgrade this hack and have 2 different discount for 2 different shopper group?

For example, i have item 123 with prices:

group1(default)=$100
group2(wholesale)=$50

And I want ability to make a discount for the first group of 30%, for the group2 40%.

Thanks.

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 #14 on: July 09, 2010, 20:33:40 pm »
you can. Set the group discount for default to 30%, and for group2 to 40% and you're done ;) Exactly that was the purpose of the hack. If you don't succeeed, you know where to find me ;)
Like a fine wine... Good from the start and getting better over time.
Donations are welcome!