2

I created 2 new attribute and I want to use them to calculate price. I use this code but I don't know how to get the value of these attribute. Any ideas on the best way to do this? Thanks so much!

<?php
class GoIvvy_PriceFormula_Model_Observer
{
   public function calculateFinalPrice($observer)
   {
        $_product = $observer->getEvent()->getProduct();
        // $mount = ???
        // $per = ???
        $finalPrice = (100+$mount)*$per;
        $_product->setFinalPrice($finalPrice);
        return $this;
   }
   public function collectionFinalPrice($observer)
   {
       $collection = $observer->getEvent()->getCollection();
       foreach($collection as $_product){
        // $mount = ???
        // $per = ???
        $finalPrice = (100+$mount)*$per;
        $_product->setMinimalPrice($finalPrice)
                  ->setPrice($finalPrice)
                  ->setFinalPrice($finalPrice);
       }
     return $this; 
   }
}
Amit Bera
  • 77,456
  • 20
  • 123
  • 237
tuanptit
  • 339
  • 2
  • 5
  • 12

1 Answers1

1

you can do this by magento event observer.

Try an fire an observer on catalog_product_save_before/catalog_product__save_commit_after event.

$_product = $observer->getEvent()->getProduct();
 $mount = $_product->getData('yourattribute');
 $per = $_product->getData('perAttribute')
$finalPrice = (100+$mount)*$per;
$_product->setFinalPrice($finalPrice);
Amit Bera
  • 77,456
  • 20
  • 123
  • 237