Inital commit

This commit is contained in:
2020-11-19 15:36:28 +01:00
parent 71f32f83d3
commit 66ce4ee218
18077 changed files with 2166122 additions and 35184 deletions

View File

@@ -2,13 +2,13 @@
namespace Thelia\Model;
use LogicException;
use Propel\Runtime\Connection\ConnectionInterface;
use Propel\Runtime\Exception\PropelException;
use Propel\Runtime\Propel;
use Thelia\Core\Event\Country\CountryEvent;
use Thelia\Core\Event\TheliaEvents;
use Thelia\Model\Base\Country as BaseCountry;
use Thelia\Model\Map\CountryTableMap;
use Thelia\Core\Translation\Translator;
@@ -18,6 +18,59 @@ class Country extends BaseCountry
protected static $defaultCountry = null;
/**
* get a regex pattern according to the zip code format field
* to match a zip code for this country.
*
* zip code format :
* - N : number
* - L : letter
* - C : iso of a state
*
* @return string|null will return a regex to match the zip code, otherwise null will be return
* if zip code format is not defined
*/
public function getZipCodeRE()
{
$zipCodeFormat = $this->getZipCodeFormat();
if (empty($zipCodeFormat)) {
return null;
}
$zipCodeRE = preg_replace("/\\s+/", ' ', $zipCodeFormat);
$trans = [
"N" => "\\d",
"L" => "[a-zA-Z]",
"C" => ".+",
" " => " +"
];
$zipCodeRE = "#^" . strtr($zipCodeRE, $trans) . "$#";
return $zipCodeRE;
}
/**
* This method ensure backward compatibility to Thelia 2.1, where a country belongs to one and
* only one shipping zone.
*
* @deprecated a country may belong to several Areas (shipping zones). Use CountryArea queries instead
*/
public function getAreaId()
{
$firstAreaCountry = CountryAreaQuery::create()->findOneByCountryId($this->getId());
if (null !== $firstAreaCountry) {
return $firstAreaCountry->getAreaId();
}
return null;
}
/**
*
* Put the current country as the default one.
@@ -49,7 +102,6 @@ class Country extends BaseCountry
$con->rollBack();
throw $e;
}
}
public function preInsert(ConnectionInterface $con = null)
@@ -117,11 +169,18 @@ class Country extends BaseCountry
*/
public static function getShopLocation()
{
$dc = CountryQuery::create()->findOneByShopCountry(true);
$countryId = ConfigQuery::getStoreCountry();
if ($dc == null)
// 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 $dc;
return $shopCountry;
}
}