Пример #1
0
 public function CancelOrder()
 {
     //init controller data
     $this->extensions->hk_InitData($this, __FUNCTION__);
     //do a few checks
     //is order exists
     $order_id = (int) $this->request->get['order_id'];
     $customer_id = $this->customer->getId();
     $this->loadModel('account/order');
     $guest = false;
     if (isset($this->request->get['ot']) && $this->config->get('config_guest_checkout')) {
         //try to decrypt order token
         $decrypted = AEncryption::mcrypt_decode($this->request->get['ot']);
         list($order_id, $email) = explode('~~~', $decrypted);
         $order_id = (int) $order_id;
         if (!$decrypted || !$order_id || !$email) {
             if ($order_id) {
                 $this->session->data['redirect'] = $this->html->getSecureURL('account/invoice', '&order_id=' . $order_id);
             }
             $this->redirect($this->html->getSecureURL('account/login'));
         }
         $order_info = $this->model_account_order->getOrder($order_id, '', 'view');
         //compare emails
         if ($order_info['email'] != $email) {
             $this->redirect($this->html->getSecureURL('account/login'));
         }
         $guest = true;
     } else {
         $order_info = $this->model_account_order->getOrder($order_id);
     }
     if (!$order_id && !$guest) {
         $this->redirect($this->html->getSecureURL('account/invoice'));
     }
     if (!$customer_id && !$guest) {
         $this->redirect($this->html->getSecureURL('account/login'));
     }
     if (!$order_info) {
         $this->redirect($this->html->getSecureURL('account/invoice'));
     }
     //is cancelation enabled at all
     if ($this->config->get('config_customer_cancelation_order_status_id')) {
         $order_cancel_ids = unserialize($this->config->get('config_customer_cancelation_order_status_id'));
     }
     //is cancelation allowed for current order status
     if (!$order_cancel_ids || !in_array($order_info['order_status_id'], $order_cancel_ids)) {
         $this->redirect($this->html->getSecureURL('account/invoice'));
     }
     //now do change
     $new_order_status_id = $this->order_status->getStatusByTextId('canceled_by_customer');
     if ($new_order_status_id) {
         $this->loadModel('checkout/order');
         $this->model_checkout_order->update($order_id, $new_order_status_id, 'Request an Order cancellation from Customer', true);
         $this->session->data['success'] = $this->language->get('text_order_cancelation_success');
         $this->messages->saveNotice(sprintf($this->language->get('text_order_cancelation_message_title'), $order_id), sprintf($this->language->get('text_order_cancelation_message_body'), $order_info['firstname'] . ' ' . $order_info['lastname'], $order_id, '#admin#rt=sale/order/details&order_id=' . $order_id));
     } else {
         //when new order status id is null by some unexpected reason - just redirect on the same page
         $this->log->write('Error: Unknown cancelation order status id. Probably integrity code problem. Check is file /core/lib/order_status.php exists.');
     }
     //update controller data
     $this->extensions->hk_UpdateData($this, __FUNCTION__);
     if (!$guest) {
         $url = $this->html->getSecureURL('account/invoice', '&order_id=' . $order_id);
     } else {
         $url = $this->html->getSecureURL('account/invoice', '&ot=' . $this->request->get['ot']);
     }
     $this->redirect($url);
 }