Reputation: 386
I have created a simple e-commerce application that calculates a price based on many options.
The price is calculated in PHP based on a bunch of variables stored in MySQL. I have coded the PHP as a web service which I use jQuery AJAX to query.
I need to integrate this into a client's existing e-commerce site, which is using Magento.
I want to allow customers to add my "dynamic priced product" to their cart. I need to be able to add the custom price along with the product information (which I am happy to have in a single hidden field).
I am familiar with programming (client and server side, most languages) but I am not at all familiar with Magento. Is there a simple way of achieving this? Ideally I would add the information to an existing form.
Upvotes: 2
Views: 1925
Reputation: 17656
The easiest way I can think of is to create a product in magento to use as a template.
Then create a observer
<events>
<sales_quote_add_item>
<observers>
<priceupdate_observer>
<type>singleton</type>
<class>mymodule/observer</class>
<method>updatePrice</method>
</priceupdate_observer>
</observers>
</sales_quote_add_item>
</events>
Then in your observer method you does something like this:
public function updatePrice($observer) {
$event = $observer->getEvent();
$quote_item = $event->getQuoteItem();
$new_price = <insert logic to check if this is the custom product and to get value from ajax>
$quote_item->setOriginalCustomPrice($new_price);
$quote_item->save();
}
(note that a user could always fake the post and change the item price)
See Customize Magento using Event/Observer
Upvotes: 1