Esempio n. 1
0
 /**
  * Ajax action for changing postcode.
  */
 public function ajaxChangePostcode()
 {
     try {
         $post = $this->wp->getPost((int) $_POST['order']);
         $this->wp->updateGlobalPost($post);
         /** @var \Jigoshop\Entity\Order $order */
         $order = $this->orderService->findForPost($post);
         if ($order->getId() === null) {
             throw new Exception(__('Order not found.', 'jigoshop'));
         }
         switch ($_POST['type']) {
             case 'shipping':
                 $address = $order->getCustomer()->getShippingAddress();
                 break;
             case 'billing':
             default:
                 $address = $order->getCustomer()->getBillingAddress();
         }
         if ($this->options->get('shopping.validate_zip') && !Validation::isPostcode($_POST['value'], $address->getCountry())) {
             throw new Exception(__('Invalid postcode.', 'jigoshop'));
         }
         $address->setPostcode($_POST['value']);
         $order = $this->rebuildOrder($order);
         $this->orderService->save($order);
         $result = $this->getAjaxResponse($order);
     } catch (Exception $e) {
         $result = array('success' => false, 'error' => $e->getMessage());
     }
     echo json_encode($result);
     exit;
 }