Exemplo n.º 1
0
 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;
 }
Exemplo n.º 2
0
 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;
 }
Exemplo n.º 3
0
 /**
  *
  * 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))]]]);
 }
Exemplo n.º 4
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;
 }
Exemplo n.º 6
0
 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);
 }
 /**
  * The options that are available
  *
  * @return array
  */
 public function getOptionsEnabled()
 {
     return explode(',', TNTFrance::getConfigValue(TNTFranceConfigValue::OPTIONS_ENABLED, TNTFrance::DEFAULT_OPTIONS_ENABLED));
 }
Exemplo n.º 8
0
 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 defaultAction()
 {
     $productsEnabled = TNTFrance::getConfigValue(TNTFranceConfigValue::PRODUCTS_ENABLED);
     return $this->render("tntfrance-configuration", ['products_enabled' => $productsEnabled]);
 }