Daniel Doyle
Daniel Doyle

Reputation: 39

Magento individual customer catalog pricing rule

I'm trying to apply a catalog price rule programmatically on a per customer basis, however I've found that catalog pricing rules are based on customer groups, not individual customers. Does anyone know of a solution to this?

Thanks

Upvotes: 0

Views: 682

Answers (1)

baoutch
baoutch

Reputation: 1704

Although you can probably find an extension that does that, there is a way to do that using Magento observers. There are probably other ways to do it, but this one is somehow rather simple.

Create a module and first configure an abserver in config.xml :

</global>
    <events>
        <catalog_product_load_after>
            <observers>
                <productloadhandle>
                    <type>singleton</type>
                    <class>Yourcompany_Customprices_Model_Observer</class>
                    <method>getCustomPrice</method>
                </productloadhandle>
            </observers>
        </catalog_product_load_after>
        <catalog_product_get_final_price>
            <observers>
                <getfinalpricehandle>
                    <type>singleton</type>
                    <class>Yourcompany_Customprices_Model_Observer</class>
                    <method>getCustomPrice</method>
                </getfinalpricehandle>
            </observers>
        </catalog_product_get_final_price>
    </events>
</global>

Then create the observer model that will implement the getCustomPrice method.

class Yourcompany_Customprices_Model_Observer extends Mage_Core_Model_Abstract
{

    public function getCustomPrice($observer)
    {
        // If not logged in just get outta here
        if (! Mage::getSingleton('customer/session')->isLoggedIn()) {
            return;
        }

        $event = $observer->getEvent();
        if (Mage::getSingleton('customer/session')->isLoggedIn()) {
            // THis is where you will want to have your price mechanism going on.
            if (Mage::getSingleton('customer/session')->getCustomer()->getId() == $someIdFromCustomModuleTable) {
                $product = $event->getProduct();
                if ($product && null != $product->getSku()) {
                    // This is where you can tweak product price, using setPrice or setFinal
                    $product->setFinalPrice($customerPrice);
                }
            }
        }
        return $this;
    }
}

You will probably have to implement rest of the module with a table to store custom prices and a grid to manage it from backend which is quite standard and that I will not explain here, but that should get you started.

Upvotes: 1

Related Questions