Esempio n. 1
0
 /**
  * 
  */
 public function Save()
 {
     $pn_order_id = $this->request->getParameter('order_id', pInteger);
     $t_order = new ca_commerce_orders($pn_order_id);
     if (!$t_order->userHasAccessToOrder($this->request->getUserID())) {
         $this->notification->addNotification(_t("Invalid order_id"), __NOTIFICATION_TYPE_ERROR__);
         $this->response->setRedirect(caNavUrl($this->request, '', 'Account', 'Index'), 302);
         return;
     } else {
         $this->view->setVar('t_order', $t_order);
         //
         // Process address(s)
         //
         $va_fields = array('shipping_fname', 'shipping_lname', 'shipping_organization', 'shipping_address1', 'shipping_address2', 'shipping_city', 'shipping_zone', 'shipping_postal_code', 'shipping_country', 'shipping_phone', 'shipping_fax', 'shipping_email', 'billing_fname', 'billing_lname', 'billing_organization', 'billing_address1', 'billing_address2', 'billing_city', 'billing_zone', 'billing_postal_code', 'billing_country', 'billing_phone', 'billing_fax', 'billing_email');
         foreach ($va_fields as $vn_i => $vs_f) {
             if (isset($_REQUEST[$vs_f])) {
                 if (!$t_order->set($vs_f, $this->request->getParameter($vs_f, pString))) {
                     $va_errors[$vs_f] = $t_order->errors();
                 }
             }
         }
         $t_order->setMode(ACCESS_WRITE);
         if ($t_order->getPrimaryKey()) {
             $t_order->update();
         } else {
             $this->notification->addNotification("Creation of orders from front-end not supported yet", __NOTIFICATION_TYPE_INFO__);
         }
         if ($t_order->numErrors()) {
             $va_errors['general'] = $t_order->errors();
             $this->notification->addNotification(_t('Errors occurred: %1', join('; ', $t_order->getErrors())), __NOTIFICATION_TYPE_ERROR__);
         }
         $this->view->setVar('errors', $va_errors);
         if (sizeof($va_errors)) {
             if (is_array($va_errors['general']) && sizeof($va_errors['general'])) {
                 $va_general_errors = array();
                 foreach ($va_errors['general'] as $o_e) {
                     $va_general_errors[] = $o_e->getErrorDescription();
                 }
                 $this->notification->addNotification(_t("There were errors in your order. Please examine your order information and correct any errors below, as well as these general problems: %1", join("; ", $va_general_errors)), __NOTIFICATION_TYPE_ERRORS__);
             } else {
                 $this->notification->addNotification(_t("There were errors in your order. Please examine your order information and correct the issues highlighted below."), __NOTIFICATION_TYPE_ERRORS__);
             }
         }
         //
         // Process payment
         //
         if (!sizeof($va_errors)) {
             if ($t_order->get('payment_received_on')) {
                 $this->notification->addNotification(_t('Order is already paid for'), __NOTIFICATION_TYPE_ERROR__);
             } else {
                 // Set payment intrinsics
                 foreach (array('payment_method', 'payment_status', 'payment_received_on') as $vs_f) {
                     if (isset($_REQUEST[$vs_f])) {
                         if (!$t_order->set($vs_f, $this->request->getParameter($vs_f, pString))) {
                             $va_errors[$vs_f] = $t_order->errors();
                         }
                     }
                 }
                 $t_order->setMode(ACCESS_WRITE);
                 // Set payment-type specific info
                 $t_order->setPaymentInfo($_REQUEST);
                 if ($t_order->numErrors()) {
                     $va_errors['payment_info'] = $t_order->getErrors();
                     $this->notification->addNotification(_t('Errors occurred: %1', join('; ', $t_order->getErrors())), __NOTIFICATION_TYPE_ERROR__);
                 } else {
                     $t_order->update();
                     if ($t_order->numErrors()) {
                         $va_errors['general'] = $t_order->errors();
                         $this->notification->addNotification(_t('Errors occurred: %1', join('; ', $t_order->getErrors())), __NOTIFICATION_TYPE_ERROR__);
                     } else {
                         if ($t_order->get('payment_received_on')) {
                             $this->notification->addNotification(_t('Payment was recorded'), __NOTIFICATION_TYPE_INFO__);
                         } else {
                             $this->notification->addNotification(_t('Billing information was successfully updated'), __NOTIFICATION_TYPE_INFO__);
                         }
                         $this->index();
                         return;
                     }
                 }
                 $this->view->setVar('errors', $va_errors);
             }
         }
         $this->viewOrder();
     }
 }