i am new to Magento.i am trying to achieve a simple way to apply custom margin at cost and then get its sale price.. i want to put only cost then some function to calculate 20% VAT (TAX) and custom attribute... and set margin 15%
example;
i have Three fields..when adding or editing product
Cost = 100
Price = 0
margin_percentage: 15 (means 15%)
after user add 100 and margin percentage 15, system first calculate 20% vat then on resulting amount add 15% margin so i this case
cost + vat + margin = 138 after saving
Cost = 100
Price = 138
margin_percentage: 15
i have write a module and trying to achieve this using Event Observer - catalog_product_save_before and catalog_product_save_after here is a function ...if this code works i may apply formula’s ..
class SmashingMagazine_LogProductUpdate_Model_Observer
{
public function logUpdate(Varien_Event_Observer $observer)
{
$product = $observer->getEvent()->getProduct();
$cost = $product->getCost();
$_product = Mage::getModel('catalog/product')->load($product->getId());
$_product->setPrice($cost); // or an other price field
$_product->save();
Mage::log(
"cost {$cost} Price {$price} updated",
null,
'product-updates.log'
);
}
}
when i create or edit product at catalog... above code not working and product price page like some infinite loop.. at end timeout and values not saved. please suggest me some hints and i am very confused how I accomplish this task. i have no experience of Magento research a lot for the last 5 days. i am following this tutorial to make module http://coding.smashingmagazine.com/2012/03/01/basics-creating-magento-module/