Set custom price in magento and Save custom values into sales_flat_quote_item and sales_flat_order_item magento

1. Create custom column using mysql files.
Jute\Sales\sql\jute_sales_setup\mysql4-install-0.0.1.php
Example: In above file i have created my custom column name like : custom_jute_name (my table column name) and am setting my custom price

2. When product is addto the cart from detail page to cart page , we have insert my custom values into above column.Then we have to do like below steps

3. Override cartcontroller.
Jute\Checkout\controllers\CartController.php
public function addAction()
{
————-
————-
$params[‘custom_jute_name’] = “My name is Jute”;
$params[‘my_custom_price’] = 10000; //10000 rupee

}

4. Override Quote file into your local – Jute\Sales\Model\Quote.php
public function addProductAdvanced(Mage_Catalog_Model_Product $product, $request = null, $processMode = null)
{
$priceCustom = $candidate->getPrice();
$custom_jute_name = $request->getData(‘custom_jute_name’);
$my_custom_price = $request->getData(‘my_custom_price’);
$item->setCustomPrice($my_custom_price);
$item->setOriginalCustomPrice($my_custom_price);
$item->setCustomJuteName($custom_jute_name);

}

5. That’s above custom price and custom name will insert into sales_flat_quote_item table

6. Same value we have to insert into sales_flat_order_item table also then what we want to do,

7. Create one observer, Jute\Sales\Model\Observer.php
class Jute_Sales_Model_Observer
{

public function convertymyquotevalueintoordertable($observer)
{
$quoteItem = $observer->getEvent()->getItem();
$orderItem = $observer->getOrderItem();
if ($quoteItem->getCustomJuteName()) {
$orderItem->setCustomJuteName($quoteItem->getCustomJuteName());
}
return $this;
}
}

8. Call, observer into config file like below – Jute\Sales\etc\config.xml
<events>
<sales_convert_quote_item_to_order_item>
<observers>
<jute_sales>
<type>model</type>
<class>jute_sales/observer</class>
<method>convertymyquotevalueintoordertable</method>
</jute_sales>
</observers>
</sales_convert_quote_item_to_order_item>
</events>

Leave a Reply