示例#1
0
 public static function getFromOrder(Order $order)
 {
     $translator = Translator::getInstance();
     if ($order->getDeliveryModuleId() !== TNTFrance::getModuleId()) {
         throw new \InvalidArgumentException($translator->trans("The order %id does not use the", ['id' => $order->getId()], TNTFrance::MESSAGE_DOMAIN));
     }
     $data = TNTFrance::getExtraOrderData($order->getId(), false);
     if (empty($data)) {
         throw new \InvalidArgumentException($translator->trans("No TNT data for order %id", ['id' => $order->getId()], TNTFrance::MESSAGE_DOMAIN));
     }
     $receiver = new TNTReceiver();
     $receiver->setType($data['tnt_service']);
     $receiver->setEmailAddress($order->getCustomer()->getEmail());
     if (array_key_exists('tnt_instructions', $data)) {
         $receiver->setInstructions($data['tnt_instructions']);
     }
     if (array_key_exists('tnt_phoneNumber', $data)) {
         $phoneNumber = str_replace(" ", "", $data['tnt_phoneNumber']);
         $receiver->setPhoneNumber($phoneNumber);
     }
     //todo : $receiver->setSendNotification(TNTFrance::getConfigValue(TNTFranceConfigValue::NOTIFICATION_USER));
     switch ($data['tnt_service']) {
         case 'INDIVIDUAL':
         case 'ENTERPRISE':
             $address = OrderAddressQuery::create()->findPk($order->getDeliveryOrderAddressId());
             if (null !== $address) {
                 $receiver->setName($address->getCompany())->setAddress1($address->getAddress1())->setAddress2($address->getAddress2())->setZipCode($address->getZipcode())->setCity($address->getCity())->setContactLastName($address->getLastname())->setContactFirstName($address->getFirstname());
                 if (array_key_exists('tnt_accessCode', $data)) {
                     $receiver->setAccessCode($data['tnt_accessCode']);
                 }
                 if (array_key_exists('tnt_floorNumber', $data)) {
                     $receiver->setAccessCode($data['tnt_floorNumber']);
                 }
                 if (array_key_exists('tnt_buildingId', $data)) {
                     $receiver->setAccessCode($data['tnt_buildingId']);
                 }
             }
             break;
         case 'DEPOT':
             $receiver->setTypeId($data['tnt_pexcode'])->setCity($data['tnt_depot_address']['city']);
             break;
         case 'DROPOFFPOINT':
             $receiver->setTypeId($data['tnt_exttcode']);
             break;
         default:
             throw new \InvalidArgumentException($translator->trans("TNT service %service is not valid for order %id", ['id' => $order->getId(), 'service' => $data['tnt_service']], TNTFrance::MESSAGE_DOMAIN));
     }
     return $receiver;
 }
 public static function getFromOrder(Order $order, $allInOne = true)
 {
     $translator = Translator::getInstance();
     if ($order->getDeliveryModuleId() !== TNTFrance::getModuleId()) {
         throw new \InvalidArgumentException($translator->trans("The order %id does not use the", ['id' => $order->getId()], TNTFrance::MESSAGE_DOMAIN));
     }
     $data = TNTFrance::getExtraOrderData($order->getId(), false);
     if (empty($data)) {
         throw new \InvalidArgumentException($translator->trans("No TNT data for order %id", ['id' => $order->getId()], TNTFrance::MESSAGE_DOMAIN));
     }
     $maxWeightPackage = TNTFrance::getConfigValue(TNTFranceConfigValue::MAX_WEIGHT_PACKAGE, 25);
     $parcelsRequest = [];
     $orderTotalWeight = 0;
     $packages = [];
     foreach ($order->getOrderProducts() as $orderProduct) {
         $orderProductWeight = $orderProduct->getQuantity() * $orderProduct->getWeight();
         $orderTotalWeight += $orderProductWeight;
         if (!$allInOne) {
             //If customer has choosen a manual number of package
             if ($orderProduct->getVirtualColumn(TNTFranceCreateExpeditionEvent::PACKAGE) && intval($orderProduct->getVirtualColumn(TNTFranceCreateExpeditionEvent::PACKAGE)) == $orderProduct->getVirtualColumn(TNTFranceCreateExpeditionEvent::PACKAGE)) {
                 $orderProductPackages = $orderProduct->getVirtualColumn(TNTFranceCreateExpeditionEvent::PACKAGE);
             } else {
                 if ($maxWeightPackage != 0) {
                     $orderProductPackages = ceil($orderProductWeight / $maxWeightPackage);
                 } else {
                     $orderProductPackages = 1;
                 }
             }
             //Divide the weight between packages
             for ($i = 1; $i <= $orderProductPackages; $i++) {
                 $packages[] = round($orderProductWeight / $orderProductPackages, 2);
             }
         }
     }
     if ($allInOne) {
         //If customer has choosen a manual number of package
         if ($order->getVirtualColumn(TNTFranceCreateExpeditionEvent::PACKAGE) && intval($order->getVirtualColumn(TNTFranceCreateExpeditionEvent::PACKAGE)) == $order->getVirtualColumn(TNTFranceCreateExpeditionEvent::PACKAGE)) {
             $orderPackages = $order->getVirtualColumn(TNTFranceCreateExpeditionEvent::PACKAGE);
         } else {
             $orderPackages = ceil($orderTotalWeight / $maxWeightPackage);
         }
         //Divide the weight between packages
         for ($i = 1; $i <= $orderPackages; $i++) {
             $packages[] = round($orderTotalWeight / $orderPackages, 2);
         }
     }
     foreach ($packages as $key => $packageWeight) {
         $parcelRequest = new TNTParcelRequest();
         $parcelRequest->setSequenceNumber($key + 1)->setCustomerReference($order->getCustomer()->getRef())->setWeight($packageWeight);
         $parcelsRequest[] = $parcelRequest;
     }
     if (count($parcelsRequest) == 0) {
         $parcelRequest = new TNTParcelRequest();
         $weight = 0.0;
         /** @var OrderProduct $orderProduct */
         foreach ($order->getOrderProducts() as $orderProduct) {
             $weight += $orderProduct->getQuantity() * floatval($orderProduct->getWeight());
         }
         $parcelRequest->setWeight($weight);
         $parcelRequest->setSequenceNumber(1);
         //$parcelRequest->setComment($data['tnt_instructions']);
         $parcelRequest->setCustomerReference($order->getCustomer()->getRef());
         $parcelsRequest[] = $parcelRequest;
     }
     return $parcelsRequest;
 }
