create toggleDefault method in lang method and modify in Country model
This commit is contained in:
@@ -3,9 +3,12 @@
|
||||
namespace Thelia\Model;
|
||||
|
||||
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;
|
||||
|
||||
class Country extends BaseCountry
|
||||
{
|
||||
@@ -16,13 +19,25 @@ class Country extends BaseCountry
|
||||
if($this->getId() === null) {
|
||||
throw new \RuntimeException("impossible to just uncheck default country, choose a new one");
|
||||
}
|
||||
CountryQuery::create()
|
||||
->filterByByDefault(1)
|
||||
->update(array('ByDefault' => 0));
|
||||
|
||||
$this
|
||||
->setByDefault(1)
|
||||
->save();
|
||||
$con = Propel::getWriteConnection(CountryTableMap::DATABASE_NAME);
|
||||
$con->beginTransaction();
|
||||
|
||||
try {
|
||||
CountryQuery::create()
|
||||
->filterByByDefault(1)
|
||||
->update(array('ByDefault' => 0), $con);
|
||||
|
||||
$this
|
||||
->setByDefault(1)
|
||||
->save($con);
|
||||
|
||||
$con->commit();
|
||||
} catch(PropelException $e) {
|
||||
$con->rollBack();
|
||||
throw $e;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function preInsert(ConnectionInterface $con = null)
|
||||
|
||||
Reference in New Issue
Block a user