Beispiel #1
0
 /**
  * Update the status of this order and trigger actions (email & hook)
  *
  * @param int $intNewStatus
  *
  * @return bool
  */
 public function updateOrderStatus($intNewStatus)
 {
     // Status already set, nothing to do
     if ($this->order_status == $intNewStatus) {
         return true;
     }
     /** @var OrderStatus $objNewStatus */
     $objNewStatus = OrderStatus::findByPk($intNewStatus);
     if (null === $objNewStatus) {
         return false;
     }
     // !HOOK: allow to cancel a status update
     if (isset($GLOBALS['ISO_HOOKS']['preOrderStatusUpdate']) && is_array($GLOBALS['ISO_HOOKS']['preOrderStatusUpdate'])) {
         foreach ($GLOBALS['ISO_HOOKS']['preOrderStatusUpdate'] as $callback) {
             $objCallback = \System::importStatic($callback[0]);
             $blnCancel = $objCallback->{$callback}[1]($this, $objNewStatus);
             if ($blnCancel === true) {
                 return false;
             }
         }
     }
     // Add the payment date if there is none
     if ($objNewStatus->isPaid() && $this->date_paid == '') {
         $this->date_paid = time();
     }
     // Trigger notification
     $blnNotificationError = null;
     if ($objNewStatus->notification > 0) {
         $arrTokens = $this->getNotificationTokens($objNewStatus->notification);
         // Override order status and save the old one to the tokens too
         $arrTokens['order_status_id'] = $objNewStatus->id;
         $arrTokens['order_status'] = $objNewStatus->getName();
         $arrTokens['order_status_old'] = $this->getStatusLabel();
         $arrTokens['order_status_id_old'] = $this->order_status;
         $blnNotificationError = true;
         /** @var Notification $objNotification */
         if (($objNotification = Notification::findByPk($objNewStatus->notification)) !== null) {
             $arrResult = $objNotification->send($arrTokens, $this->language);
             if (in_array(false, $arrResult)) {
                 $blnNotificationError = true;
                 \System::log('Error sending status update notification for order ID ' . $this->id, __METHOD__, TL_ERROR);
             } elseif (!empty($arrResult)) {
                 $blnNotificationError = false;
             }
         } else {
             \System::log('Invalid notification for order status ID ' . $objNewStatus->id, __METHOD__, TL_ERROR);
         }
     }
     if (TL_MODE == 'BE') {
         \Message::addConfirmation($GLOBALS['TL_LANG']['tl_iso_product_collection']['orderStatusUpdate']);
         if ($blnNotificationError === true) {
             \Message::addError($GLOBALS['TL_LANG']['tl_iso_product_collection']['orderStatusNotificationError']);
         } elseif ($blnNotificationError === false) {
             \Message::addConfirmation($GLOBALS['TL_LANG']['tl_iso_product_collection']['orderStatusNotificationSuccess']);
         }
     }
     // Store old status and set the new one
     $intOldStatus = $this->order_status;
     $this->order_status = $objNewStatus->id;
     $this->save();
     // !HOOK: order status has been updated
     if (isset($GLOBALS['ISO_HOOKS']['postOrderStatusUpdate']) && is_array($GLOBALS['ISO_HOOKS']['postOrderStatusUpdate'])) {
         foreach ($GLOBALS['ISO_HOOKS']['postOrderStatusUpdate'] as $callback) {
             $objCallback = \System::importStatic($callback[0]);
             $objCallback->{$callback}[1]($this, $intOldStatus, $objNewStatus);
         }
     }
     // Trigger payment and shipping methods that implement the interface
     if (($objPayment = $this->getPaymentMethod()) !== null && $objPayment instanceof IsotopeOrderStatusAware) {
         $objPayment->onOrderStatusUpdate($this, $intOldStatus, $objNewStatus);
     }
     if (($objShipping = $this->getShippingMethod()) !== null && $objShipping instanceof IsotopeOrderStatusAware) {
         $objShipping->onOrderStatusUpdate($this, $intOldStatus, $objNewStatus);
     }
     return true;
 }