findOne(); } catch (\Exception $e) { $database = new Database($con); $database->insertSql(null, [ __DIR__ . '/Config/thelia.sql' ]); // Test Enseigne and private key self::setConfigValue(self::CODE_ENSEIGNE, "BDTEST13"); self::setConfigValue(self::PRIVATE_KEY, "PrivateK"); self::setConfigValue(self::WEBSERVICE_URL, "https://api.mondialrelay.com/Web_Services.asmx?WSDL"); self::setConfigValue(self::GOOGLE_MAPS_API_KEY, "get_your_own_api_key"); self::setConfigValue(self::ALLOW_HOME_DELIVERY, true); self::setConfigValue(self::ALLOW_RELAY_DELIVERY, true); self::setConfigValue(self::ALLOW_INSURANCE, true); // Create mondial relay shipping zones for relay and home delivery $moduleId = self::getModuleId(); $rateFromEuro = Currency::getDefaultCurrency()->getRate(); $moduleConfiguration = json_decode(file_get_contents(__DIR__. '/Config/config-data.json')); if (false === $moduleConfiguration) { throw new TheliaProcessException("Invalid JSON configuration for Mondial Relay module"); } // Create all shipping zones, and associate Mondial relay module with them. foreach ($moduleConfiguration->shippingZones as $shippingZone) { AreaQuery::create()->filterByName($shippingZone->name)->delete(); $area = new Area(); $area ->setName($shippingZone->name) ->save(); foreach ($shippingZone->countries as $countryIsoCode) { if (null !== $country = CountryQuery::create()->findOneByIsoalpha3($countryIsoCode)) { (new CountryArea()) ->setAreaId($area->getId()) ->setCountryId($country->getId()) ->save(); } } // Define zone attributes (new MondialRelayZoneConfiguration()) ->setAreaId($area->getId()) ->setDeliveryType($shippingZone->delivery_type) ->setDeliveryTime($shippingZone->delivery_time_in_days) ->save(); // Attach this zone to our module (new AreaDeliveryModule()) ->setArea($area) ->setDeliveryModuleId($moduleId) ->save(); // Create base prices foreach ($shippingZone->prices as $price) { (new MondialRelayDeliveryPrice()) ->setAreaId($area->getId()) ->setMaxWeight($price->up_to) ->setPriceWithTax($price->price_euro * $rateFromEuro) ->save(); } } // Insurances foreach ($moduleConfiguration->insurances as $insurance) { (new MondialRelayDeliveryInsurance()) ->setMaxValue($insurance->value) ->setPriceWithTax($insurance->price_with_tax_euro) ->setLevel($insurance->level) ->save(); } if (null === MessageQuery::create()->findOneByName(self::TRACKING_MESSAGE_NAME)) { $message = new Message(); $message ->setName(self::TRACKING_MESSAGE_NAME) ->setHtmlLayoutFileName('') ->setHtmlTemplateFileName(self::TRACKING_MESSAGE_NAME.'.html') ->setTextLayoutFileName('') ->setTextTemplateFileName(self::TRACKING_MESSAGE_NAME.'.txt') ; $languages = LangQuery::create()->find(); /** @var Lang $language */ foreach ($languages as $language) { $locale = $language->getLocale(); $message->setLocale($locale); $message->setTitle( Translator::getInstance()->trans('Mondial Relay tracking information', [], self::DOMAIN_NAME, $locale) ); $message->setSubject( Translator::getInstance()->trans('Your order has been shipped', [], self::DOMAIN_NAME, $locale) ); } $message->save(); } /* Deploy the module's image */ $module = $this->getModuleModel(); if (ModuleImageQuery::create()->filterByModule($module)->count() == 0) { $this->deployImageFolder($module, sprintf('%s/images', __DIR__), $con); } } } /** * @param ConnectionInterface|null $con * @param bool $deleteModuleData * @throws \Propel\Runtime\Exception\PropelException */ public function destroy(ConnectionInterface $con = null, $deleteModuleData = false) { if ($deleteModuleData) { // Delete message MessageQuery::create()->filterByName(self::TRACKING_MESSAGE_NAME)->delete($con); // Delete module config data ModuleConfigQuery::create()->filterByModuleId(self::getModuleId())->delete($con); // Delete module tables. if (null !== $con) { $database = new Database($con); $database->insertSql(null, [__DIR__ . '/Config/drop.sql']); } } parent::destroy($con, $deleteModuleData); } }