/**
  * Notify Event Handler
  *
  * @param 	unknown_type $event
  * @access 	public
  */
 function notify($event)
 {
     $update = false;
     $conversion_info = $this->checkForConversion($event);
     if ($conversion_info) {
         $s = owa_coreAPI::entityFactory('base.session');
         $new_id = $s->generateId(trim(strtolower($event->get('campaign'))));
         $s->getByPk('id', $event->get('session_id'));
         $id = $s->get('id');
         // only record one goal of a particular type per session
         if ($id) {
             //record conversion
             if (!empty($conversion_info['conversion'])) {
                 $goal_column = 'goal_' . $conversion_info['conversion'];
                 $already = $s->get($goal_column);
                 // see if an existing value has been set goal value
                 $goal_value_column = 'goal_' . $conversion_info['conversion'] . '_value';
                 $existing_value = $s->get($goal_value_column);
                 $value = $conversion_info['value'];
                 // determin is we have a conversion event worth updating
                 if ($already != true) {
                     // there is a goal conversion
                     $s->set($goal_column, true);
                     $update = true;
                     owa_coreAPI::debug("{$goal_column} was achieved.");
                 } else {
                     // goal already happened but check to see if we need to add a value to it.
                     // happens in the case of ecommerce transaction where the value
                     // can come in a secondary request. if no value then return.
                     if (!$value) {
                         owa_coreAPI::debug('Not updating session. Goal was already achieved and in same session.');
                         return OWA_EHS_EVENT_HANDLED;
                     }
                 }
                 // Allow a value to be set if one has not be set already.
                 // this is needed to support dynamic values passed by commerce transaction events
                 if ($value && !$existing_value) {
                     $s->set($goal_value_column, owa_lib::prepareCurrencyValue($value));
                     $update = true;
                 }
             }
             //record goal start
             if (!empty($conversion_info['start'])) {
                 $goal_start_column = 'goal_' . $conversion_info['start'] . '_start';
                 $already_started = $s->get($goal_start_column);
                 if ($already_started != true) {
                     $s->set($goal_start_column, true);
                     $update = true;
                     owa_coreAPI::debug("{$goal_start_column} was started.");
                 } else {
                     owa_coreAPI::debug("{$goal_start_column} was already started.");
                 }
             }
             //update object
             if ($update) {
                 // summarize goal conversions
                 $s->set('num_goals', $this->countGoalConversions($s));
                 // summarize goal conversion value
                 $s->set('goals_value', $this->sumGoalValues($s));
                 // summarize goal starts
                 $s->set('num_goal_starts', $this->countGoalStarts($s));
                 $ret = $s->update();
                 if ($ret) {
                     // create a new_conversion event so that the total conversion
                     // metrics can be resummarized
                     $this->dispatchNewConversionEvent($event);
                     return OWA_EHS_EVENT_HANDLED;
                 } else {
                     return OWA_EHS_EVENT_FAILED;
                 }
             } else {
                 owa_coreAPI::debug("nothing about this conversion is worth updating.");
                 return OWA_EHS_EVENT_HANDLED;
             }
         } else {
             owa_coreAPI::debug("Conversion processing aborted. No session could be found.");
             return OWA_EHS_EVENT_FAILED;
         }
     } else {
         owa_coreAPI::debug('No goal start or conversion detected.');
         return OWA_EHS_EVENT_HANDLED;
     }
 }
 function persistLineItem($item, $parent)
 {
     $ct = owa_coreAPI::entityFactory('base.commerce_line_item_fact');
     $guid = $item['li_order_id'] . $item['li_sku'];
     $pk = $ct->generateId($guid);
     $ct->getByPk('id', $pk);
     $id = $ct->get('id');
     if (!$id) {
         $ct->setProperties($parent->getProperties());
         $ct->set('id', $pk);
         // Generate Location Id. Location data is comming from user input
         $ct->set('order_id', trim($item['li_order_id']));
         $ct->set('sku', trim($item['li_sku']));
         $ct->set('product_name', trim(strtolower($item['li_product_name'])));
         $ct->set('category', $item['li_category']);
         $ct->set('unit_price', owa_lib::prepareCurrencyValue(round($item['li_unit_price'], 2)));
         $ct->set('quantity', round($item['li_quantity']));
         $revenue = round($item['li_quantity'] * $item['li_unit_price'], 2);
         $ct->set('item_revenue', owa_lib::prepareCurrencyValue($revenue));
         $ret = $ct->create();
         if ($ret) {
             return true;
         } else {
             return false;
         }
     } else {
         owa_coreAPI::debug('Not Persisting. line item already exists');
         return false;
     }
 }