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

Comments

Anandyrh’s picture

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

glennnz’s picture

@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:


function 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

Anandyrh’s picture

Thanks glennnz, it's Great!

Please say me where do i need to use this code?

Thanks & Regards,
AnAnD

glennnz’s picture

@Anandyrh

I put this in a custom module, but you could also use this code in the uc_custom_price module.

Glenn

Anandyrh’s picture

Hi Glenn,

Thank you very much! :)

Let me try it out...

Regards,
AnAnD

Prodigy’s picture

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!

glennnz’s picture

@Prodigy

If you use the custom price module, use the same if then statements.
e.g.:

if ($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