2

I have created a new attribute for Customer Groups called course_id but I need to get the value of this attribute to then become the value for a new attribute for a Sales Order.

Any ideas how I could do this?

I would assume:

  1. Create new Sales Order attribute for Course ID
  2. Get value of Customer Group Course ID to set the value for all new Sales Orders attribute for Course ID

Any help is much appreciated.

EDIT:

This is my current observer, but it doesn't seem to be working correctly. I have added the new new columns in the database (customer group is course_id and sales order is salescourse_id):

<?php 
class MyCompany_CustomerGroupCourseID_Model_Observer 
{
    /**
     *
     * @param Varien_Event_Observer $observer
     * @return object
     */
    public function setCourseID(Varien_Event_Observer  $observer)
    {
                //get event data
        $event = $observer->getEvent();

                //get order
        $order = $event->getOrder();

        //get current customer group and set course id

         $customerid = Mage::getSingleton('customer/session')->getCustomerGroupId();
        $courseId = Mage::getSingleton('customer/group')->load($customerid)->getData('course_id');

        if (isset($courseId)){

        $order->setSalescourseId($courseId)

        return $this;
        }
    }
}   
1

You will need to add an extra field "course_id" to the sales_flat_order table. And you just add an observer on sales_order_place_before, to catch the current customer group, and assign it to the current order (you don't even have to save the model, just $order->setCourseId($courseId) is sufficient).

Also note that if you want to display this data on the sales order grid, you will have to also add the "course_id" field to the sales_flat_order_grid table. (it will be populated automatically when the order model is saved)

  • This is my observer, but it doesn't appear to work correctly. See my edit. Thanks for your help. – performadigital Jul 8 '14 at 2:19

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.