Field Access Permissions

Contrib type: 
Module
Status: 
Complete and working
Moderation: 
Not ready for moderation
Latest version: 
1.0

Downloads

Compatibility: 
Ubercart 1.x

Sponsor: end user
Developer: Sundays Energy

This module allows you to control the visibility of each ubercart field based on a user role. For example you could hide the "add to cart" button and sell price but display the list price for anonymous users. Access to the fields is controlled in the usual /admin/user/access area.

PreviewAttachmentSize
uc_field_access.zip1.98 KB
Ryan's picture
Offline
Joined: 08/07/2007
Juice: 15450
Re: Field Access Permissions

Sounds very useful! Thanks for posting. Smiling

buntstich's picture
Offline
Joined: 07/11/2008
Juice: 2
edit-qty

It is possible to hide the edit-qty field?

buntstich

studioridge's picture
Offline
Joined: 07/16/2008
Juice: 8
"add to cart" button, not directing to shopping cart

For some reason, the "add to cart" buttons don't want to redirect to the shopping cart page but rather just reload the same page. This was not always the case and I am not sure what settings have changed. The settings on "Configurations > Cart Settings > Add to Cart Redirect" is just "cart" and this is the same as when it was working.

The product is added to the cart and a new text line is added to the top of the page with the product name and then "...added to your shopping cart." witht he last part as a link to your shopping cart.

You can test it here, http://womenhelpingwomen.com/store/annual-membership
or you can see the screenshot that shows the new line of text.

AttachmentSize
whw-screenshot.jpg 53.18 KB
Ryan's picture
Offline
Joined: 08/07/2007
Juice: 15450
Re: "add to cart" button, not directing to shopping cart

It actually worked fine for me... I wonder if there was some other issue. Looking at the source for this contrib I don't see anything that affects what happens when the add to cart form is submitted.

studioridge's picture
Offline
Joined: 07/16/2008
Juice: 8
Re: "add to cart" button, not directing to shopping cart

Ryan,
Thanks for the quick reply. It works now because I had to uninstall the "wish list" module. I think it was treating the product differently.

Sam

matteblacke's picture
Offline
Joined: 08/06/2008
Juice: 17
Re: Re: "add to cart" button, not directing to shopping cart

i keep getting the following error when i put this module in the sites/all/modules directly

Parse error: syntax error, unexpected '&', expecting T_VARIABLE or '$' in /home/www/urhirtwsh/uber/sites/all/modules/uc_field_access/uc_field_access.module on line 110

can anyone help?

thanks

Ryan's picture
Offline
Joined: 08/07/2007
Juice: 15450
Re: Re: Re: "add to cart" button, not directing to shopping cart

Looks like the module uses a PHP 5 specific feature of foreach(). Any way you can update the version of PHP on your web server?

matteblacke's picture
Offline
Joined: 08/06/2008
Juice: 17
Re: Re: Re: Re: "add to cart" button, not directing to shopping

Thanks Ryan, makes sense. thay only have v4 point something.

I'll look into modifying the code unless anyone has a suggestion?

thanks

matteblacke's picture
Offline
Joined: 08/06/2008
Juice: 17
Re: Re: Re: Re: Re: "add to cart" button, not directing to shopp

i've just commented out the following (pretty much flying blind but i don't have the wish list installed anyway) tell me if it's going to do some bad... but it seems to work fine now.

<?php
function uc_field_access_form_alter($form_id, &$form)
{
   
$product=$form['#parameters'][1];
   
$cid=$product->type;

    if(

$form_id == 'uc_product_add_to_cart_form_' . $form['nid']['#value'])
    {
        if (!
user_access('view '.$cid.' add_to_cart'))
        {
           
$form['submit']['#access'] = false;
        }       
    }

   

//if (($form_id == 'uc_wishlist_view_form'))
    //{
    //    foreach ($form['items'] as $key => &$value)
    //    {
    //        if (!user_access('view '.$cid.' add_to_cart'))
    //        {
    //            $value['addcart']['#access'] = false;
    //        }
    //        if (!user_access('view '.$cid.' display_price'))
    //        {
    //            $value['#total'] = 0;
    //        }
    //    }
    //}
}
?>
Ryan's picture
Offline
Joined: 08/07/2007
Juice: 15450
Re: Re: Re: Re: Re: Re: "add to cart" button, not directing to s

It looks to be specific for the wishlist form, so if you're not using the wishlist module I wouldn't worry about it.

ubernewbie's picture
Offline
Joined: 05/03/2008
Juice: 43
Permissions Ignored with my Setup

Thanks for the module.

Having some problems.

I've overridden the product display page, as per the "nifty products" tutorial.

I've added this code to my node-product.tpl.php:

<?php if($node->content['cost']["#access"]) { print $node->content['cost']["#value"];} ?>
<?php if($node->content['sell_price']["#access"]) { print $node->content['sell_price']["#value"];} ?>

