Hi

I'm writing a module which changes the prices of products when they are added to the cart, depending on a users roles.

If I am logged in as Admin it works perfectly. For any other user it doesn't work at all. I've spent ages on it and can't figure it out; I'm wondering if it has something to do with hook_perm().

Can anyone help, I'm fast running out of time to get this website launched, and this is a key part.

Thanks

Glenn

role_price.module

<?php

function role_price_perm() {
  return array('access role prices');
}

function role_price_cart_item($op, &$item) {
global $user;
$access = user_access('access role prices');
if ($access == TRUE) {
  switch ($op) {
    case 'load':
      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';
      }
    }
  }
}
?>

Comments

glennnz’s picture

Bump

Glenn
THECA Group

glennnz’s picture