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:
- Create new Sales Order attribute for Course ID
- 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;
}
}
}
Best Answer
You will need to add an extra field "course_id" to the
sales_flat_order
table. And you just add an observer onsales_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)