public static function getServices() { $services = []; $translator = Translator::getInstance(); $services[] = ['id' => 'INDIVIDUAL', 'enabled' => (bool) TNTFrance::getConfigValue(TNTFranceConfigValue::USE_INDIVIDUAL), 'name' => $translator->trans('Home delivery', [], 'tntfrance')]; $services[] = ['id' => 'ENTERPRISE', 'enabled' => (bool) TNTFrance::getConfigValue(TNTFranceConfigValue::USE_ENTERPRISE), 'name' => $translator->trans('Enterprise delivery', [], 'tntfrance')]; $services[] = ['id' => 'DEPOT', 'enabled' => (bool) TNTFrance::getConfigValue(TNTFranceConfigValue::USE_DEPOT), 'name' => $translator->trans('TNT Depot', [], 'tntfrance')]; $services[] = ['id' => 'DROPOFFPOINT', 'enabled' => (bool) TNTFrance::getConfigValue(TNTFranceConfigValue::USE_DROPOFFPOINT), 'name' => $translator->trans('Drop Off Point', [], 'tntfrance')]; return $services; }
public function orderProductNumberPackage($params, $template = null) { $numberOfPackage = 1; $maxWeightPackage = TNTFrance::getConfigValue(TNTFranceConfigValue::MAX_WEIGHT_PACKAGE, 25); if (null != ($orderProductId = $this->getParam($params, "order_product_id", null))) { if (null != ($orderProduct = OrderProductQuery::create()->findPk($orderProductId))) { $orderProductTotalWeight = $orderProduct->getQuantity() * $orderProduct->getWeight(); $numberOfPackage = ceil($orderProductTotalWeight / $maxWeightPackage); } } return $numberOfPackage; }
public function saveAction() { $baseForm = $this->createForm("tntfrance.configuration"); $errorMessage = null; try { $form = $this->validateForm($baseForm); $data = $form->getData(); TNTFrance::setConfigValue(TNTFranceConfigValue::ENABLED, is_bool($data["enabled"]) ? (int) $data["enabled"] : $data["enabled"]); TNTFrance::setConfigValue(TNTFranceConfigValue::MODE_PRODUCTION, is_bool($data["mode_production"]) ? (int) $data["mode_production"] : $data["mode_production"]); TNTFrance::setConfigValue(TNTFranceConfigValue::ACCOUNT_NUMBER, is_bool($data["account_number"]) ? (int) $data["account_number"] : $data["account_number"]); TNTFrance::setConfigValue(TNTFranceConfigValue::USERNAME, is_bool($data["username"]) ? (int) $data["username"] : $data["username"]); TNTFrance::setConfigValue(TNTFranceConfigValue::PASSWORD, is_bool($data["password"]) ? (int) $data["password"] : $data["password"]); TNTFrance::setConfigValue(TNTFranceConfigValue::USE_INDIVIDUAL, is_bool($data["use_individual"]) ? (int) $data["use_individual"] : $data["use_individual"]); TNTFrance::setConfigValue(TNTFranceConfigValue::USE_ENTERPRISE, is_bool($data["use_enterprise"]) ? (int) $data["use_enterprise"] : $data["use_enterprise"]); TNTFrance::setConfigValue(TNTFranceConfigValue::USE_DEPOT, is_bool($data["use_depot"]) ? (int) $data["use_depot"] : $data["use_depot"]); TNTFrance::setConfigValue(TNTFranceConfigValue::USE_DROPOFFPOINT, is_bool($data["use_dropoffpoint"]) ? (int) $data["use_dropoffpoint"] : $data["use_dropoffpoint"]); TNTFrance::setConfigValue(TNTFranceConfigValue::PRODUCTS_ENABLED, is_bool($data["products_enabled"]) ? (int) $data["products_enabled"] : $data["products_enabled"]); TNTFrance::setConfigValue(TNTFranceConfigValue::OPTIONS_ENABLED, is_bool($data["options_enabled"]) ? (int) $data["options_enabled"] : $data["options_enabled"]); TNTFrance::setConfigValue(TNTFranceConfigValue::REGULAR_PICKUP, is_bool($data["regular_pickup"]) ? (int) $data["regular_pickup"] : $data["regular_pickup"]); TNTFrance::setConfigValue(TNTFranceConfigValue::SENDER_NAME, is_bool($data["sender_name"]) ? (int) $data["sender_name"] : $data["sender_name"]); TNTFrance::setConfigValue(TNTFranceConfigValue::SENDER_ADDRESS1, is_bool($data["sender_address1"]) ? (int) $data["sender_address1"] : $data["sender_address1"]); TNTFrance::setConfigValue(TNTFranceConfigValue::SENDER_ADDRESS2, is_bool($data["sender_address2"]) ? (int) $data["sender_address2"] : $data["sender_address2"]); TNTFrance::setConfigValue(TNTFranceConfigValue::SENDER_ZIP_CODE, is_bool($data["sender_zip_code"]) ? (int) $data["sender_zip_code"] : $data["sender_zip_code"]); TNTFrance::setConfigValue(TNTFranceConfigValue::SENDER_CITY, is_bool($data["sender_city"]) ? (int) $data["sender_city"] : $data["sender_city"]); TNTFrance::setConfigValue(TNTFranceConfigValue::CONTACT_LASTNAME, is_bool($data["contact_lastname"]) ? (int) $data["contact_lastname"] : $data["contact_lastname"]); TNTFrance::setConfigValue(TNTFranceConfigValue::CONTACT_FIRSTNAME, is_bool($data["contact_firstname"]) ? (int) $data["contact_firstname"] : $data["contact_firstname"]); TNTFrance::setConfigValue(TNTFranceConfigValue::CONTACT_EMAIL, is_bool($data["contact_email"]) ? (int) $data["contact_email"] : $data["contact_email"]); TNTFrance::setConfigValue(TNTFranceConfigValue::CONTACT_PHONE, is_bool($data["contact_phone"]) ? (int) $data["contact_phone"] : $data["contact_phone"]); TNTFrance::setConfigValue(TNTFranceConfigValue::NOTIFICATION_EMAILS, is_bool($data["notification_emails"]) ? (int) $data["notification_emails"] : $data["notification_emails"]); TNTFrance::setConfigValue(TNTFranceConfigValue::NOTIFICATION_SUCCESS, is_bool($data["notification_success"]) ? (int) $data["notification_success"] : $data["notification_success"]); TNTFrance::setConfigValue(TNTFranceConfigValue::LABEL_FORMAT, is_bool($data["label_format"]) ? (int) $data["label_format"] : $data["label_format"]); TNTFrance::setConfigValue(TNTFranceConfigValue::FREE_SHIPPING, is_bool($data["free_shipping"]) ? (int) $data["free_shipping"] : $data["free_shipping"]); TNTFrance::setConfigValue(TNTFranceConfigValue::MAX_WEIGHT_PACKAGE, is_bool($data["max_weight_package"]) ? (int) $data["max_weight_package"] : $data["max_weight_package"]); TNTFrance::setConfigValue(TNTFranceConfigValue::TRACKING_URL, is_bool($data["tracking_url"]) ? (int) $data["tracking_url"] : $data["tracking_url"]); } catch (FormValidationException $ex) { // Invalid data entered $errorMessage = $this->createStandardFormValidationErrorMessage($ex); } catch (\Exception $ex) { // Any other error $errorMessage = $this->getTranslator()->trans('Sorry, an error occurred: %err', ['%err' => $ex->getMessage()], [], TNTFrance::MESSAGE_DOMAIN); } if (null !== $errorMessage) { // Mark the form as with error $baseForm->setErrorMessage($errorMessage); // Send the form and the error to the parser $this->getParserContext()->addForm($baseForm)->setGeneralError($errorMessage); } else { $this->getParserContext()->set("success", true); } return $this->defaultAction(); }
public function saveAction() { $errorMessage = null; $current_tab = $this->getRequest()->get('current_tab'); if ($current_tab != "weight") { return parent::saveAction(); } $form = new TNTPriceWeightForm($this->getRequest()); try { $formValidate = $this->validateForm($form); TNTFrance::setConfigValue(TNTFranceConfigValue::FREE_SHIPPING, $formValidate->get(TNTFranceConfigValue::FREE_SHIPPING)->getData() ? $formValidate->get(TNTFranceConfigValue::FREE_SHIPPING)->getData() : 0); TNTFrance::setConfigValue(TNTFranceConfigValue::SURCHARGE_FUEL, $formValidate->get(TNTFranceConfigValue::SURCHARGE_FUEL)->getData() ? $formValidate->get(TNTFranceConfigValue::SURCHARGE_FUEL)->getData() : 0); TNTFrance::setConfigValue(TNTFranceConfigValue::SURCHARGE_SECURITY_FEE, $formValidate->get(TNTFranceConfigValue::SURCHARGE_SECURITY_FEE)->getData() ? $formValidate->get(TNTFranceConfigValue::SURCHARGE_SECURITY_FEE)->getData() : 0); TNTFrance::setConfigValue(TNTFranceConfigValue::SURCHARGE_MULTI_PACKAGE, $formValidate->get(TNTFranceConfigValue::SURCHARGE_MULTI_PACKAGE)->getData() ? $formValidate->get(TNTFranceConfigValue::SURCHARGE_MULTI_PACKAGE)->getData() : 0); TNTFrance::setConfigValue(TNTFranceConfigValue::SEPARATE_PRODUCT_IN_PACKAGE, $formValidate->get(TNTFranceConfigValue::SEPARATE_PRODUCT_IN_PACKAGE)->getData() ? $formValidate->get(TNTFranceConfigValue::SEPARATE_PRODUCT_IN_PACKAGE)->getData() : 0); TNTFrance::setConfigValue(TNTFranceConfigValue::OPTION_P_PAYMENT_BACK, $formValidate->get(TNTFranceConfigValue::OPTION_P_PAYMENT_BACK)->getData() ? $formValidate->get(TNTFranceConfigValue::OPTION_P_PAYMENT_BACK)->getData() : 0); TNTFrance::setConfigValue(TNTFranceConfigValue::OPTION_W_EXPEDITION_UNDER_PROTECTION, $formValidate->get(TNTFranceConfigValue::OPTION_W_EXPEDITION_UNDER_PROTECTION)->getData() ? $formValidate->get(TNTFranceConfigValue::OPTION_W_EXPEDITION_UNDER_PROTECTION)->getData() : 0); TNTFrance::setConfigValue(TNTFranceConfigValue::OPTION_D_RELAY_PACKAGE, $formValidate->get(TNTFranceConfigValue::OPTION_D_RELAY_PACKAGE)->getData() ? $formValidate->get(TNTFranceConfigValue::OPTION_D_RELAY_PACKAGE)->getData() : 0); TNTFrance::setConfigValue(TNTFranceConfigValue::OPTION_Z_HOME_DELIVERY, $formValidate->get(TNTFranceConfigValue::OPTION_Z_HOME_DELIVERY)->getData() ? $formValidate->get(TNTFranceConfigValue::OPTION_Z_HOME_DELIVERY)->getData() : 0); TNTFrance::setConfigValue(TNTFranceConfigValue::OPTION_E_WITHOUT_ANNOTATING, $formValidate->get(TNTFranceConfigValue::OPTION_E_WITHOUT_ANNOTATING)->getData() ? $formValidate->get(TNTFranceConfigValue::OPTION_E_WITHOUT_ANNOTATING)->getData() : 0); //Save the contracted rates $prices = $formValidate->get(TNTFranceConfigValue::PRICE_ONE_KG)->getData(); $priceKgSups = $formValidate->get(TNTFranceConfigValue::PRICE_KG_SUP)->getData(); foreach ($prices as $id => $price) { if (null != ($tntPriceWeight = TntPriceWeightQuery::create()->findPk($id))) { $tntPriceWeight->setPrice($price); if (is_array($priceKgSups) && array_key_exists($id, $priceKgSups)) { $tntPriceWeight->setPriceKgSup($priceKgSups[$id]); } $tntPriceWeight->save(); } } } catch (FormValidationException $ex) { // Invalid data entered $errorMessage = $this->createStandardFormValidationErrorMessage($ex); } catch (\Exception $ex) { // Any other error $errorMessage = $this->getTranslator()->trans('Sorry, an error occurred: %err', ['%err' => $ex->getMessage()], [], TNTFrance::MESSAGE_DOMAIN); } if (null !== $errorMessage) { // Mark the form as with error $form->setErrorMessage($errorMessage); // Send the form and the error to the parser $this->getParserContext()->addForm($form)->setGeneralError($errorMessage); } else { $this->getParserContext()->set("success", true); } return $this->defaultAction(); }
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; }
/** * * in this function you add all the fields you need for your Form. * Form this you have to call add method on $this->formBuilder attribute : * * $this->formBuilder->add("name", "text") * ->add("email", "email", array( * "attr" => array( * "class" => "field" * ), * "label" => "email", * "constraints" => array( * new \Symfony\Component\Validator\Constraints\NotBlank() * ) * ) * ) * ->add('age', 'integer'); * * @return null */ protected function buildForm() { $this->formBuilder->add(TNTFranceConfigValue::FREE_SHIPPING, 'integer', ['label' => Translator::getInstance()->trans('Free shipping', [], TNTFrance::MESSAGE_DOMAIN), 'label_attr' => ['for' => TNTFranceConfigValue::FREE_SHIPPING], 'data' => TNTFrance::getConfigValue(TNTFranceConfigValue::FREE_SHIPPING)])->add(TNTFranceConfigValue::SURCHARGE_FUEL, 'number', ['label' => Translator::getInstance()->trans('Fuel surchage', [], TNTFrance::MESSAGE_DOMAIN), 'label_attr' => ['for' => TNTFranceConfigValue::SURCHARGE_FUEL, 'description' => Translator::getInstance()->trans('Based on the monthly average price of a liter of diesel at the pump released by the National Committee Road, for all of your domestic shipments.', [], TNTFrance::MESSAGE_DOMAIN), 'helper' => Translator::getInstance()->trans('(Around %default_price€ per expedition by default)', ['%default_price' => 0.6], TNTFrance::MESSAGE_DOMAIN)], 'constraints' => [new NotBlank()], 'data' => TNTFrance::getConfigValue(TNTFranceConfigValue::SURCHARGE_FUEL)])->add(TNTFranceConfigValue::SURCHARGE_SECURITY_FEE, 'number', ['label' => Translator::getInstance()->trans('Security fee', [], TNTFrance::MESSAGE_DOMAIN), 'label_attr' => ['for' => TNTFranceConfigValue::SURCHARGE_SECURITY_FEE, 'helper' => Translator::getInstance()->trans('(%default_price€ per package by default)', ['%default_price' => 0.36], TNTFrance::MESSAGE_DOMAIN)], 'data' => TNTFrance::getConfigValue(TNTFranceConfigValue::SURCHARGE_SECURITY_FEE)])->add(TNTFranceConfigValue::SURCHARGE_MULTI_PACKAGE, 'number', ['label' => Translator::getInstance()->trans('Multi package treatment', [], TNTFrance::MESSAGE_DOMAIN), 'label_attr' => ['for' => TNTFranceConfigValue::SURCHARGE_MULTI_PACKAGE, 'description' => Translator::getInstance()->trans('From the second package.', ['%default_price' => 0.5], TNTFrance::MESSAGE_DOMAIN), 'helper' => Translator::getInstance()->trans('(%default_price€ per package by default)', ['%default_price' => 0.5], TNTFrance::MESSAGE_DOMAIN)], 'data' => TNTFrance::getConfigValue(TNTFranceConfigValue::SURCHARGE_MULTI_PACKAGE)])->add(TNTFranceConfigValue::SEPARATE_PRODUCT_IN_PACKAGE, 'integer', ['label' => Translator::getInstance()->trans('Do one package per product', [], TNTFrance::MESSAGE_DOMAIN), 'label_attr' => ['for' => TNTFranceConfigValue::SEPARATE_PRODUCT_IN_PACKAGE, 'description' => Translator::getInstance()->trans('Allows you to send several packages even if the max weight is not reached.', ['%default_price' => 0.5], TNTFrance::MESSAGE_DOMAIN)], 'data' => TNTFrance::getConfigValue(TNTFranceConfigValue::SEPARATE_PRODUCT_IN_PACKAGE)])->add(TNTFranceConfigValue::OPTION_P_PAYMENT_BACK, 'number', ['label' => Translator::getInstance()->trans('Option payment back', [], TNTFrance::MESSAGE_DOMAIN), 'label_attr' => ['for' => TNTFranceConfigValue::OPTION_P_PAYMENT_BACK, 'description' => Translator::getInstance()->trans('Delivery against payment by check.', [], TNTFrance::MESSAGE_DOMAIN), 'helper' => Translator::getInstance()->trans('(%default_price€ per expedition by default)', ['%default_price' => 16.5], TNTFrance::MESSAGE_DOMAIN)], 'constraints' => [new NotBlank()], 'data' => TNTFrance::getConfigValue(TNTFranceConfigValue::OPTION_P_PAYMENT_BACK)])->add(TNTFranceConfigValue::OPTION_W_EXPEDITION_UNDER_PROTECTION, 'number', ['label' => Translator::getInstance()->trans('Option expedition under protection', [], TNTFrance::MESSAGE_DOMAIN), 'label_attr' => ['for' => TNTFranceConfigValue::OPTION_W_EXPEDITION_UNDER_PROTECTION, 'description' => Translator::getInstance()->trans('For your sensitive goods, exclusive feature and enhanced for maximum safety, from pickup to delivery.', [], TNTFrance::MESSAGE_DOMAIN), 'helper' => Translator::getInstance()->trans('(%default_price€ per package by default)', ['%default_price' => 3.6], TNTFrance::MESSAGE_DOMAIN)], 'constraints' => [new NotBlank()], 'data' => TNTFrance::getConfigValue(TNTFranceConfigValue::OPTION_W_EXPEDITION_UNDER_PROTECTION)])->add(TNTFranceConfigValue::OPTION_D_RELAY_PACKAGE, 'number', ['label' => Translator::getInstance()->trans('Option relay package', [], TNTFrance::MESSAGE_DOMAIN), 'label_attr' => ['for' => TNTFranceConfigValue::OPTION_D_RELAY_PACKAGE, 'description' => Translator::getInstance()->trans('Package delivered in one of the 4,200 Relay Colis.', [], TNTFrance::MESSAGE_DOMAIN), 'helper' => Translator::getInstance()->trans('(%default_price€ per package by default)', ['%default_price' => 1.9], TNTFrance::MESSAGE_DOMAIN)], 'constraints' => [new NotBlank()], 'data' => TNTFrance::getConfigValue(TNTFranceConfigValue::OPTION_D_RELAY_PACKAGE)])->add(TNTFranceConfigValue::OPTION_Z_HOME_DELIVERY, 'number', ['label' => Translator::getInstance()->trans('Option home delivery', [], TNTFrance::MESSAGE_DOMAIN), 'label_attr' => ['for' => TNTFranceConfigValue::OPTION_Z_HOME_DELIVERY, 'description' => Translator::getInstance()->trans('Parcels delivered to the recipient (if absent or access problem: the package is automatically deposited into a Relais Colis).', [], TNTFrance::MESSAGE_DOMAIN), 'helper' => Translator::getInstance()->trans('(%default_price€ per package by default)', ['%default_price' => 2.9], TNTFrance::MESSAGE_DOMAIN)], 'constraints' => [new NotBlank()], 'data' => TNTFrance::getConfigValue(TNTFranceConfigValue::OPTION_Z_HOME_DELIVERY)])->add(TNTFranceConfigValue::OPTION_E_WITHOUT_ANNOTATING, 'number', ['label' => Translator::getInstance()->trans('Option delivery without annotating', [], TNTFrance::MESSAGE_DOMAIN), 'label_attr' => ['for' => TNTFranceConfigValue::OPTION_E_WITHOUT_ANNOTATING, 'description' => Translator::getInstance()->trans('Contractual TNT option.', [], TNTFrance::MESSAGE_DOMAIN), 'helper' => Translator::getInstance()->trans('(%default_price€ per expedition by default)', ['%default_price' => 0], TNTFrance::MESSAGE_DOMAIN)], 'constraints' => [new NotBlank()], 'data' => TNTFrance::getConfigValue(TNTFranceConfigValue::OPTION_E_WITHOUT_ANNOTATING)])->add(TNTFranceConfigValue::PRICE_ONE_KG, 'collection', ['type' => 'number', 'label' => Translator::getInstance()->trans('Price', [], TNTFrance::MESSAGE_DOMAIN), 'allow_add' => true, 'allow_delete' => true, 'options' => ['constraints' => [new NotBlank(), new GreaterThan(array('value' => 0))]]])->add(TNTFranceConfigValue::PRICE_KG_SUP, 'collection', ['type' => 'number', 'label' => Translator::getInstance()->trans('Price kg sup', [], TNTFrance::MESSAGE_DOMAIN), 'allow_add' => true, 'allow_delete' => true, 'options' => ['constraints' => [new NotBlank(), new GreaterThan(array('value' => 0))]]]); }
protected function addTrackingUrlField(array $translationKeys, array $fieldsIdKeys) { $this->formBuilder->add("tracking_url", "text", array("label" => $this->readKey("tracking_url", $translationKeys), "label_attr" => ["for" => $this->readKey("tracking_url", $fieldsIdKeys), "help" => $this->readKey("help.tracking_url", $translationKeys)], "required" => false, "constraints" => array(), "data" => TNTFrance::getConfigValue(TNTFranceConfigValue::TRACKING_URL))); }
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; }
public function tntCalculCartWeight(CartEvent $event) { $event->getCart()->setVirtualColumn('total_weight', $event->getCart()->getWeight()); $maxWeightPackage = TNTFrance::getConfigValue(TNTFranceConfigValue::MAX_WEIGHT_PACKAGE, 25); $totalPackage = 0; //If packages are separated per product if (1 == TNTFrance::getConfigValue(TNTFranceConfigValue::SEPARATE_PRODUCT_IN_PACKAGE, 0)) { /** @var \Thelia\Model\CartItem $cartItem */ foreach ($event->getCart()->getCartItems() as $cartItem) { if (null != ($pse = ProductSaleElementsQuery::create()->findPk($cartItem->getProductSaleElementsId()))) { $totalPackage += ceil($cartItem->getQuantity() * $pse->getWeight() / $maxWeightPackage); } } } else { $totalPackage += ceil($event->getCart()->getVirtualColumn('total_weight') / $maxWeightPackage); } $event->getCart()->setVirtualColumn('total_package', $totalPackage); }
public function getValidPickUpDateAction() { return new Response(json_encode(TNTFrance::getDisablePickUpDate()), 200, array('content-type' => 'application/json')); }
/** * The options that are available * * @return array */ public function getOptionsEnabled() { return explode(',', TNTFrance::getConfigValue(TNTFranceConfigValue::OPTIONS_ENABLED, TNTFrance::DEFAULT_OPTIONS_ENABLED)); }
public static function calculPriceForService($serviceCode, $numberOfPackages, $weight = 0) { $price = 0; $freeShipping = intval(self::getConfigValue(TNTFranceConfigValue::FREE_SHIPPING, 0)); //A serviceCode is composed by a tnt_code_product AND a tnt_code_option if (strlen($serviceCode) == 2) { $productCode = substr($serviceCode, 0, 1); $optionCode = substr($serviceCode, 1, 1); } else { $productCode = $serviceCode; $optionCode = null; } if (0 == $freeShipping) { /** @var \TNTFrance\Model\TntPriceWeight $tntPriceWeight */ if (null != ($tntPriceWeight = TntPriceWeightQuery::create()->filterByTntProductCode($productCode)->findOne())) { $price = $tntPriceWeight->getPrice() + (floor($weight) - 1) * $tntPriceWeight->getPriceKgSup(); //Package SURCHARGES //surcharge_security_fee $price += $numberOfPackages * (double) TNTFrance::getConfigValue(TNTFranceConfigValue::SURCHARGE_SECURITY_FEE, 0); //surcharge surcharge_multi_package if ($numberOfPackages > 1) { $price += ($numberOfPackages - 1) * (double) TNTFrance::getConfigValue(TNTFranceConfigValue::SURCHARGE_MULTI_PACKAGE, 0); } //If there is an option_code and this option aply to each package if (null != $optionCode && in_array($optionCode, ['W', 'D', 'Z'])) { switch ($optionCode) { //option_expedition_under_protection case 'W': $price += $numberOfPackages * (double) TNTFrance::getConfigValue(TNTFranceConfigValue::OPTION_W_EXPEDITION_UNDER_PROTECTION, 0); break; //option_relay_package //option_relay_package case 'D': $price += $numberOfPackages * (double) TNTFrance::getConfigValue(TNTFranceConfigValue::OPTION_D_RELAY_PACKAGE, 0); break; //option_home_delivery //option_home_delivery case 'Z': $price += $numberOfPackages * (double) TNTFrance::getConfigValue(TNTFranceConfigValue::OPTION_Z_HOME_DELIVERY, 0); break; default: break; } } //Expedition SURCHARGES //surcharge_fuel $price += (double) TNTFrance::getConfigValue(TNTFranceConfigValue::SURCHARGE_FUEL, 0); //If there is an option_code and this option aply to each expedition if (null != $optionCode && in_array($optionCode, ['P', 'E'])) { switch ($optionCode) { //option_payment_back case 'P': $price += (double) TNTFrance::getConfigValue(TNTFranceConfigValue::OPTION_P_PAYMENT_BACK, 0); break; //option_without_annotating //option_without_annotating case 'E': $price += (double) TNTFrance::getConfigValue(TNTFranceConfigValue::OPTION_E_WITHOUT_ANNOTATING, 0); break; default: break; } } } } return $price; }
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)); }
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()])); }