A seemingly simple question caused serious headaches in past weeks. One of my clients who has an already seriously cross-hacked VirtueMart shop (SkinRich) asked me to make it possible, that a specific shopper group she had, the Distributors, namely, to be able to order products only in six-packs, making warehouse people's life much easier, and costs lower. The other users should have the default quantity options.

After thinking a lot about how to solve the problem, I came out with a 4 line simple hack, which works perfectly for me.

Let's say that the user group in question has the ID=6. (you can find this ID easily taking a look to the 'jos_vm_shopper_group' table, or the User Groups list in the VirtueMart Admin>User Groups list, by clicking on the group name and locating the &group_id=XX parameter in the URL of the resulted page)

And let's say you want this user group to have only the choice to buy products in groups of 6, and no more than 240 items once.

Ready? Let's hack!

Open the /administrator/components/com_virtuemart/classes/ps_product_attribute.php and locate the function "show_quantity_box". Depending on your exact VirtueMart version, it's around line 1050.

Go down until you find this code:

//Start output of quantity
//Check for incompatabilities and reset to normal
if( CHECK_STOCK == '1' && ! $product_in_stock ) {
	$display_type = 'hide' ;
	}
if( empty( $display_type ) || (@$display_type == "hide" && $child == 'Y') || (@$display_type == "radio" && $child == 'YM') || (@$display_type == "radio" && ! $child) ) {
	$display_type = "none" ;
	}

Below that, insert this:

		$auth = $_SESSION['auth'];
		if($auth["shopper_group_id"]==6) {		
			$display_type = "drop" ;
			$quantity_options['quantity_box'] = "drop";
			}

Save it.

You are done with hacking part. Now let's set up the products accordingly. Presuming that you want all the products to behave similarly, as described above, go to your hosting panel, open phpMyAdmin, and run this query:

UPDATE `yourdatabase`.`jos_vm_product` SET `quantity_options` = 'none,0,240,6';

Of course, replace the elements of the above query with the data you want to use. The trick relies on showing for the given shopper group a dropdown list type of quantity selector no matter how the preferences set for quantity box display are. Happy hacking!

And, remember - this hack - as any other hacks there - are coming with absolutely no guarantees. Use it at your own risk! Tested on VirtueMart versions 1.1.2-1.1.9

PS: You can follow the afterlife of this hack in VirtueMart's Forum.

0
0
0
s2sdefault
Category: VirtueMart hacks