Discounts by Attribute
glennnz - January 30, 2009 - 05:05
| Project: | UC Discounts |
| Version: | 5.x-1.x-dev |
| Component: | User interface |
| Category: | feature request |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | active |
Jump to:
Description
Hi
I want to be able to give a role based discount to products with a particular attribute.
In my case, I sell training courses with modules, and for a particular role, one of these modules is free.
Is there a way to do this that I can't see?
Thanks
Glenn

#1
Hi
I am also using this module it's relay great module, i am able to give discounts to users in various ways,
But now i am not able to give a role based discount to products with a particular attribute.
Please Help!!!
Thanks & Regards,
AnAnD
#2
@AnAnD
I struggled loooooong and hard to get stuff to work with role based discounts. I wrote code and couldn';t figure out why it wouldn't work. It turned out that another module was interfering with mine, see this thread, the offending module was one which displays tax inclusive prices; I can't find it now :(
My final code was:
<?phpfunction role_price_cart_item($op, &$item) {
cache_clear_all();
global $user;
switch ($op) {
case 'load':
$nid = $item->nid;
$type = db_result(db_query("SELECT type FROM {node} WHERE nid = %d", $nid));
if ($type == 'rbtpa_course') {
if ($item->data['attributes'][1] == '1') {
$item->price = '1553';
}
if ($item->data['attributes'][1] == '2') {
$item->price = '816';
}
if ($item->data['attributes'][1] == '3') {
$item->price = '628';
}
if ($item->data['attributes'][1] == '4') {
$item->price = '298';
}
if (in_array('Member', $user->roles) && $item->data['attributes'][1] == '1') {
$item->price = '1352';
}
if (in_array('Member', $user->roles) && $item->data['attributes'][1] == '2') {
$item->price = '717';
}
if (in_array('Member', $user->roles) && $item->data['attributes'][1] == '3') {
$item->price = '548';
}
if (in_array('Member', $user->roles) && $item->data['attributes'][1] == '4') {
$item->price = '253';
}
if (in_array('Assessor', $user->roles) && $item->data['attributes'][1] == '1') {
$item->price = '1091';
}
if (in_array('Assessor', $user->roles) && $item->data['attributes'][1] == '2') {
$item->price = '627';
}
if (in_array('Assessor', $user->roles) && $item->data['attributes'][1] == '3') {
$item->price = '480';
}
if (in_array('Assessor', $user->roles) && $item->data['attributes'][1] == '4') {
$item->price = '0';
}
}
if ($type == 'hsa_course') {
$item->price = '1760';
if (in_array('Assessor', $user->roles)) {
$item->price = '1210';
}
if (in_array('Member', $user->roles)) {
$item->price = '1210';
}
}
if ($type == 'nz_hers_course') {
$item->price = '1553';
if (in_array('Member', $user->roles)) {
$item->price = '1352';
}
}
}
}
?>
This is obviously very specific to my needs, but hopefully you can find your way forward from here. You just need to examine the attributes array to find the $item->data['attributes'][x] that you need.
:-)
Glenn
#3
Thanks glennnz, it's Great!
Please say me where do i need to use this code?
Thanks & Regards,
AnAnD
#4
@Anandyrh
I put this in a custom module, but you could also use this code in the uc_custom_price module.
Glenn
#5
Hi Glenn,
Thank you very much! :)
Let me try it out...
Regards,
AnAnD
#6
A godsend!
Also trying to have a different price for a products attributes based on user role. I saw you made your own module, and also mentioned use in the Uc_customprice module.
If using the custom price module, how does your code change?
Any other helpful hints & tips are greatly appreciated!
#7
@Prodigy
If you use the custom price module, use the same if then statements.
e.g.:
<?phpif ($item->data['attributes'][1] == '1') {
$item->price = 1.50;
}
if ($item->data['attributes'][1] == '2') {
$item->price = 12.50;
}
if ($item->data['attributes'][1] == '3') {
$item->price = 123.50;
}
if ($item->data['attributes'][1] == '4') {
$item->price = 1234.50;
}
?>
Glenn