示例#1
0
 public function updateStatus(OrderEvent $event)
 {
     $order = $event->getOrder();
     $colissimo = new Colissimo();
     if ($order->isSent() && $order->getDeliveryModuleId() == $colissimo->getModuleModel()->getId()) {
         $contact_email = ConfigQuery::getStoreEmail();
         if ($contact_email) {
             $message = MessageQuery::create()->filterByName('mail_colissimo')->findOne();
             if (false === $message) {
                 throw new \Exception("Failed to load message 'order_confirmation'.");
             }
             $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());
             $this->parser->assign('package', $order->getDeliveryRef());
             $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("Colissimo shipping message sent to customer " . $customer->getEmail());
         } else {
             $customer = $order->getCustomer();
             Tlog::getInstance()->debug("Colissimo shipping message no contact email customer_id", $customer->getId());
         }
     }
 }
示例#2
0
 public function editprices()
 {
     // Get data & treat
     $post = $this->getRequest();
     $operation = $post->get('operation');
     $area = $post->get('area');
     $weight = $post->get('weight');
     $price = $post->get('price');
     if (preg_match("#^add|delete\$#", $operation) && preg_match("#^\\d+\$#", $area) && preg_match("#^\\d+\\.?\\d*\$#", $weight)) {
         // check if area exists in db
         $exists = AreaQuery::create()->findPK($area);
         if ($exists !== null) {
             if (null !== ($data = Colissimo::getConfigValue(ColissimoConfigValue::PRICES, null))) {
                 $json_data = json_decode($data, true);
             }
             if ((double) $weight > 0 && $operation == "add" && preg_match("#\\d+\\.?\\d*#", $price)) {
                 $json_data[$area]['slices'][$weight] = $price;
             } elseif ($operation == "delete") {
                 if (isset($json_data[$area]['slices'][$weight])) {
                     unset($json_data[$area]['slices'][$weight]);
                 }
             } else {
                 throw new \Exception("Weight must be superior to 0");
             }
             ksort($json_data[$area]['slices']);
             Colissimo::setConfigValue(ColissimoConfigValue::PRICES, json_encode($json_data));
         } else {
             throw new \Exception("Area not found");
         }
     } else {
         throw new \ErrorException("Arguments are missing or invalid");
     }
     return $this->redirectToConfigurationPage();
 }
示例#3
0
 public function updateStatus(OrderEvent $event)
 {
     $order = $event->getOrder();
     $colissimo = new Colissimo();
     if ($order->isSent() && $order->getDeliveryModuleId() == $colissimo->getModuleModel()->getId()) {
         $contact_email = ConfigQuery::getStoreEmail();
         if ($contact_email) {
             $order = $event->getOrder();
             $customer = $order->getCustomer();
             $this->mailer->sendEmailToCustomer('mail_colissimo', $customer, ['customer_id' => $customer->getId(), 'order_ref' => $order->getRef(), 'order_date' => $order->getCreatedAt(), 'update_date' => $order->getUpdatedAt(), 'package' => $order->getDeliveryRef()]);
             Tlog::getInstance()->debug("Colissimo shipping message sent to customer " . $customer->getEmail());
         } else {
             $customer = $order->getCustomer();
             Tlog::getInstance()->debug("Colissimo shipping message no contact email customer_id", $customer->getId());
         }
     }
 }
 /**
  * @param AreaDeleteEvent $event
  */
 public function updateConfig(AreaDeleteEvent $event)
 {
     if (null !== ($data = Colissimo::getConfigValue(ColissimoConfigValue::PRICES, null))) {
         $areaId = $event->getAreaId();
         $json_data = json_decode($data, true);
         unset($json_data[$areaId]);
         Colissimo::setConfigValue(ColissimoConfigValue::PRICES, json_encode($json_data, true));
     }
 }
示例#5
0
文件: Price.php 项目: margery/thelia
 public function buildArray()
 {
     $area = $this->getArea();
     $prices = Colissimo::getPrices();
     if (!isset($prices[$area]) || !isset($prices[$area]["slices"])) {
         return array();
     }
     $areaPrices = $prices[$area]["slices"];
     ksort($areaPrices);
     return $areaPrices;
 }
