Tags/topics: 
11
Answers
Vote up!
0
Vote down!

Per user pricing

I'm trying to work out a way to change the price for each user. Basically certain customers are going to be given a special price for various products.

In my mind the best way to do this is to create a new entity with a product reference field, User reference and price.

The part I'm having trouble with is the pricing rule, as I would need to be able to retrieve the appropriate entity based on uid and product_id to get the price. From what I can gather though this doesn't seem possible.

Does anyone have any suggestions on a way around this.

Asked by: dottodotdesign
on March 28, 2013

11 Answers

Vote up!
4
Vote down!

I did it in one of my projects.

Following are the steps I followed:

1. Add a field called wholesale_price to the product.

2. Add a role called wholeseller (only if you want to set price by role)

3. Create a product pricing rule:

When calculating the sell price of an order
Condition: Entity has field => Entity: commerce-line-item:commerce_product
Condition: Entity has field => Entity: commerce-line-item:commerce-product: field_wholesale_price

opt A. (to check by roles)
Condition: User has roles: site:current-user, Roles: wholeseller

-- or --

opt B. (to check by user id)
Condition: Add new condition: site:current-user:uid, whateveruserid

Action: Commerce Line Item: Set the unit price to a specific amount: Parameter: Line item: [commerce_line_item], Value: [commerce-line-item:commerce-product:field-adminprice:amount]

Following is the Export of Rule:

{ "rules_wholesale_price_for_wholesellers_of_accessories" : {
"LABEL" : "Wholesale Price For Wholesellers if has wholesaleprice field",
"PLUGIN" : "reaction rule",
"REQUIRES" : [ "rules", "commerce_line_item", "commerce_product_reference" ],
"ON" : [ "commerce_product_calculate_sell_price" ],
"IF" : [
{ "entity_has_field" : { "entity" : [ "commerce-line-item" ], "field" : "commerce_product" } },
{ "entity_has_field" : {
"entity" : [ "commerce-line-item:commerce-product" ],
"field" : "field_wholesale_price"
}
},
{ "user_has_role" : {
"account" : [ "site:current-user" ],
"roles" : { "value" : { "6" : "6" } },
"operation" : "OR"
}
}
],
"DO" : [
{ "commerce_line_item_unit_price_amount" : {
"commerce_line_item" : [ "commerce_line_item" ],
"amount" : [ "commerce-line-item:commerce-product:field-wholesale-price:amount" ],
"component_name" : "base_price",
"round_mode" : "1"
}
}
]
}
}

note : you have to change the value in "roles", which is 6 in my case

I hope this helps.

Answer by: drupalastic
Posted: Apr 4, 2013

Comments

Unfortunately my situation is more complicated as it's more a case of each user having having their own personal price, so for example there could be 100 customers each with their own unique price for a certain product.

This is why I was thinking that a separate entity that links to the user and the product with the custom price would be the best way. I just can't work out a rule that would fetch the correct entity an then apply the price.

- dottodotdesign on April 4, 2013

Hi,
My situation was almost the same as yours, we created a rule useing option (b)

opt B. (to check by user id)
Condition: Add new condition: site:current-user:uid, whateveruserid

And we keep cloning the rule and changing the user id for every new customer.

It may sound a little complicated but it is very easy manage and takes less than a minute for every new customer.

- drupalastic on April 5, 2013
Vote up!
0
Vote down!

Hi,
my project needs to be able to have different prices for products per user. So we have 1000 users and 4000 products. Every user have different price per product, based on our ERP product price lists. So how can we use these price lists of user on drupal commerce. We will develop a sync of our ERP db (with users and price lists) to drupal db with some new table.

So if we have these references of user-price-product on drupal db, how could we extend the price of our products in drupal on views with the right price per user? Is it possible with rules an some custom modules? Or it is impossible?

Answer by: tarasiadis
Posted: Aug 3, 2013
Vote up!
0
Vote down!

Hi,

Using this great rule I got the following debug messages:
- Unable to evaluate action commerce_line_item_unit_price_amount.
- Unable to get the data value for the variable or parameter amount. Error: Unable to get the data property amount as the parent data structure is not set.

Anyone has this same situation or a solution?
greetings, Martijn

Answer by: Summit
Posted: Dec 6, 2013

Comments

Summit, I m sure you have gone through following videos : commerceguys
If not, its worth time...

What is looking obvious to me that commerce_line_item_unit_price_amount is not under scope of rule or some thing like that.. going through these videos will make it clear & easy..

Hope it helps..

- drupalastic on December 8, 2013
Vote up!
0
Vote down!

Hi @Drupalastic, Can you tell which video specifically? I can;t get the condition working like Entity has Field...
greetings, Martijn

Answer by: Summit
Posted: Dec 9, 2013

Comments

some modules like client side validation etc, breaks the Jquery of rules drop down... Please make sure there is no such issue....

- drupalastic on December 11, 2013
Vote up!
0
Vote down!

Hi,
I did look through the video, but couldn't see what I am missing with the rule above.
You say commerce_line_item_unit_price_amount is not under scope of rule.
But how is it then possible that it is working in your rule above?

I tried adding a data comparison as explained in the video, but no go.
How can I get commerce_line_item_unit_price_amount under the scope of the rule?

