1
Answers
Vote up!
0
Vote down!

Programmatically Update Product Price From Add Cart Form

Hi,

My client has a huge number of product prices based on customer id and product which often change. The vendor hosts the pricing table on an external server.

I have been trying to modify commerce_cart_add_to_cart_form with my own hook module to
1. Grab the pricing from the external server with drupal_http_request

2. Update the unit price of the line item so that when the using hits the Add To Cart (submit) button, the new price goes into the cart.

I have #1 working fine... I can get the price and assign it to a variable. What I -can't- figure out is #2: how to assign that to the line_item object.

I thought there might be a way to add PHP directly to a pricing rule, but I can't figure -that- out. And when I looked for help on hook_commerce_cart_product_add ... which seems to be the hook I need, I can find no examples.

Any ideas?

TIA,

---JC

Asked by: suntower
on October 10, 2012

1 Answer

Vote up!
0
Vote down!

Working on a Drupal 7 Commerce site. The unit price of each line item will be determined by an external database accessible via http. (The price table is changed often based on customer so we can't just build a large pricing table.) I added a little code into the hook to alter the product form to get the proper price.

What I can't figure out is how to update the form with that price so that when the user clicks 'Add To Cart' my new price updates the new line item in the cart.

I'm sorry I can't put in the actual code (I'm not @ my work computer right now) but I'm sure people who work with Drupal Commerce will know what I'm on about. All the videos I've watched are about using the built-in pricing tables. Can't find anything on programmatically updating the unit price.

regards.
bizworldusa

Answer by: Anonymous (not verified)
Posted: Oct 18, 2012