1

I have a store with different customer group.in which all customer has a specific discount for all product.Suppose customer group A has 10 customer and discount is also 10% on all product. Discount is decided from one of my API site so it's a real time discount for different customer group When customer logging in that belongs to customer group A he/she is able to see price with 10% discount every where (Product listing,product view,and with whole check out process.)

i can achieve this by calling below code but it display only on cart page not every where.

checkout_cart_product_add_after

observer function

$item = $observer->getQuoteItem();
     $product = $observer->getProduct();
     $price = $product->getPrice();
     //print_r($item->toArray());exit;
     // Discounted 25% off
     $percentDiscount = 0.25;

     // This makes sure the discount isn't applied over and over when refreshing
     $specialPrice = $product->getPrice() - ($product->getPrice() * $percentDiscount);
     // Make sure we don't have a negative
     if($specialPrice>0){
        $item->setCustomPrice($specialPrice);
        $item->setOriginalCustomPrice($specialPrice);
        $item->getProduct()->setIsSuperMode(true);
        }

How can i achieve this Please help

1

Depending on how much products, storeviews and customer groups you have, it might be an idea to just import the discount rules as catalog price rules.

The problem with this is, that the rules are generating an index with the size

#product * #storeviews * #customer_groups

So if these counts are not so high, just add new catalog rules, save them and magento will do the rest for you.

1

The prices for products in the catalog are displayed from the getFinalPrice method in the clas Mage_Catalog_Model_Product that is used in the catalog category list and the product view page. Rewriting this function will enable you to show a different price per customer but that is only half of the catalog.

A bit more complicated will be the layared navigation and advanced search since these get their price from an index. Rewriting this will be a lot more tricky so you might just want to leave that out of scope.

The price displayed in the cart (quote) and later on in the order, invoices and shipments is a lot more simple. Check out this stack overflow answer that uses an observer to modify the price in of the quote item. After that the item prices will also be passed along to the order and further along.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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