Exemplo n.º 1
0
 /**
  * Save slice
  *
  * @return \Symfony\Component\HttpFoundation\RedirectResponse
  */
 public function saveAction()
 {
     $response = $this->checkAuth([], ['customdelivery'], AccessManager::UPDATE);
     if (null !== $response) {
         return $response;
     }
     $this->checkXmlHttpRequest();
     $responseData = ["success" => false, "message" => '', "slice" => null];
     $messages = [];
     $response = null;
     $config = CustomDelivery::getConfig();
     try {
         $requestData = $this->getRequest()->request;
         if (0 !== ($id = intval($requestData->get('id', 0)))) {
             $slice = CustomDeliverySliceQuery::create()->findPk($id);
         } else {
             $slice = new CustomDeliverySlice();
         }
         if (0 !== ($areaId = intval($requestData->get('area', 0)))) {
             $slice->setAreaId($areaId);
         } else {
             $messages[] = $this->getTranslator()->trans('The area is not valid', [], CustomDelivery::MESSAGE_DOMAIN);
         }
         if ($config['method'] != CustomDelivery::METHOD_WEIGHT) {
             $priceMax = floatval($requestData->get('priceMax', 0));
             if (0 != $priceMax) {
                 $slice->setPriceMax($priceMax);
             } else {
                 $messages[] = $this->getTranslator()->trans('The price max value is not valid', [], CustomDelivery::MESSAGE_DOMAIN);
             }
         }
         if ($config['method'] != CustomDelivery::METHOD_PRICE) {
             $weightMax = floatval($requestData->get('weightMax', 0));
             if (0 != $weightMax) {
                 $slice->setWeightMax($weightMax);
             } else {
                 $messages[] = $this->getTranslator()->trans('The weight max value is not valid', [], CustomDelivery::MESSAGE_DOMAIN);
             }
         }
         $price = floatval($requestData->get('price', 0));
         $slice->setPrice($price);
         if (0 === count($messages)) {
             $slice->save();
             $messages[] = $this->getTranslator()->trans('Your slice has been saved', [], CustomDelivery::MESSAGE_DOMAIN);
             $responseData['success'] = true;
             $responseData['slice'] = $slice->toArray(TableMap::TYPE_STUDLYPHPNAME);
         }
     } catch (\Exception $e) {
         $message[] = $e->getMessage();
     }
     $responseData['message'] = $messages;
     return $this->jsonResponse(json_encode($responseData));
 }
 public function updateStatus(OrderEvent $event)
 {
     $order = $event->getOrder();
     $customDelivery = new CustomDelivery();
     if ($order->isSent() && $order->getDeliveryModuleId() == $customDelivery->getModuleModel()->getId()) {
         $contact_email = ConfigQuery::getStoreEmail();
         if ($contact_email) {
             $message = MessageQuery::create()->filterByName('mail_custom_delivery')->findOne();
             if (false === $message) {
                 throw new \Exception("Failed to load message 'mail_custom_delivery'.");
             }
             $order = $event->getOrder();
             $customer = $order->getCustomer();
             $this->parser->assign('customer_id', $customer->getId());
             $this->parser->assign('order_ref', $order->getRef());
             $this->parser->assign('order_date', $order->getCreatedAt());
             $this->parser->assign('update_date', $order->getUpdatedAt());
             $package = $order->getDeliveryRef();
             $trackingUrl = null;
             if (!empty($package)) {
                 $config = CustomDelivery::getConfig();
                 $trackingUrl = $config['url'];
                 if (!empty($trackingUrl)) {
                     $trackingUrl = str_replace('%ID%', $package, $trackingUrl);
                 }
             }
             $this->parser->assign('package', $package);
             $this->parser->assign('tracking_url', $trackingUrl);
             $message->setLocale($order->getLang()->getLocale());
             $instance = \Swift_Message::newInstance()->addTo($customer->getEmail(), $customer->getFirstname() . " " . $customer->getLastname())->addFrom($contact_email, ConfigQuery::getStoreName());
             // Build subject and body
             $message->buildMessage($this->parser, $instance);
             $this->mailer->send($instance);
             Tlog::getInstance()->debug("Custom Delivery shipping message sent to customer " . $customer->getEmail());
         } else {
             $customer = $order->getCustomer();
             Tlog::getInstance()->debug("Custom Delivery shipping message no contact email customer_id", $customer->getId());
         }
     }
 }
Exemplo n.º 3
0
 protected function buildForm()
 {
     $form = $this->formBuilder;
     $config = CustomDelivery::getConfig();
     $form->add("url", "text", ['constraints' => [new NotBlank()], 'data' => $config['url'], 'label' => $this->trans("Tracking URL"), 'label_attr' => ['for' => "url", 'help' => $this->trans("The tracking URL. %ID% will be replaced by the tracking number entered in the order")]])->add("method", "choice", ['constraints' => [new NotBlank(), new GreaterThanOrEqual(['value' => 0])], "choices" => [CustomDelivery::METHOD_PRICE_WEIGHT => $this->trans("Price and weight"), CustomDelivery::METHOD_PRICE => $this->trans("Price"), CustomDelivery::METHOD_WEIGHT => $this->trans("Weight")], 'data' => $config['method'], 'label' => $this->trans("Method"), 'label_attr' => ['for' => "method", 'help' => $this->trans("The method used to select the right slice.")]])->add("tax", "tax_rule_id", ["constraints" => [new Callback(["methods" => [[$this, "checkTaxRuleId"]]])], 'required' => false, 'data' => $config['tax'], 'label' => $this->trans("Tax rule"), 'label_attr' => ['for' => "method", 'help' => $this->trans("The tax rule used to calculate postage taxes.")]]);
 }
Exemplo n.º 4
0
 protected function buildForm()
 {
     $form = $this->formBuilder;
     $config = CustomDelivery::getConfig();
     $form->add("id", "number", ['constraints' => [new NotBlank()], 'label' => $this->trans("Id")])->add("area", "area_id", ['constraints' => [new NotBlank(), new GreaterThanOrEqual(['value' => 0])], 'label' => $this->trans("Area")])->add("priceMax", "float", ['constraints' => [new NotBlank(), new GreaterThanOrEqual(['value' => 0])], 'label' => $this->trans("Area")])->add("weightMax", "float", ['constraints' => [new NotBlank(), new GreaterThanOrEqual(['value' => 0])], 'label' => $this->trans("Area")]);
 }
Exemplo n.º 5
0
 public function onModuleConfiguration(HookRenderEvent $event)
 {
     $moduleId = $this->getModule()->getModuleId();
     $config = CustomDelivery::getConfig();
     $event->add($this->render("configuration.html", ['module_id' => $moduleId, 'method' => $config['method']]));
 }