I am trying to build a store where the customer can put their own value into a line item field, that adjusts the price of the product.

I used rules to take the value (in inches), calculated a new value from that, and converts it into a dollar amount and add it to the product price. It all works, except for two issues:

  1. Commerce tries to read the field value in cents, so it divides it by 100. This is okay because I just calculated a value and multiplied it by 100. However, if the value is a decimal value, it drops off the decimal values and they are lost when I do the multiplication.
  2. The rules event is done when "Calculating the sell price of the product" so it adjusts it when I add the product to the cart, but it would be great if the price adjusted while still on the page.

I know that it a tall order, so any help would be greatly appreciated! Thanks in advance!

Comments

rszrama’s picture

Assigned: abluem97 » Unassigned
Status: Active » Closed (duplicate)

There's a video on this exact topic at http://www.drupalcommerce.org/videos/tutorials/donations-custom-line-ite.... Please search drupalcommerce.org for your future support requests and use http://www.drupalcommerce.org/questions if you can't find an answer.

abluem97’s picture

Thanks for the reply rszrama.

I did watch that tutorial, and that got me most of the way there, it was just those last couple of hangups that I couldn't figure out. I would have really like to make this work in commerce, but i'm leaning towards bailing on it and using Ubercart now.

rszrama’s picture

Sure, I suppose my old UC Variable Price module may still work; not sure if it's being maintained atm. You should've mentioned the video I suppose, and you can definitely post follow-up questions on DC.org. I don't see any reason why your concerns can't be answered.

fwiw, your question #2 exists in an open feature request in this queue, and Ubercart wouldn't support that anyways. I don't think you provided enough information here for #1 to be answered yet, but if you can repost with more detail at the dc.org/questions link above, I'm sure you can get help.

rszrama’s picture

Issue summary: View changes

Also, if I set the rule event to "Before Adding a product to the Cart", I get "Error: Data selector commerce-line-item for parameter entity is invalid"

virtualwaves’s picture

Is there a solution for Drupal 8 similar to the one Randy Fey described in his tutorial in 2011? I'm basically looking for a donation amount picker to be used as the price of the product. I've got the order item type all configured so that people can pick their donation. What I'm missing now is how to set up the product pricing rule. The D8 module price rule https://www.drupal.org/project/commerce_price_rule doesn't seem to do that. Am I missing something? Thank you!