Exemplo n.º 1
0
 public function onOrderDeliveryExtra(HookRenderEvent $event)
 {
     $address = TNTFrance::getCartDeliveryAddress($this->getRequest());
     if (null === $address) {
         return;
     }
     $cartWeight = $this->getCart()->getWeight();
     $isModuleSelected = false;
     if (null !== ($order = $this->getOrder())) {
         $isModuleSelected = TNTFrance::getModuleId() === $this->getOrder()->getDeliveryModuleId();
     }
     $data = TNTFrance::getExtraOrderData($this->getCart()->getId(), []);
     $company = $address->getCompany();
     $serviceSelected = null;
     if (array_key_exists('tnt_service', $data)) {
         $serviceSelected = $data['tnt_service'];
         if (!in_array($serviceSelected, array('INDIVIDUAL', 'ENTERPRISE', 'DEPOT', 'DROPOFFPOINT'))) {
             $serviceSelected = 'INDIVIDUAL';
         }
         if ($serviceSelected == 'INDIVIDUAL' && !empty($company)) {
             $serviceSelected = 'ENTERPRISE';
         } elseif ($serviceSelected == 'ENTERPRISE' && empty($company)) {
             $serviceSelected = 'INDIVIDUAL';
         }
     }
     /** @var Feasibility $ws */
     /*
     $ws = $this->container->get('tnt.ws.factory')->get('feasibility');
     $choices = $ws->exec();
     */
     $event->add($this->render('order-delivery-extra.html', ['postalCode' => $address->getZipcode(), 'city' => $address->getCity(), 'weight' => $cartWeight, 'is_module_selected' => $isModuleSelected, 'service_selected' => $serviceSelected, 'services' => TNTFranceConfigValue::getServices(), 'company' => $company]));
 }
Exemplo n.º 2
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));
 }