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()); } } }
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.")]]); }
/** * Save module configuration * * @return \Symfony\Component\HttpFoundation\RedirectResponse */ public function saveConfigurationAction() { $response = $this->checkAuth([AdminResources::MODULE], ['customdelivery'], AccessManager::UPDATE); if (null !== $response) { return $response; } $form = $this->createForm('customdelivery.configuration.form', 'form'); $message = ""; $response = null; try { $vform = $this->validateForm($form); $data = $vform->getData(); ConfigQuery::write(CustomDelivery::CONFIG_TRACKING_URL, $data['url']); ConfigQuery::write(CustomDelivery::CONFIG_PICKING_METHOD, $data['method']); ConfigQuery::write(CustomDelivery::CONFIG_TAX_RULE_ID, $data['tax']); } catch (\Exception $e) { $message = $e->getMessage(); } if ($message) { $form->setErrorMessage($message); $this->getParserContext()->addForm($form); $this->getParserContext()->setGeneralError($message); return $this->render("module-configure", ["module_code" => CustomDelivery::getModuleCode()]); } return RedirectResponse::create(URL::getInstance()->absoluteUrl("/admin/module/" . CustomDelivery::getModuleCode())); }
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")]); }
public function onModuleConfiguration(HookRenderEvent $event) { $moduleId = $this->getModule()->getModuleId(); $config = CustomDelivery::getConfig(); $event->add($this->render("configuration.html", ['module_id' => $moduleId, 'method' => $config['method']])); }