示例#3
0
 public function setOrderDelivery(OrderEvent $event)
 {
     if ($event->getOrder()->getDeliveryModuleId() == TNTFrance::getModuleId()) {
         // we have the order id
         $data = TNTFrance::getExtraOrderData($event->getOrder()->getCartId());
         TNTFrance::setExtraOrderData($event->getOrder()->getId(), $data, false);
     }
 }
示例#4
0
 /**
  * Calculate and return delivery price in the shop's default currency
  *
  * @param Country $country the country to deliver to.
  *
  * @return OrderPostage|float             the delivery price
  * @throws DeliveryException if the postage price cannot be calculated.
  */
 public function getPostage(Country $country)
 {
     $postage = new OrderPostage();
     $freeShipping = intval(self::getConfigValue(TNTFranceConfigValue::FREE_SHIPPING));
     if (0 == $freeShipping) {
         $data = TNTFrance::getExtraOrderData($this->getRequest()->getSession()->getSessionCart()->getId(), true);
         if (array_key_exists('tnt_serviceCode', $data)) {
             $cartEvent = new CartEvent($this->getRequest()->getSession()->getSessionCart($this->getDispatcher()));
             $this->getDispatcher()->dispatch(OrderAction::TNT_CALCUL_CART_WEIGHT, $cartEvent);
             $postage->setAmount(self::calculPriceForService($data['tnt_serviceCode'], $cartEvent->getCart()->getVirtualColumn('total_package'), $cartEvent->getCart()->getVirtualColumn('total_weight')));
         }
     }
     return $postage->getAmount();
 }
 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));
 }
示例#6
0
 public function onBackAddress(HookRenderEvent $event)
 {
     $data = TNTFrance::getExtraOrderData($event->getArgument('order_id'), false);
     $order = OrderQuery::create()->findPk($event->getArgument('order_id'));
     $event->add($this->render('delivery-address.html', ['data' => $data, 'order_id' => $event->getArgument('order'), 'address_id' => $order->getDeliveryOrderAddressId()]));
 }