Ejemplo n.º 1
0
 public function afterSave()
 {
     if ($this->isNewRecord) {
         //for the tracker
         $tracker = new OrderTracking('OrderCreated');
         $tracker->shipments_id = $this->primaryKey;
         $tracker->save();
         //for shipment event
         $shipment_event = new ShipmentEvent();
         $shipment_event->shipment_id = $this->id;
         $shipment_event->status = $this->shipping_status;
         $shipment_event->event_time = $this->event_time;
         if ($this->getScenario() == 'api-requestpickup') {
             $shipment_event->user_id = 0;
         } else {
             $shipment_event->user_id = Yii::app()->user->id;
         }
         $shipment_event->setScenario('order');
         $shipment_event->save();
         if (!empty($this->customer_id)) {
             $trans = new Transaction();
             $trans->shipment_id = $this->id;
             $trans->customer_id = $this->customer_id;
             $trans->created = $this->created;
             $trans->charges = $this->shipping_charges;
             $trans->total = $this->charges;
             $trans->save();
         }
     } else {
         if ($this->getScenario() != 'event') {
             $shipment_event = new ShipmentEvent();
             $shipment_event->shipment_id = $this->id;
             $shipment_event->status = $this->shipping_status;
             $shipment_event->event_time = time();
             $shipment_event->user_id = Yii::app()->user->id;
             $shipment_event->with_mde = 1;
             $shipment_event->setScenario('order');
             $shipment_event->save();
         }
         if (!empty($this->customer_id)) {
             $trans = Transaction::model()->findByAttributes(array('shipment_id' => $this->id));
             $trans->shipment_id = $this->id;
             $trans->customer_id = $this->customer_id;
             $trans->created = $this->created;
             $trans->charges = $this->shipping_charges;
             $trans->total = $this->charges;
             $trans->save();
         }
     }
 }