For some reason, the sell_price is getting hidden for anonymous, but the "cost" field will not display for anyone, even admin.

Could you help?

cyb.tachyon's picture
Offline
Joined: 12/16/2008
Juice: 2
Update for Drupal 6.x

Just made it fully compatible for Drupal 6.x. Thanks webmasterkai and Sundays Energy for the original; I love it and am glad you saved some dev time.

Enjoy!

p.s. Works great for me, but I'm not responsible for any problems.

AttachmentSize
uc_field_access.zip 2.19 KB
dimanic's picture
Offline
Joined: 11/30/2008
Juice: 2
Drupal 6 Works excellent

Drupal 6
Works excellent only if you don't use Views2, otherwise price still appears.

Bartezz's picture
Offline
Joined: 04/18/2008
Juice: 104
Re: Field Access Permissions

Nice module, thanx for sharing. One problem tho, if you have uc_product_table setup to have a 'add to cart' button it will be there, even if you have disabled it for anonymous users with your module... Is there a fix to this except for hiding the button from uc_product_table Smiling

Cheers

end user's picture
Offline
Joined: 01/11/2008
Juice: 1685
Re: Field Access Permissions

I noticed that if I override

function theme_uc_catalog_product_grid($products) {
code
}

with

function mytemplate_uc_catalog_product_grid($products) {
code
}

in my template.php file then the grid access controls don't work anymore.

What can I do to solve this?

Thanks
Arek

end user's picture
Offline
Joined: 01/11/2008
Juice: 1685
Re: Re: Field Access Permissions

Hmm for now I'll just have to change the core file.

bighead's picture
Offline
Joined: 03/07/2009
Juice: 90
Re: Re: Field Access Permissions

Have you solved this problem? How?

guodskrap's picture
Offline
Joined: 02/12/2009
Juice: 35
Grid alignment shift

Greetings,

I am running Drupal 6.x using the Zen Classic theme. When I install Field Access Permissions and hide pricing for anonymous users, the layout of the grid is getting shifted. Essentially, instead of having the title over the image, it's next to it (the same with the price, but I'm trying to hide that). Unfortunately, it completely spoils the look of the catalog, leaving it a jumbled mess.

Can you tell me where the module is making these changes so that I can iron out how to sustain the layout while using the module?

Thanks.

guodskrap's picture
Offline
Joined: 02/12/2009
Juice: 35
Re: Grid alignment shift

Ah, I found that if I add breaks into the uc_field_access.module, I can make it display correctly.

testingUB's picture
Offline
Joined: 07/01/2009
Juice: 10
Views - problems

Hi. I've just tested your module (the one on comment #12) in Drupal 6 with Ubercart 2.x.

As for the other users, I've founded that Views does not respect the permissions set. Can you please point me out where to start to make the module compatible with Views?

LoveGolf's picture
Offline
Joined: 10/16/2008
Juice: 106
Re: Views - problems

This doesn't happen to work w/ attributes as well? Need to change the price of attributes based on users role. Will sponsor. Contact me.

tomsm's picture
Offline
Joined: 03/02/2009
Juice: 17
Tested with Ubercart 2.rc7, Drupal 6.14, Views 3.x-dev

The Add to cart button is gone, but Quantity field is still shown for anonymous users.
In views the Sell price and the Add to cart button are still shown.

Is there a solution for this?

ColinMctavish's picture
Offline
Joined: 11/04/2009
Juice: 2
Catalog Grid Titles and Quantity Field

Hi, I am confused about how to fix the grid titles in the catalog. It became off center after using this module. Also, is it possible to disable the quantity field for an anonymous user and have it be seen by an authenticated user?

Great work besides those two problems..

Cheers

guodskrap's picture
Offline
Joined: 02/12/2009
Juice: 35
6.15 compatibility

Greetings,

Any plans on upgrading this module to be compatible with Drupal 6.15?

Thanks,

Doug.

alexJohnston's picture
Offline
Bug Finder
Joined: 08/28/2009
Juice: 14
First step to a Ubercart 2.x Version?

Perhaps starting with this will help someone polish a port of this module for Ubercart 2.x.

I'm really green at this so I don't know how good it is but it works for me. The only thing I know is wrong with it is the lack of a .install file which I have no clue how to author.

AttachmentSize
UNTESTED Port of uc_field_access module for Ubercart 2.0 2.84 KB

~~~~~~~~~~~~~
Alex Johnston
~~~~~~~~~~~~~

mm
mm's picture
Offline
Joined: 12/05/2008
Juice: 26
Re: Field Access Permissions

it seems it's not working with product kits

Scott M. Sanders's picture
Offline
Joined: 04/24/2009
Juice: 326
Works for Me

It works great for me. Smiling It could use product kit support though.

Bartezz's picture
Offline
Joined: 04/18/2008
Juice: 104
Re: Field Access Permissions

http://www.ubercart.org/forum/support/15406/hide_price_add_cart_anonymou...

Looks like there was a bug that got fixed in the D6 version?

Cheers