0

Our Goal

We're creating a book product. It comes in a variety of sizes (ex. 5x5, 8x8, 10x10) with 20 pages included. We're using the size as an attribute field. Customers can order a standard book, or add additional pages up to 100 total pages. Additional pages are priced /page and /size; for example 5x5 = $1.00/page, 8x8 = $1.50/page etc. The "Add to Cart" section should look something like this:

===========================

BOOK

  • Size [5x5]
  • Pages [ enter amount ]

Total: $75.00 [Add to Cart]

===========================

The simplest solution would be to add a pricing option with its own quantity field, except that functionality doesn't seem to be available.

I've considered the following:

  • Commerce Option I: Creating a pricing attributes option (select list or radio button styles as a slider). The only caveat is the admin on adjusting pricing for 4000 options (50 books with 80 page options each) is a usability nightmare.
  • Commerce Option II: Creating a pricing attributes integer field (acting as a quantity field) and using Rules to do the math and adjust the pricing. Unfortunately the variables and math did not seem to be available to Rules.
  • Commerce Product Bundle: Creating a pages product variation and using page size as an attribute field. That would allow us to leverage the quantity field in the bundle's add to cart display. The problem in this case is two fold:
    1. Having to create 3 product variations, then having to create at least 2 products (book and book/pages bundle; 3 if you have different papers or page pricing needs to vary) each time you add a new book to your collection. This very quickly creates something close to an administrative hell for the shop owner.
    2. Commerce Product Bundle is still in Alpha, and has been for 2 years. No commits have been made in over a year. The module, even though it often works well, is buggy and doesn't play well with Commerce Option; which we leverage quite substantially.
  • Custom Line Item: Using Randy Fay's "custom line item custom discount technique" leveraging an integer field and rules. I added an integer field to the product variation for cost per page. Then created an integer field which needed to be exposed to the customer. Using the combination of both I attempted to create a rule which calculated the additional price based on the product of the those fields. It does not appear that this is possible using Rules.

Conclusion, and request for additional brain power

I've gone around multiple circles trying to figure this one out and am about to go completely bonkers. Perhaps I'm missing something completely simple, or I'm approaching this problem from the wrong angle. Has anyone been able to do something similar? How did you achieve it?

1

Commerce by default supports line item fields that can appear on the Add to Cart form. If you only sell this one type of product on the site and will always need that "additional pages" field, then you could just add the field to the default product line item type. If you have other needs, you'd use a custom line item type either defined in code or created via https://drupal.org/project/commerce_custom_product.

Once you have customers putting in their custom number of pages, it's up to you to adjust the price accordingly. Pricing rules receive the full line item object for price manipulation, including the values of any line item fields present on the Add to Cart form. You can construct a variety of rules that look at the referenced product to determine how much to charge for additional pages and work it out using the Rules actions to create data values.

  • Thanks Ryan. I attempted this using commerce_custom_product by adding quantity field to a custom line-item and a price field to the product variation type. Unfortunately when using a pricing rule I was only able to access the field in the line item, but could find no way of getting the field on the product variation to load. "You can construct a variety of rules that look at the referenced product..." This was the part I couldn't get to work. Looking at Randy Fay's tutorials as well as itangelo's series on rules I still couldn't figure out how to expose those fields. – FranCarstens Jan 8 '15 at 5:04
  • Is it because you haven't used the "Entity has field" condition yet to tell Rules the field existed on the entity? – Ryan Szrama Jan 9 '15 at 2:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.