getWrappedConnection()); $database->insertSql(null, array(__DIR__ . '/Config/insert.sql')); DeliveryRound::setConfigValue('price', 0); } /** * 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) { // Get current addressId $currentAddressId = $this->getRequest()->request->get('address_id'); if (empty($currentAddressId)) { if (null !== $customer = $this->getRequest()->getSession()->getCustomerUser()) { $currentAddressId = AddressQuery::create() ->filterByCustomer($customer) ->filterByIsDefault(1) ->select('ID') ->findOne(); } else { return false; } } // Get delivered zipcodes $deliveryRounds = DeliveryRoundQuery::create()->find(); $deliveryRoundZipcode = []; /** @var \DeliveryRound\Model\DeliveryRound $deliveryRound */ foreach ($deliveryRounds as $deliveryRound) { $deliveryRoundZipcode[] = $deliveryRound->getZipCode(); } // Check if the customer's current address is in delivered zipcodes if (null !== AddressQuery::create()->filterByZipcode($deliveryRoundZipcode)->findOneById($currentAddressId)) { return true; } else { return false; } } /** * @param $request * @return mixed * @throws \Propel\Runtime\Exception\PropelException */ protected function getCurrentlySelectedAddress($request) { return $currentAddressId; } /** * 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.") ); } return $this->getConfigValue('price', 0); } }