The question does not state whether this should be done by adding some logic to the code or not. So since you have answers for developer there is also something that is called cart price rules (in admin panel go to Promotions > Shopping Cart Price Rules) where you can create different rules for making sales and discounts (with or without coupons).
To change product price while adding product to cart, use an observer event.
Follow the steps given below
1. Add an observer in your module config.xml file.
2. Create an observer file in your model
3. add checkout_cart_product_add_after event
class MGS_Rileytheme_Model_Observer {
public function modifyPrice(Varien_Event_Observer $observer) {
//$order = Mage::registry('current_order'); For getting current order
//$orderid = $order->getRealOrderId(); For getting orderid
$quote_item = $observer->getQuoteItem();
$payment = 30; //add your custom product price here and do your logic here
$quote_item->setOriginalCustomPrice($payment);
$quote_item->save();
return $this;
}
}
<?php
//Notes
class Ajax_ProductAdjust_Model_Observer
{
public function _construct()
{
}
public function getNewPrice()
{
//Your new functionality here
//
$newprice = "";
return $newprice;
}
public function updatePrice( Varien_Event_Observer $observer )
{
$event = $observer->getEvent();
$quote_item = $event->getQuoteItem();
$new_price = $this->getNewPrice();
$quote_item->setOriginalCustomPrice($new_price);
$quote_item->save();
}
}
You can use an observer class to listen to checkout_cart_product_add_after, and use a product’s “Super Mode” to set custom prices against the quote item.
In your /app/code/local/{namespace}/{yourmodule}/etc/config.xml:
And then create an Observer class at /app/code/local/{namespace}/{yourmodule}/Model/Observer.php
<?php
class <namespace>_<modulename>_Model_Observer
{
public function modifyPrice(Varien_Event_Observer $obs)
{
$customPrice = Mage::getSingleton(’core/session’)->getCustomPriceCalcuation(); // Provide you price i have set with session
$p = $obs->getQuoteItem();
$p->setCustomPrice($customPrice)->setOriginalCustomPrice($customPrice);
}
}
As righty answered by Gershon Herczeg, Jürgen Thelen and Xman Classical. You will need to write a observer of sales_quote_add_item event.
When any product is added to cart your observer will be triggered. If the product is Configurable then this event will be fired twice, You will have to something like that to get simple product only.
$item = $observer->getEvent()->getQuoteItem();
$quote = $item->getQuote();
$product = $item->getProduct();
if ($product->getTypeId() != "configurable") {
//Do your thing here
}
The question does not state whether this should be done by adding some logic to the code or not. So since you have answers for developer there is also something that is called cart price rules (in admin panel go to Promotions > Shopping Cart Price Rules) where you can create different rules for making sales and discounts (with or without coupons).
File: app/code/local/Namespace/Module/etc/config.xml
eg: app/code/local/MGS/Rileytheme/etc/config.xml
File:app/code/local/MGS/Rileytheme/Model/Observer.php
Soup to Nuts.
File: /app/etc/modules/config.xml
File: /app/code/local/Ajax/ProductAdjust/etc/config.xml
File: /app/code/local/Ajax/ProductAdjust/Model/Observer.php
Cheers,
You can use an observer class to listen to checkout_cart_product_add_after, and use a product’s “Super Mode” to set custom prices against the quote item.
In your /app/code/local/{namespace}/{yourmodule}/etc/config.xml:
And then create an Observer class at /app/code/local/{namespace}/{yourmodule}/Model/Observer.php
As righty answered by Gershon Herczeg, Jürgen Thelen and Xman Classical. You will need to write a observer of sales_quote_add_item event. When any product is added to cart your observer will be triggered. If the product is Configurable then this event will be fired twice, You will have to something like that to get simple product only.
The way to do it is add an observer which looks for this event
'sales_quote_add_item'
:The observer should have a method which does something like this: