Beispiel #1
0
 public function setModuleDelivery(OrderEvent $event)
 {
     if ($event->getDeliveryModule() == TNTFrance::getModuleId()) {
         $request = $this->getRequest();
         $id = $request->getSession()->getSessionCart()->getId();
         $address = TNTFrance::getCartDeliveryAddress($this->getRequest());
         $data = TNTFrance::getExtraOrderData($id);
         try {
             $this->saveExtraInformation($data, $event->getOrder(), $address);
             //We must recalcul postage when this informations are saved :(
             if (array_key_exists('tnt_serviceCode', $data)) {
                 $cartEvent = new CartEvent($this->getRequest()->getSession()->getSessionCart($event->getDispatcher()));
                 $event->getDispatcher()->dispatch(OrderAction::TNT_CALCUL_CART_WEIGHT, $cartEvent);
                 $postage = TNTFrance::calculPriceForService($data['tnt_serviceCode'], $cartEvent->getCart()->getVirtualColumn('total_package'), $cartEvent->getCart()->getVirtualColumn('total_weight'));
                 $event->getOrder()->setPostage($postage);
                 $event->setPostage($postage);
             }
         } catch (\Exception $ex) {
             throw $ex;
         }
         TNTFrance::setExtraOrderData($id, $data);
     }
 }
 public function saveConfigurationAction()
 {
     $this->checkAuth();
     $this->checkXmlHttpRequest();
     $customer = $this->getSecurityContext()->getCustomerUser();
     $address = TNTFrance::getCartDeliveryAddress($this->getRequest());
     $order = $this->getSession()->getOrder();
     $data = TNTFrance::getExtraOrderData($this->getSession()->getSessionCart()->getId());
     if ($address->getCustomerId() !== $customer->getId()) {
         $this->accessDenied();
     }
     if (null !== ($city = $this->getRequest()->request->get('tnt_city'))) {
         $address->setCity($city)->save();
     }
     $fields = ['tnt_service', 'tnt_instructions', 'tnt_contactLastName', 'tnt_contactFirstName', 'tnt_emailAdress', 'tnt_phoneNumber', 'tnt_accessCode', 'tnt_floorNumber', 'tnt_buldingId', 'tnt_sendNotification', 'tnt_pexcode', 'tnt_depot_zipcode', 'tnt_depot_city', 'tnt_depot_address', 'tnt_xettcode', 'tnt_dop_zipcode', 'tnt_dop_city', 'tnt_dop_address'];
     foreach ($fields as $field) {
         $value = $this->getRequest()->request->get($field);
         if (null !== $value) {
             if (in_array($field, ['tnt_dop_address', 'tnt_depot_address'])) {
                 $data[$field] = json_decode($value, true);
             } else {
                 $data[$field] = $value;
             }
         }
     }
     TNTFrance::setExtraOrderData($this->getSession()->getSessionCart()->getId(), $data);
     // get feasibility
     $params = ['unavailable' => false, 'feasibility' => false];
     switch ($data['tnt_service']) {
         case 'INDIVIDUAL':
             $this->checkIndividual($params, $address, $data);
             break;
         case 'ENTERPRISE':
             $this->checkEnterprise($params, $address, $data);
             break;
         case 'DEPOT':
             $this->checkDepot($params, $address, $data);
             break;
         case 'DROPOFFPOINT':
             $this->checkDropOffPoint($params, $address, $data);
             break;
         default:
     }
     $out = ['status' => 0, 'content' => ''];
     $choices = [];
     if ($params['feasibility']) {
         /** @var Feasibility $ws */
         $ws = $this->getWebService('feasibility');
         $ws->setZipCode($params['feasibility_zipcode'])->setCity($params['feasibility_city'])->setType($data['tnt_service']);
         $choices = $ws->exec();
     }
     $cartEvent = new CartEvent($this->getRequest()->getSession()->getSessionCart($this->getDispatcher()));
     $this->dispatch(OrderAction::TNT_CALCUL_CART_WEIGHT, $cartEvent);
     /** @var \TNTFrance\WebService\Model\TNTService $tntService */
     foreach ($choices as $tntService) {
         $tntService->setPrice(TNTFrance::calculPriceForService($tntService->getServiceCode(), $cartEvent->getCart()->getVirtualColumn('total_package'), $cartEvent->getCart()->getVirtualColumn('total_weight')));
     }
     $out["status"] = count($choices);
     $out["content"] = $this->renderRaw('ajax-feasibility', ['choices' => $choices]);
     return $this->jsonResponse(json_encode($out));
 }