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 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; }
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); }
/** * 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]; }
/** * 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; }