示例#1
0
 /**
  * Set order status & insert information to Status History
  *
  * @param integer|string $statusId
  * @param string $comments
  * @param bool $notifyCustomer
  * @return bool
  */
 public function setStatus($statusId, $comments = '', $notifyCustomer = false)
 {
     if (is_string($statusId) && in_array($statusId, array_values(Axis_Collect_OrderStatus::collect()))) {
         $status = $statusId;
         $statusId = Axis::single('sales/order_status')->getIdByName($status);
     } else {
         $status = Axis_Collect_OrderStatus::getName($statusId);
     }
     /* Relation exist or not */
     $childrens = Axis::single('sales/order_status_relation')->getChildrens($this->order_status_id);
     if (!in_array($statusId, $childrens)) {
         Axis::message()->addError(Axis::translate('sales')->__('Relation not exist %s <=> %s', $this->order_status_id, $statusId));
         return false;
     }
     $retMethod = Axis::single('sales/order_status_run')->{$status}($this);
     if (!$retMethod) {
         $status = 'failed';
         Axis::single('sales/order_status_run')->failed($this);
         $statusId = Axis::single('sales/order_status')->getIdByName('failed');
         $notifyCustomer = false;
         $messages = array();
         foreach (Axis::message()->get() as $messageGroup) {
             $comments .= ' ' . implode('.', $messageGroup);
         }
     }
     $this->order_status_id = $statusId;
     $this->save();
     /* save Status History */
     $this->addComment($comments, $notifyCustomer, $statusId);
     //        $message = Axis::translate('sales')->__(
     //            "Order status was changed to %s", $status
     //        );
     //        if ($status == 'failed' && Axis_Area::isFrontend()) {
     //            Axis::message()->addError($message);
     //            if (!$retMethod) {
     //                Axis::message()->addError($comments);
     //            }
     //        } else {
     //            Axis::message()->addSuccess($message);
     //        }
     return $retMethod;
 }