Ejemplo n.º 1
0
 /**
  * Returns a new CountryQuery object.
  *
  * @param     string $modelAlias The alias of a model in the query
  * @param     CountryQuery|Criteria $criteria Optional Criteria to build the query from
  *
  * @return CountryQuery
  */
 public static function create($modelAlias = null, $criteria = null)
 {
     if ($criteria instanceof CountryQuery) {
         return $criteria;
     }
     $query = new CountryQuery();
     if (null !== $modelAlias) {
         $query->setModelAlias($modelAlias);
     }
     if ($criteria instanceof Criteria) {
         $query->mergeWith($criteria);
     }
     return $query;
 }
Ejemplo n.º 2
0
 /**
  * Retrieve a country by ISO code (long or short)
  * 
  * @param mixed $country_code
  * @return Country
  */
 public static function retrieveByCountryCode($country_iso_code)
 {
     // If it's a long-code search
     if (strlen($country_iso_code) == 3) {
         return \CountryQuery::create()->filterByIsoCode($country_iso_code)->findOne();
         // Short code
     } elseif (strlen($country_iso_code) == 2) {
         return \CountryQuery::create()->filterByIsoShortCode($country_iso_code)->findOne();
     }
 }
Ejemplo n.º 3
0
 /**
  * Removes this object from datastore and sets delete attribute.
  *
  * @param      PropelPDO $con
  * @return void
  * @throws PropelException
  * @throws Exception
  * @see        BaseObject::setDeleted()
  * @see        BaseObject::isDeleted()
  */
 public function delete(PropelPDO $con = null)
 {
     if ($this->isDeleted()) {
         throw new PropelException("This object has already been deleted.");
     }
     if ($con === null) {
         $con = Propel::getConnection(CountryPeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
     }
     $con->beginTransaction();
     try {
         $deleteQuery = CountryQuery::create()->filterByPrimaryKey($this->getPrimaryKey());
         $ret = $this->preDelete($con);
         // symfony_behaviors behavior
         foreach (sfMixer::getCallables('BaseCountry:delete:pre') as $callable) {
             if (call_user_func($callable, $this, $con)) {
                 $con->commit();
                 return;
             }
         }
         if ($ret) {
             $deleteQuery->delete($con);
             $this->postDelete($con);
             // symfony_behaviors behavior
             foreach (sfMixer::getCallables('BaseCountry:delete:post') as $callable) {
                 call_user_func($callable, $this, $con);
             }
             $con->commit();
             $this->setDeleted(true);
         } else {
             $con->commit();
         }
     } catch (Exception $e) {
         $con->rollBack();
         throw $e;
     }
 }
Ejemplo n.º 4
0
 /**
  * Return the shop country
  *
  * @throws LogicException if no shop country is defined
  */
 public static function getShopLocation()
 {
     $dc = CountryQuery::create()->findOneByShopCountry(true);
     if ($dc == null) {
         throw new \LogicException(Translator::getInstance()->trans("Cannot find the shop country. Please select a shop country."));
     }
     return $dc;
 }
Ejemplo n.º 5
0
 /**
  * Return the shop country
  *
  * @throws LogicException if no shop country is defined
  */
 public static function getShopLocation()
 {
     $countryId = ConfigQuery::getStoreCountry();
     // return the default country if no shop country defined
     if (empty($countryId)) {
         return self::getDefaultCountry();
     }
     $shopCountry = CountryQuery::create()->findPk($countryId);
     if ($shopCountry === null) {
         throw new \LogicException(Translator::getInstance()->trans("Cannot find the shop country. Please select a shop country."));
     }
     return $shopCountry;
 }
Ejemplo n.º 6
0
 /**
  * Get the associated Country object
  *
  * @param      PropelPDO $con Optional Connection object.
  * @return                 Country The associated Country object.
  * @throws PropelException
  */
 public function getCountry(PropelPDO $con = null)
 {
     if ($this->aCountry === null && $this->country_id !== null) {
         $this->aCountry = CountryQuery::create()->findPk($this->country_id, $con);
         /* The following can be used additionally to
               guarantee the related object contains a reference
               to this object.  This level of coupling may, however, be
               undesirable since it could result in an only partially populated collection
               in the referenced object.
               $this->aCountry->addStates($this);
            */
     }
     return $this->aCountry;
 }
Ejemplo n.º 7
0
 /**
  * Return the postage without tax
  * @return float|int
  */
 public function getUntaxedPostage()
 {
     // get default tax rule
     $taxRuleQuery = new TaxRuleQuery();
     $taxRule = $taxRuleQuery->findOneByIsDefault(true);
     // get default country
     $countryQuery = new CountryQuery();
     $country = $countryQuery->findOneByByDefault(true);
     // get calculator for this tax / country
     $calculator = new \Thelia\TaxEngine\Calculator();
     $calculator->loadTaxRuleWithoutProduct($taxRule, $country);
     // return untaxed price
     return round($calculator->getUntaxedPrice($this->getPostage()), 2);
 }
Ejemplo n.º 8
0
 /**
  * Returns the number of related Country objects.
  *
  * @param      Criteria $criteria
  * @param      boolean $distinct
  * @param      PropelPDO $con
  * @return int             Count of related Country objects.
  * @throws PropelException
  */
 public function countCountrys(Criteria $criteria = null, $distinct = false, PropelPDO $con = null)
 {
     if (null === $this->collCountrys || null !== $criteria) {
         if ($this->isNew() && null === $this->collCountrys) {
             return 0;
         } else {
             $query = CountryQuery::create(null, $criteria);
             if ($distinct) {
                 $query->distinct();
             }
             return $query->filterByCurrency($this)->count($con);
         }
     } else {
         return count($this->collCountrys);
     }
 }