http://drupal.org/project/commerce
The Problem
- Product Entity Fields: Field Permissions do not currently work on Product Entities. Upon editing any field attached to a product entity, no field permissions settings appear.
- Product Entity Reference Fields: They partially work on Product Entity Reference Fields on Nodes: The add to cart button is hidden, but the price is not.

Proposed Solution
1) The Field Permissions for Product Entity Reference Fields on Nodes should apply to all fields from a Product Entity displayed through a node (so it should hide price, product:sku, product:title if a user does not have the "view" permission)
2) Field Permissions should be possible for Product Entity Fields

If we could get solution #1 working 1st, this would be ideal -> since most of the users access products through the node interface.

Comments

TimelessDomain’s picture

The problem with Commerce (right now) is that it is impossible to hide the product price while still displaying other product data. The solutions i proposed would help fix this. Thanks

TimelessDomain’s picture

So field permissions work for fields on commerce entities, but they do not work for the core commerce:fields (Price).
The workaround I did was to create a decimal field, then i used rules to grab the price to populate the field. Since commerce stores prices in simple digits, I had to divide by 100. Decimal field allowed for a quick prefixing of $ symbol.

This export contains both a decimal field & text field that get populated by the Commerce Price field (works with updates). Attach these fields to the Product Entity.

{ "rules_duplicate_price" : {
    "LABEL" : "Duplicate Price",
    "PLUGIN" : "reaction rule",
    "REQUIRES" : [ "rules", "entity" ],
    "ON" : [ "commerce_product_presave" ],
    "IF" : [
      { "entity_has_field" : { "entity" : [ "commerce-product" ], "field" : "commerce_price" } },
      { "entity_has_field" : { "entity" : [ "commerce-product" ], "field" : "field_price_displayed" } },
      { "data_is" : { "data" : [ "commerce-product" ], "value" : [ "commerce-product" ] } },
      { "entity_has_field" : { "entity" : [ "commerce-product" ], "field" : "field_price_view" } }
    ],
    "DO" : [
      { "data_calc" : {
          "USING" : {
            "input_1" : [ "commerce-product:commerce-price:amount" ],
            "op" : "\/",
            "input_2" : "100"
          },
          "PROVIDE" : { "result" : { "result" : "Calculation result" } }
        }
      },
      { "data_set" : {
          "data" : [ "commerce-product:field-price-displayed" ],
          "value" : [ "result" ]
        }
      },
      { "data_set" : {
          "data" : [ "commerce-product:field-price-view" ],
          "value" : [ "result" ]
        }
      }
    ]
  }
}
klavs’s picture

I too would definetely like field permissions to work - on particular on the price field.

My usecase is for a B2B customer site - where only approved businesses get an account - and thus only approved businesses should be able to see the product price (and add2cart button), but everyone should be able to see the product.

end user’s picture

My usecase is for a B2B customer site - where only approved businesses get an account - and thus only approved businesses should be able to see the product price (and add2cart button), but everyone should be able to see the product.

You can do this with views and blocks. Set up a view with two blocks. Select the fields, one with price and buy b button and one with out, set up the Contextual filters to Content NID, Provide default value "Content ID from URL".

Now for each block set up Access:Role So for registered users select the appropriate role which will see the price and buy button form.

For anonymous users select anonymous user.

Make sure to make changes for the current view and not all views.

Now create a new region in the template_name.info file and print it in the custom node template for whatever node type is used by Commerce. For example in Ubercart its node--product.tpl.php

I use this to print the region

<?php print render(block_get_blocks_by_region('product_buy_buttons')); ?>

product_buy_buttons is the region I created.
regions[product_buy_buttons] = Product Buy Buttons

Now in the block settings select the roles that can view those blocks and select the blocks to show in the new region for your template.

Now if anonymous users view the product page they won't be able to see the price or buy button and only when they log in BUT they can see the rest of the product page. You can see the results here. For anonymous users I show this them this http://www.maximumgrowth.ca/products/green-planet-nutrients/aussie-tonic Registers users see the price and buy button.

mariacha1’s picture

Issue summary: View changes
Status: Active » Closed (won't fix)

Given the age of this request and the workarounds suggested in the ticket, I'm closing this one. People can reopen with patches, if available.