public function findByCountryAndModule(Country $country, Module $module) { $response = null; if (null !== $country->getAreaId()) { $response = $this->filterByAreaId($country->getAreaId())->filterByModule($module)->findOne(); } return $response; }
/** * @param CountryModel $country * @depends testUpdate */ public function testDelete(CountryModel $country) { $event = new CountryDeleteEvent($country->getId()); $action = new Country(); $action->delete($event, null, $this->getMockEventDispatcher()); $deletedCountry = $event->getCountry(); $this->assertInstanceOf('Thelia\\Model\\Country', $deletedCountry); $this->assertTrue($deletedCountry->isDeleted()); }
/** * calculate and return delivery price * * @param Country $country * @throws \Exception * * @return mixed */ public function getPostage(Country $country) { if ($country !== null && $country->getArea() !== null) { $postage = $country->getArea()->getPostage(); } else { throw new \InvalidArgumentException("Country or Area should not be null"); } return $postage === null ? 0 : $postage; }
/** * Check if a delivery module is suitable for the given country. * * @param Country $country * @param Module $module * @return null|AreaDeliveryModule * @throws \Propel\Runtime\Exception\PropelException */ public function findByCountryAndModule(Country $country, Module $module) { $response = null; $countryInAreaList = CountryAreaQuery::create()->filterByCountryId($country->getId())->find(); foreach ($countryInAreaList as $countryInArea) { $response = $this->filterByAreaId($countryInArea->getAreaId())->filterByModule($module)->findOne(); if ($response !== null) { break; } } return $response; }
public static function findByCountryAndState(Country $country, State $state = null) { $response = null; if (null !== $state) { $countryAreaList = self::create()->filterByCountryId($country->getId())->filterByStateId($state->getId())->find(); if (count($countryAreaList) > 0) { return $countryAreaList; } } $countryAreaList = self::create()->filterByCountryId($country->getId())->filterByStateId(null)->find(); return $countryAreaList; }
/** * 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) { $cartWeight = $this->getRequest()->getSession()->getSessionCart($this->getDispatcher())->getWeight(); $areaId = $country->getAreaId(); $prices = SocolissimoPriceQuery::create()->filterByAreaId($areaId)->filterByWeightMax($cartWeight, Criteria::GREATER_EQUAL)->findOne(); $freeShipping = SocolissimoDeliveryModeQuery::create()->findOneByFreeshippingActive(1); /* check if Colissimo delivers the asked area*/ if (null !== $prices || null !== $freeShipping) { return true; } return false; }
public function testGetPostage() { $country = new Country(); $area = new Area(); $instance = new FlatFeeDelivery(); $area->setPostage(2.0); $country->setArea($area); $this->assertEquals($instance->getPostage($country), 2.0); $area->setPostage(null); $country->setArea($area); $this->assertEquals($instance->getPostage($country), 0.0); }
public function loadTaxRuleWithoutProduct(TaxRule $taxRule, Country $country) { $this->product = null; $this->country = null; $this->taxRulesCollection = null; if ($taxRule->getId() === null) { throw new TaxEngineException('TaxRule id is empty in Calculator::loadTaxRule', TaxEngineException::UNDEFINED_TAX_RULE); } if ($country->getId() === null) { throw new TaxEngineException('Country id is empty in Calculator::loadTaxRule', TaxEngineException::UNDEFINED_COUNTRY); } $this->country = $country; $this->product = new Product(); $this->taxRulesCollection = $this->taxRuleQuery->getTaxCalculatorCollection($taxRule, $country); return $this; }
/** * @param TaxRule $taxRule * @param Country $country * * @return array|mixed|\Propel\Runtime\Collection\ObjectCollection */ public function getTaxCalculatorCollection(TaxRule $taxRule, Country $country, State $state = null) { $key = sprintf('%s-%s-%s', $taxRule->getId(), $country->getId(), $state !== null ? $state->getId() : 0); if (array_key_exists($key, self::$caches)) { return self::$caches[$key]; } $taxRuleQuery = TaxRuleCountryQuery::create()->filterByCountry($country, Criteria::EQUAL)->filterByTaxRuleId($taxRule->getId()); if (null !== $state) { $taxRuleCount = $taxRuleQuery->filterByStateId($state->getId(), Criteria::EQUAL)->count(); if (0 === $taxRuleCount) { $taxRuleQuery->filterByStateId(null, Criteria::EQUAL); } } $search = TaxQuery::create()->filterByTaxRuleCountry($taxRuleQuery->find())->withColumn(TaxRuleCountryTableMap::POSITION, self::ALIAS_FOR_TAX_RULE_COUNTRY_POSITION)->orderBy(self::ALIAS_FOR_TAX_RULE_COUNTRY_POSITION, Criteria::ASC); return self::$caches[$key] = $search->find(); }
public function loadTaxRule(TaxRule $taxRule, Country $country, Product $product) { $this->product = null; $this->country = null; $this->taxRulesCollection = null; if ($taxRule->getId() === null) { throw new TaxEngineException('TaxRule id is empty in Calculator::loadTaxRule', TaxEngineException::UNDEFINED_TAX_RULE); } if ($country->getId() === null) { throw new TaxEngineException('Country id is empty in Calculator::loadTaxRule', TaxEngineException::UNDEFINED_COUNTRY); } if ($product->getId() === null) { throw new TaxEngineException('Product id is empty in Calculator::loadTaxRule', TaxEngineException::UNDEFINED_PRODUCT); } $this->country = $country; $this->product = $product; $key = $product->getTaxRule()->getId() . '-' . $country->getId(); if (!isset(self::$taxRulesMap[$key])) { self::$taxRulesMap[$key] = $this->taxRuleQuery->getTaxCalculatorCollection($taxRule, $country); } $this->taxRulesCollection = self::$taxRulesMap[$key]; return $this; }
public function buildModelCriteria() { $query = GoogleshoppingProductSynchronisationQuery::create()->filterByProductId($this->getProductId()); if ($this->getCountry()) { $targetCountry = $this->getCountry(); } else { $targetCountry = Country::getDefaultCountry()->getIsoalpha2(); } if ($this->getLocale()) { $lang = LangQuery::create()->findOneByLocale($this->getLocale())->getCode(); } else { $lang = Lang::getDefaultLanguage()->getCode(); } $query->filterByTargetCountry($targetCountry)->filterByLang($lang); return $query; }
/** * Retrieve the delivery country for a customer * * The rules : * - the country of the delivery address of the customer related to the * cart if it exists * - the country saved in cookie if customer have changed * the default country * - the default country for the shop if it exists * * * @param \Thelia\Model\Customer $customer * @return \Thelia\Model\Country */ protected function getDeliveryInformation(Customer $customer = null) { $address = null; // get the selected delivery address if (null !== ($addressId = $this->getCurrentRequest()->getSession()->getOrder()->getChoosenDeliveryAddress())) { if (null !== ($address = AddressQuery::create()->findPk($addressId))) { $this->isCustomizable = false; return [$address, $address->getCountry(), null]; } } // get country from customer addresses if (null !== $customer) { $address = AddressQuery::create()->filterByCustomerId($customer->getId())->filterByIsDefault(1)->findOne(); if (null !== $address) { $this->isCustomizable = false; return [$address, $address->getCountry(), null]; } } // get country from cookie $cookieName = ConfigQuery::read('front_cart_country_cookie_name', 'fcccn'); if ($this->getCurrentRequest()->cookies->has($cookieName)) { $cookieVal = $this->getCurrentRequest()->cookies->getInt($cookieName, 0); if (0 !== $cookieVal) { $country = CountryQuery::create()->findPk($cookieVal); if (null !== $country) { return [null, $country, null]; } } } // get default country for store. try { $country = Country::getDefaultCountry(); return [null, $country, null]; } catch (\LogicException $e) { } return [null, null, null]; }
public function toggleProductSync($id) { if (null !== ($response = $this->checkAuth(array(AdminResources::MODULE), array('GoogleShopping'), AccessManager::UPDATE))) { return $response; } if ($this->getRequest()->query->get('target_country')) { $targetCountry = CountryQuery::create()->findOneByIsoalpha2($this->getRequest()->get('target_country')); } else { $targetCountry = Country::getDefaultCountry(); } if ($this->getRequest()->query->get('locale')) { $lang = LangQuery::create()->findOneByLocale($this->getRequest()->query->get('locale')); } else { $lang = Lang::getDefaultLanguage(); } $product = ProductQuery::create()->findPk($id); $googleProductEvent = new GoogleProductEvent($product); $googleProductEvent->setTargetCountry($targetCountry)->setLang($lang); $this->getDispatcher()->dispatch(GoogleShoppingEvents::GOOGLE_PRODUCT_TOGGLE_SYNC, $googleProductEvent); }
public function getPostage(Country $country) { $cartWeight = $this->getRequest()->getSession()->getSessionCart($this->getDispatcher())->getWeight(); $postage = self::getPostageAmount($country->getAreaId(), $cartWeight); return $postage; }
/** * @param array $data * @return array * * Return the untaxed prices to store */ protected function extractPrices(array $data) { $calculator = new Calculator(); $calculator->loadTaxRuleWithoutProduct(TaxRuleQuery::create()->findPk($data["tax_rule_id"]), Country::getShopLocation()); $price = null === $data["price_with_tax"] ? $data["price"] : $calculator->getUntaxedPrice($data["price_with_tax"]); $salePrice = null === $data["sale_price_with_tax"] ? $data["sale_price"] : $calculator->getUntaxedPrice($data["sale_price_with_tax"]); return [$price, $salePrice]; }
/** * Calculate and return delivery price in the shop's default currency * * @param Country $country the country to deliver to. * * @return OrderPostage the delivery price * @throws DeliveryException if the postage price cannot be calculated. */ public function getPostage(Country $country) { $areaId = $country->getAreaId(); $cart = $this->getRequest()->getSession()->getSessionCart(); /** @var CustomDeliverySlice $slice */ $postage = $this->getSlicePostage($cart, $country); if (null === $postage) { throw new DeliveryException(); } return $postage; }
/** * Calculate taxed/untexted price for a product * * @param $price * @param $price_type * @param Product $product * @param bool $convert * @return string */ protected function computePrice($price, $price_type, Product $product, $convert = false) { $calc = new Calculator(); $calc->load($product, Country::getShopLocation()); if ($price_type == 'without_tax') { $return_price = $calc->getTaxedPrice($price); } elseif ($price_type == 'with_tax') { $return_price = $calc->getUntaxedPrice($price); } else { $return_price = $price; } if ($convert != 0) { $return_price = $price * Currency::getDefaultCurrency()->getRate(); } return floatval($return_price); }
/** * Update the promo status of the sale's selected products and combinations * * @param ProductSaleStatusUpdateEvent $event * @throws \RuntimeException * @throws \Exception * @throws \Propel\Runtime\Exception\PropelException */ public function updateProductsSaleStatus(ProductSaleStatusUpdateEvent $event) { $taxCalculator = new Calculator(); $sale = $event->getSale(); // Get all selected product sale elements for this sale if (null !== ($saleProducts = SaleProductQuery::create()->filterBySale($sale)->orderByProductId())) { $saleOffsetByCurrency = $sale->getPriceOffsets(); $offsetType = $sale->getPriceOffsetType(); $con = Propel::getWriteConnection(SaleTableMap::DATABASE_NAME); $con->beginTransaction(); try { /** @var SaleProduct $saleProduct */ foreach ($saleProducts as $saleProduct) { // Reset all sale status on product's PSE ProductSaleElementsQuery::create()->filterByProductId($saleProduct->getProductId())->update(['Promo' => false], $con); $taxCalculator->load($saleProduct->getProduct($con), CountryModel::getShopLocation()); $attributeAvId = $saleProduct->getAttributeAvId(); $pseRequest = ProductSaleElementsQuery::create()->filterByProductId($saleProduct->getProductId()); // If no attribute AV id is defined, consider ALL product combinations if (!is_null($attributeAvId)) { // Find PSE attached to combination containing this attribute av : // SELECT * from product_sale_elements pse // left join attribute_combination ac on ac.product_sale_elements_id = pse.id // where pse.product_id=363 // and ac.attribute_av_id = 7 // group by pse.id $pseRequest->useAttributeCombinationQuery(null, Criteria::LEFT_JOIN)->filterByAttributeAvId($attributeAvId)->endUse(); } $pseList = $pseRequest->find(); if (null !== $pseList) { $this->updateProductSaleElementsPrices($pseList, $sale->getActive(), $offsetType, $taxCalculator, $saleOffsetByCurrency, $con); } } $con->commit(); } catch (PropelException $e) { $con->rollback(); throw $e; } } }
/** * 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 = true; // We just check the country and weight // the address could not be a valid address for TNT at this moment cp - city if ('FR' !== $country->getIsoalpha2()) { $isValid = false; } /** @var \Thelia\Model\Customer $customer */ if (null != ($customer = $this->getRequest()->getSession()->getCustomerUser())) { //If INDIVIDUAL service exist, be sure that the customer has no company if (1 == TNTFrance::getConfigValue(TNTFranceConfigValue::USE_INDIVIDUAL, 0)) { if (null != $customer->getDefaultAddress()->getCompany() && $customer->getDefaultAddress()->getCompany() != "") { $isValid = false; } } //If ENTERPRISE service exist, be sure that the customer has a company if (1 == TNTFrance::getConfigValue(TNTFranceConfigValue::USE_ENTERPRISE, 0)) { if (null == $customer->getDefaultAddress()->getCompany() && $customer->getDefaultAddress()->getCompany() == "") { $isValid = false; } } } return $isValid; }
public function create(CountryCreateEvent $event) { $country = new CountryModel(); $country->setVisible($event->isVisible())->setIsocode($event->getIsocode())->setIsoalpha2($event->getIsoAlpha2())->setIsoalpha3($event->getIsoAlpha3())->setHasStates($event->isHasStates())->setLocale($event->getLocale())->setTitle($event->getTitle())->save(); $event->setCountry($country); }
/** * Exclude object from result * * @param ChildCountry $country Object to remove from the list of results * * @return ChildCountryQuery The current query, for fluid interface */ public function prune($country = null) { if ($country) { $this->addUsingAlias(CountryTableMap::ID, $country->getId(), Criteria::NOT_EQUAL); } return $this; }
/** * Format an address to a postal label * * @param AddressInterface $address * @param null $locale * @param null $originCountry * @param array $options * @return string */ public function postalLabelFormat(AddressInterface $address, $locale = null, $originCountry = null, $options = []) { $locale = $this->normalizeLocale($locale); $addressFormatRepository = new AddressFormatRepository(); $countryRepository = new CountryRepository(); $subdivisionRepository = new SubdivisionRepository(); if (null === $originCountry) { $countryId = Country::getShopLocation(); if (null === ($country = CountryQuery::create()->findPk($countryId))) { $country = Country::getDefaultCountry(); } $originCountry = $country->getIsoalpha2(); } $formatter = new PostalLabelFormatter($addressFormatRepository, $countryRepository, $subdivisionRepository, $originCountry, $locale, $options); $addressFormatted = $formatter->format($address); return $addressFormatted; }
/** * Retrieve the delivery country for a customer * * The rules : * - the country of the delivery address of the customer related to the * cart if it exists * - the country saved in cookie if customer have changed * the default country * - the default country for the shop if it exists * * * @param \Thelia\Model\Customer $customer * @return \Thelia\Model\Country */ protected function getDeliveryCountry(Customer $customer = null) { // get country from customer addresses if (null !== $customer) { $address = AddressQuery::create()->filterByCustomerId($customer->getId())->filterByIsDefault(1)->findOne(); if (null !== $address) { $this->isCustomizable = false; return $address->getCountry(); } } // get country from cookie $cookieName = ConfigQuery::read('front_cart_country_cookie_name', 'fcccn'); if ($this->request->cookies->has($cookieName)) { $cookieVal = $this->request->cookies->getInt($cookieName, 0); if (0 !== $cookieVal) { $country = CountryQuery::create()->findPk($cookieVal); if (null !== $country) { return $country; } } } // get default country for store. try { $country = Country::getDefaultCountry(); return $country; } catch (\LogicException $e) { } return null; }
/** * Filter the query by a related \Thelia\Model\Country object * * @param \Thelia\Model\Country|ObjectCollection $country the related object to use as filter * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL * * @return ChildAreaQuery The current query, for fluid interface */ public function filterByCountry($country, $comparison = null) { if ($country instanceof \Thelia\Model\Country) { return $this->addUsingAlias(AreaTableMap::ID, $country->getAreaId(), $comparison); } elseif ($country instanceof ObjectCollection) { return $this->useCountryQuery()->filterByPrimaryKeys($country->getPrimaryKeys())->endUse(); } else { throw new PropelException('filterByCountry() only accepts arguments of type \\Thelia\\Model\\Country or Collection'); } }
/** * Declares an association between this object and a ChildCountry object. * * @param ChildCountry $v * @return \Thelia\Model\OrderAddress The current object (for fluent API support) * @throws PropelException */ public function setCountry(ChildCountry $v = null) { if ($v === null) { $this->setCountryId(NULL); } else { $this->setCountryId($v->getId()); } $this->aCountry = $v; // Add binding for other direction of this n:n relationship. // If this object has already been added to the ChildCountry object, it will not be re-added. if ($v !== null) { $v->addOrderAddress($this); } return $this; }
/** * Calculate taxed/untexted price for a product * * @param $price * @param $price_type * @param Product $product * @param bool $convert * @return string */ protected function computePrice($price, $price_type, Product $product, $convert = false) { $calc = new Calculator(); $calc->load($product, Country::getShopLocation()); if ($price_type == 'without_tax') { $return_price = $calc->getTaxedPrice($price); } elseif ($price_type == 'with_tax') { $return_price = $calc->getUntaxedPrice($price); } else { $return_price = $price; } if ($convert != 0) { $return_price = $price * Currency::getDefaultCurrency()->getRate(); } // Format the number using '.', to perform further calculation return NumberFormat::getInstance($this->getRequest())->formatStandardNumber($return_price); }
/** * @param Country $country * @return null|mixed */ public static function translateCountry(Country $country) { $name = $country->setLocale("en_US")->getTitle(); $name = str_replace(" ", "_", strtoupper($name)); return defined($const = "Predict\\Export\\CountryEnum::" . $name) ? constant($const) : null; }
/** * Returns the object ID from the object * * @param \Thelia\Model\Country $object */ protected function getObjectId($object) { return $object->getId(); }
/** * Filter the query by a related \Thelia\Model\Country object * * @param \Thelia\Model\Country|ObjectCollection $country The related object(s) to use as filter * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL * * @return ChildCountryI18nQuery The current query, for fluid interface */ public function filterByCountry($country, $comparison = null) { if ($country instanceof \Thelia\Model\Country) { return $this->addUsingAlias(CountryI18nTableMap::ID, $country->getId(), $comparison); } elseif ($country instanceof ObjectCollection) { if (null === $comparison) { $comparison = Criteria::IN; } return $this->addUsingAlias(CountryI18nTableMap::ID, $country->toKeyValue('PrimaryKey', 'Id'), $comparison); } else { throw new PropelException('filterByCountry() only accepts arguments of type \\Thelia\\Model\\Country or Collection'); } }
/** * * calculate and return delivery price * * @param Country $country * @return mixed * @throws DeliveryException */ public function getPostage(Country $country) { $cartWeight = $this->getRequest()->getSession()->getCart()->getWeight(); $postage = PricesQuery::getPostageAmount($country->getAreaId(), $cartWeight); return $postage; }