Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Can I modify prices of base products and attributes based on a user's role?
Thanks
Glenn
Comments
Comment #1
abramo CreditAttribution: abramo commentedYes : example:
or
hope this helps.
Comment #2
glennnz CreditAttribution: glennnz commentedHi
I can't get this to work...
Below is what I'm using to test.
The module works fine if I use just:
But when I use
the price doesn't change for a user with that role...
Thanks
Comment #3
glennnz CreditAttribution: glennnz commentedAlso, is there a way to make the displayed price on the product node change?
At the moment, the price is only being modified when the product is added to the cart.
Thanks
Comment #4
glennnz CreditAttribution: glennnz commentedThis is what I really want to do:
global $user;
if (in_array('member', $user->roles) && '[modules]' == 'theory only')
{
$item->price = '1500';
}
if (in_array('member', $user->roles) && '[modules]' == 'software only')
{
$item->price = '1850';
}
Is this correct?
Also, should the attribute tokens be '[attribute]' or ['attribute']?
Thanks
Glenn
Comment #5
mrfelton CreditAttribution: mrfelton commentedI don't think you can not use this module to alter the display price. The price modification only affects the price at checkout and it is your responsibility to inform the user if and when discounts/fees may be applied, probably in the product's description. Perhaps you could try the uc_discounts module instead (http://drupal.org/project/uc_discounts), although I'm not really sure if price adjustments are displayed to the user with that module either.
Regarding the token - as far as I know there should only be quote marks if your token holds a string. For example,
[cost] = 4. Then:
[cost] = 'string'. Then:
Hope that makes sense.
Comment #6
glennnz CreditAttribution: glennnz commentedGreat, thanks
The if statement still doesn't work though...
Comment #7
mrfelton CreditAttribution: mrfelton commenteduse the devel module to inspect your array? Perhaps it isn't what you think it is?
Comment #8
glennnz CreditAttribution: glennnz commentedUmmmm.... I downloaded and installed the devel module, but can't see the user array.
I tried testing this previously by using:
and this worked fine. It's just when I put the $item->price = $item->price*3; in there that it doesn't work...
I desperately need to get this sorted out, I can call you if you are happy for me to? Email me if this is so.
Thanks
Glenn
Comment #9
glennnz CreditAttribution: glennnz commentedOK, still not working, some more info.
With this code:
it works perfectly for the administrator, but not for anyone else....
HELP!!!!!!!
Thanks
Glenn
Comment #10
mrfelton CreditAttribution: mrfelton commentedHi Glenn,
Sorry I didn't respond for so long. My computer died and I had to get an entire new development environment set before I could continue with this stuff. Are you still having trouble with this?
Comment #11
mrfelton CreditAttribution: mrfelton commentedComment #12
glennnz CreditAttribution: glennnz commentedHi
Yes, have played a little, with no luck at all.
My test code (which is not working at all) is:
Thanks
Glenn
Comment #13
mrfelton CreditAttribution: mrfelton commentedYour very first example works absolutely fine for me... In the Custom Price Calculation textarea I enter:
When I add the product to my cart, the price shows £1000 more expensive that it was listed in the product page.
Unfortunately I do not have a Drupal 5 setup at the moment, but it should be working in exactly the same way and there are currently a handful of people using it on Drupal 5 sites successfully. When I ported this module to Drupal 6 I did make it clear that I wouldn't be supporting the Drupal 5 version so if you need more help with this, cYu is going to be your man as he is the original author and maintainer of the Drupal 5 version of this module. Alternatively, if you upgrade to Drupal 6 and still have the problem I will be more than willing to peruse this with you.
Comment #14
glennnz CreditAttribution: glennnz commentedVery strange
Your code works fine for some users, not for others. I'll chat with cYu. Thanks.
Comment #15
Prodigy CreditAttribution: Prodigy commentedPerhaps some of you are trying for Drupal 5 and some for Drupal 6?
Comment #16
Scott M. Sanders CreditAttribution: Scott M. Sanders commentedThis is (almost) exactly what I need for distributor pricing, thanks!
Comment #17
Prodigy CreditAttribution: Prodigy commentedUsing 6 or 5 Scott? And which solution worked for you?
Comment #18
Scott M. Sanders CreditAttribution: Scott M. Sanders commentedd6 -- and actually it almost works, except that I will need to recalculate all of the product prices based on the final order subtotal and against a fixed three-column, tiered distributor pricing sheet that I was given. It's close though. :)
Comment #19
Prodigy CreditAttribution: Prodigy commentedI'm trying to do something really similar and am curious if it can be accomplished through use of this module.
I need to change the price of 4 different attributes based on the users role.
Below is the code for changing the base price ... may I get some assistance in how to change attributes prices?
Comment #20
glennnz CreditAttribution: glennnz commented@Prodigy
Here is the code snippet for mine:
You just need to figure out the values of your attributes. In this case it was Attribute 1, Option 4.
Cheers
Glenn
Comment #21
Prodigy CreditAttribution: Prodigy commentedThanks Glenn! Linking the two as the 2 issues are near in the same http://drupal.org/node/366525
Comment #22
DrPhunk CreditAttribution: DrPhunk commentedCan anyone suggest how one might pull other node fields into this equation? We want multiple set prices for each product that aren't based off a common percentage or amount added / subtracted. What I would like to do is pull in a CCK field value and set it as the price with a fallback to the retail price, e.g.
This doesn't work for me, can anyone offer some help?
Edit - duh, needed to load the node data :P Is there a more efficient way than loading the entire node data set?
Comment #23
mrfelton CreditAttribution: mrfelton commentedI think node_load is the most efficient way of loading an entire node, since it benefits from static caching. I don't know of a better way. If you only wanted specific bits of data, it may be better do do a few manual database queries, however since you are pulling data from cck fields, and those can be stored in a number of different ways, node_load is probably your best bet
Comment #24
TR CreditAttribution: TR commentedI'm going to marked this as "fixed" and close the issue. This seems to have become a catch-all issue, and as far as I can tell most if not all the various unrelated questions have been answered. If there are still outstanding problems, please open a new issue for your question.