0
votes

I've noticed that when moving items from the customers basket (left hand side) to an order (in the Admin area -> "Admin > Sales > New order") the products price does not carry over the customer group price. So if a product is in the customers basket for £10.00 (this is a specific groups price) and an admin moves this over to the order, this £10.00 prices is not carried over. The price in the basket is now £15.00 (original price)

I'm thinking the best way to resolve this is to create an event observer and update the price as it moves to the order?

1

1 Answers

0
votes

I managed to resolve this by creating an observer for the 'sales_quote_add_item' adminhtml event. Please see below. Hope this helps someone

<?xml version="1.0"?>
<config>
    <modules>
        <Companyname_Extensionname>
            <version>0.0.1</version>
        </Companyname_Extensionname>
    </modules>
    <global>
        <models>
            <Companyname_Extensionname>
                <class>Companyname_Extensionname_Model_Observer</class>
            </Companyname_Extensionname>
        </models>
    </global>
    <adminhtml>
        <events>
            <sales_quote_add_item>
                <observers>
                    <companyname_extensionname>
                        <class>companyname_extensionname/observer</class>
                        <method>carttoorder</method>
                    </companyname_extensionname>
                </observers>
            </sales_quote_add_item>
        </events>
    </adminhtml>
</config>

<?php 
class Companyname_Extensionname_Model_Observer {
    public function carttoorder(Varien_Event_Observer $observer) {
        $event = $observer->getEvent();
        $quote_item = $event->getQuoteItem();
        $product_sku = $quote_item->getSku();

        $sessionquoteId = Mage::getSingleton('adminhtml/session_quote')->getQuote()->getId();
        $sessionCustomerId = Mage::getModel('sales/quote')->loadByIdWithoutStore($sessionquoteId)->getCustomerId();
        $customerData = Mage::getModel('customer/customer')->load($sessionCustomerId);
        $customerId = $customerData->getGroupId();

        $_product = Mage::getModel('catalog/product');
        $_product->load($_product->getIdBySku($product_sku));

        $groupPrices = $_product->getData('group_price');

        if (!is_null($groupPrices) || is_array($groupPrices)) {
            foreach ($groupPrices as $groupPrice) {
                if($groupPrice['cust_group'] == $customerId){
                    $group_price = $groupPrice['website_price'];
                    break;
                }
            }
        }
        $quote_item->setOriginalCustomPrice($group_price);
        $quote_item->getProduct()->setIsSuperMode(true);
    } 
}