getWrappedConnection()); $database->insertSql(null, array(__DIR__ . '/Config/thelia.sql')); $database->insertSql(null, array(__DIR__ . '/Config/insert.sql')); } /** * This method is called by the Delivery loop, to check if the current module has to be displayed to the customer. * Override it to implements your delivery rules/ * * If you return true, the delivery method will de displayed to the customer * If you return false, the delivery method will not be displayed * * @param Country $country the country to deliver to. * * @return boolean */ public function isValidDelivery(Country $country) { $isValid = false; $con = Propel::getConnection(); $currentAddressId = $this->getRequest()->getSession()->getOrder()->getChoosenDeliveryAddress(); if (!empty($currentAddressId)) { $zipcode = AddressQuery::create()->filterById($currentAddressId)->findOne($con)->getZipcode(); // Condition 1 : le client doit être situé dans un secteur couvert par la livraison à domicile. if (null !== $areaFromZipcode = LpsAreaCityQuery::create()->filterByZipcode($zipcode)->findOne($con)) { $areaId = $areaFromZipcode->getIdArea(); $area = LpsAreaQuery::create()->findOneById($areaId); // Condition 2 : le secteur doit être actif à date. if (null !== $area && $area->getActive() === self::SECTEUR_ACTIF) $isValid = true; } } return $isValid; } /** * Calculate and return delivery price in the shop's default currency * * @param Country $country the country to deliver to. * * @return OrderPostage|float the delivery price * @throws DeliveryException if the postage price cannot be calculated. */ public function getPostage(Country $country) { if (! $this->isValidDelivery($country)) { throw new DeliveryException( Translator::getInstance()->trans("This module cannot be used on the current cart.") ); } $price = 0; $con = Propel::getConnection(); $currentAddressId = $this->getRequest()->getSession()->getOrder()->getChoosenDeliveryAddress(); if (!empty($currentAddressId)) { $zipcode = AddressQuery::create()->filterById($currentAddressId)->findOne($con)->getZipcode(); $areaId = LpsAreaCityQuery::create()->findOneByZipcode($zipcode)->getIdArea(); $price = LpsAreaQuery::create()->findOneById($areaId)->getPrice(); } return $price; } }