0

I am working on a project where i want to give personal discount for every customer. I want to add a customer attribute where i will give the discount amount for every customer. As example if a gave 30 to customer "John doe" then John doe will get a discount of fixed 30.

Can anyone please help me how to do that??

1 Answer 1

1

I suggest you create observer and set final price for product.

observer event as below

       <catalog_product_get_final_price>
            <observers>
                <seta_discountprice_price_observer>
                    <type>singleton</type>
                    <class>Namespace_Modulename_Model_Observer</class>
                    <method>setDiscount</method>
                </seta_discountprice_price_observer>
            </observers>
        </catalog_product_get_final_price>

Observer code

 public function setDiscount($observer)
    {
        $event = $observer->getEvent();
        $product = $event->getProduct();

         //get Login customer

         if(Mage::getSingleton('customer/session')->isLoggedIn()) {
            $customerData = Mage::getSingleton('customer/session')->getCustomer();   
            $discount =  $customerData->getDiscount(); //here is your attribute instead of discount
         }
         $discountPrice = ($product->getPrice()*$discount)/100;

        // process percentage discounts only for simple products
        if ($product->getSuperProduct() && $product->getSuperProduct()->isConfigurable()) {
        } else {

            $product->setFinalPrice($discountPrice);
        }
        return $this;
    }

Refere link it is also useful to you

2
  • Thanks for your answer. I will definitely try it now and let you know
    – Asish Hira
    Mar 17, 2016 at 6:21
  • This worked. Thank you very much for your help
    – Asish Hira
    Mar 17, 2016 at 7:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.