示例#6
0
 public function set()
 {
     $response = $this->checkAuth(AdminResources::MODULE, [Colissimo::DOMAIN_NAME], AccessManager::UPDATE);
     if (null !== $response) {
         return $response;
     }
     $form = $this->createForm('colissimo.freeshipping.form');
     try {
         $validateForm = $this->validateForm($form);
         $data = $validateForm->getData();
         Colissimo::setConfigValue(ColissimoConfigValue::FREE_SHIPPING, (int) $data["freeshipping"]);
         return $this->redirectToConfigurationPage();
     } catch (\Exception $e) {
         $response = JsonResponse::create(array("error" => $e->getMessage()), 500);
     }
     return $response;
 }
示例#7
0
 public function editConfiguration()
 {
     if (null !== ($response = $this->checkAuth(AdminResources::MODULE, [Colissimo::DOMAIN_NAME], AccessManager::UPDATE))) {
         return $response;
     }
     $form = $this->createForm('colissimo.configuration');
     $error_message = null;
     try {
         $validateForm = $this->validateForm($form);
         $data = $validateForm->getData();
         Colissimo::setConfigValue(ColissimoConfigValue::ENABLED, is_bool($data["enabled"]) ? (int) $data["enabled"] : $data["enabled"]);
         return $this->redirectToConfigurationPage();
     } catch (FormValidationException $e) {
         $error_message = $this->createStandardFormValidationErrorMessage($e);
     }
     if (null !== $error_message) {
         $this->setupFormErrorContext('configuration', $error_message, $form);
         $response = $this->render("module-configure", ['module_code' => 'Colissimo']);
     }
     return $response;
 }
示例#8
0
 public function update($currentVersion, $newVersion, ConnectionInterface $con = null)
 {
     $uploadDir = __DIR__ . '/Config/prices.json';
     $database = new Database($con);
     $table_exists = $database->execute("SELECT COUNT(*)\n             FROM information_schema.tables\n             WHERE table_schema = 'thelia'\n             AND table_name = 'colissimo_freeshipping'")->fetch()["COUNT(*)"] ? true : false;
     if (Colissimo::getConfigValue(ColissimoConfigValue::FREE_SHIPPING, null) == null && $table_exists) {
         $result = $database->execute('SELECT active FROM colissimo_freeshipping WHERE id=1')->fetch()["active"];
         Colissimo::setConfigValue(ColissimoConfigValue::FREE_SHIPPING, $result);
     }
     if (is_readable($uploadDir) && Colissimo::getConfigValue(ColissimoConfigValue::PRICES, null) == null) {
         Colissimo::setConfigValue(ColissimoConfigValue::PRICES, file_get_contents($uploadDir));
     }
 }
示例#9
0
 protected function buildForm()
 {
     $this->formBuilder->add("enabled", "checkbox", array("label" => "Enabled", "label_attr" => ["for" => "enabled", "help" => Translator::getInstance()->trans('Check if you want to activate Colissimo', [], Colissimo::DOMAIN_NAME)], "required" => false, "constraints" => array(), "value" => Colissimo::getConfigValue(ColissimoConfigValue::ENABLED, 1)));
 }
示例#10
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("freeshipping", "checkbox", array("label" => Translator::getInstance()->trans("Activate free shipping: ", [], Colissimo::DOMAIN_NAME), "value" => Colissimo::getConfigValue(ColissimoConfigValue::FREE_SHIPPING, false)));
 }
示例#11
0
 public function update($currentVersion, $newVersion, ConnectionInterface $con = null)
 {
     $uploadDir = __DIR__ . '/Config/prices.json';
     $database = new Database($con);
     $tableExists = $database->execute("SHOW TABLES LIKE 'colissimo_freeshipping'")->rowCount();
     if (Colissimo::getConfigValue(ColissimoConfigValue::FREE_SHIPPING, null) == null && $tableExists) {
         $result = $database->execute('SELECT active FROM colissimo_freeshipping WHERE id=1')->fetch()["active"];
         Colissimo::setConfigValue(ColissimoConfigValue::FREE_SHIPPING, $result);
         $database->execute("DROP TABLE `colissimo_freeshipping`");
     }
     if (is_readable($uploadDir) && Colissimo::getConfigValue(ColissimoConfigValue::PRICES, null) == null) {
         Colissimo::setConfigValue(ColissimoConfigValue::PRICES, file_get_contents($uploadDir));
     }
 }