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

Can I make price a field that is not required?

I have a handful of products sold in bulk that get custom pricing. I've created a field called "Call for Price" that, when checked, is supposed to disable the Price field. However, it does not and I cannot submit the variation without a price. How do I make price a field that is not required?

Asked by: abiconsulting
on April 7, 2013

1 Answer

Vote up!
1
Vote down!

The trick is to standardize on a price field that is not dependent on a code implementation. Unfortunately, you can't disable a field that is defined in code. This is known as a "core quirk" and I found at least one developer mention it openly in regards to a different module:

http://drupal.org/node/1649096#comment-6143472

See point #1 that guy makes about a field that's defined in code.

So, the default line item type has a price field that is defined in code. For example, if you go here to try and edit the default line item price field: admin/commerce/config/line-items/product/fields/commerce_unit_price you will get the following "notice"

The field Unit price is locked and cannot be edited.

This is by design, partially due to the fact that prices are constantly being re-calculated for each new user (this is designed to allow for user-specific pricing).

How do you get around this design? I'm guessing here, but pretty sure you have two options:

1) You could use http://drupal.org/project/commerce_custom_product and create a new "non-default" line item type with a price field that is not required.

or

2) You could create a rule that simply sets the price to zero if the checkbox "Call for Price" is checked

I tend to think option #2 makes the most sense as it works within the standard system without requiring yet another module.

Josh Miller
Answer by: Josh Miller
Posted: Apr 8, 2013

Comments

Interesting. Thank you very much for your help. I think I could change the price to $0 or $9999 or something and then hide the Add To Cart button. That might be a decent solution. A custom product could work here as well, but might make for a headache as really this is a variation of a product - they're sold in say, 10#, 50# or bulk (truckload, etc) sizes. Re-entering all the other fields for a custom product for ~1/3 of the products seems like a lot of work (and crazy-making). I'll try your second suggestion with some dependencies and see what happens.

Thanks again.

- abiconsulting on April 8, 2013