I tried all sort of things, but still same errors:
- Unable to evaluate action commerce_line_item_unit_price_amount.
- Unable to get the data value for the variable or parameter amount. Error: Unable to get the data property amount as the parent data structure is not set.

Can you help me please? Thanks a lot in advance!
Greetings, Martijn

Answer by: Summit
Posted: Dec 12, 2013
Vote up!
0
Vote down!

Hi,
I think I solved it adding those things to the rule, is this correct.
To have order in scope? Is the Data comparison necessary?

{ "rules_wholesale_price_for_wholesellers_of_accessories" : {
    "LABEL" : "Wholesale Price For Wholesellers if has wholesaleprice field",
    "PLUGIN" : "reaction rule",
    "REQUIRES" : [ "rules", "commerce_line_item", "commerce_product_reference" ],
    "ON" : [ "commerce_product_calculate_sell_price" ],
    "IF" : [
      { "entity_has_field" : { "entity" : [ "commerce-line-item" ], "field" : "commerce_product" } },
      { "entity_has_field" : {
          "entity" : [ "commerce-line-item:commerce-product" ],
          "field" : "field_wholesale_price"
        }
      },
      { "entity_has_field" : {
          "entity" : [ "commerce-line-item:order" ],
          "field" : "field_wholesale_price"
        }
      },
      { "data_is" : {
          "data" : [ "commerce-line-item:commerce-product" ],
          "value" : [ "commerce-line-item:commerce-product" ]
        }
      },
      { "user_has_role" : {
          "account" : [ "site:current-user" ],
          "roles" : { "value" : { "4" : "4" } },
          "operation" : "OR"
        }
      }
    ],
    "DO" : [
      { "commerce_line_item_unit_price_amount" : {
          "commerce_line_item" : [ "commerce_line_item" ],
          "amount" : [ "commerce-line-item:commerce-product:field-wholesale-price:amount" ],
          "component_name" : "base_price",
          "round_mode" : "0"
        }
      }
    ]
  }
}

Greetings, Martijn
Answer by: Summit
Posted: Dec 13, 2013

Comments

Hi, I have a more complicated situation!

I need one pricelist per user! What I mean:
I have 500 customers that have different price per product on my ERP. So one pricelist per user.
I have 1000 products.
So, have I need to create 500x1000=500000 rules?

I search something about pricelist er user to use them during order.

Some help on this please?
Thanks

- tarasiadis on February 4, 2014

Hi tarasiadis,
I'm having the same situation - different prices for customer and per product. Have you find any solutions?

- fintelligent on June 11, 2014

No I have not find any solution until now.

But my thoughts is to have my pricelist on a db and make a drupal commerce custom rule to calculate the final price per user.
I have create a new topic at https://drupalcommerce.org/comment/10033

I 'll try next days to do some experiments on this and I'll inform. If somebody could help us please post some ideas.

- tarasiadis on August 26, 2014
Vote up!
0
Vote down!

Hi,
This is not working...
I keep getting the errors:
- Unable to evaluate action commerce_line_item_unit_price_amount.
- Unable to get the data value for the variable or parameter amount. Error: Unable to get the data property amount as the parent data structure is not set.

I tried also to mimic the sale_price rule, but with the field_wholesale_price.
All the time these warnings in my log.

Can you help me please?
Thanks a lot in advance, greetings, Martijn

Answer by: Summit
Posted: Dec 16, 2013
Vote up!
0
Vote down!

The complete error is:

0 ms Rule Wholesale price (Rules component) fires.
1.638 ms Unable to get the data value for the variable or parameter amount. Error: Unable to get the data property amount as the parent data structure is not set.
2.53 ms Unable to evaluate action commerce_line_item_unit_price_amount. [edit]
2.572 ms Rule Wholesale price (Rules component) has fired.

greetings, Martijn
Answer by: Summit
Posted: Dec 16, 2013
Vote up!
0
Vote down!

Hi, I read all of this also: http://www.drupalcommerce.org/user-guide/product-pricing-rules-screencasts and there I see this remark:

However if you are on a pricing rule event “Calculating the sell price of a product” (line item) end you bring the product and then the stock field using two “Entity has field” conditions, then you don’t get access ):

Somehow I think I do not have access to: commerce_line_item_unit_price_amount ...while I use entity has field and data comparison...

greetings, Martijn

Answer by: Summit
Posted: Dec 16, 2013
Vote up!
0
Vote down!

Hi, I have a more complicated situation!

I need one pricelist per user! What I mean:
I have 500 customers that have different price per product on my ERP. So one pricelist per user.
I have 1000 products.
So, have I need to create 500x1000=500000 rules?

I search something about pricelist er user to use them during order.

Some help on this please?
Thanks

Answer by: tarasiadis
Posted: Jan 11, 2014
Vote up!
0
Vote down!

Hi, I have a more complicated situation!

I need one pricelist per user! What I mean:
I have 500 customers that have different price per product on my ERP. So one pricelist per user.
I have 1000 products.
So, have I need to create 500x1000=500000 rules?

I search something about pricelist er user to use them during order.

Some help on this please?
Thanks

Answer by: tarasiadis
Posted: Feb 4, 2014