create toggleDefault method in lang method and modify in Country model

This commit is contained in:
Manuel Raynaud
2013-10-23 09:19:53 +02:00
parent eac2c274e7
commit f881edbaa6
3 changed files with 61 additions and 6 deletions

View File

@@ -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)