Merge branch 'master' into tax

This commit is contained in:
Etienne Roudeix
2013-10-23 16:32:10 +02:00
25 changed files with 1469 additions and 128 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)

View File

@@ -2,10 +2,18 @@
namespace Thelia\Model;
use Propel\Runtime\Connection\ConnectionInterface;
use Propel\Runtime\Exception\PropelException;
use Propel\Runtime\Propel;
use Thelia\Core\Event\Lang\LangEvent;
use Thelia\Core\Event\TheliaEvents;
use Thelia\Model\Base\Lang as BaseLang;
use Thelia\Model\Base\LangQuery;
use Thelia\Model\Map\LangTableMap;
class Lang extends BaseLang {
use \Thelia\Model\Tools\ModelEventDispatcherTrait;
/**
* Return the default language object, using a local variable to cache it.
*
@@ -20,4 +28,65 @@ class Lang extends BaseLang {
return $default_lang;
}
public function toggleDefault()
{
if($this->getId() === null) {
throw new \RuntimeException("impossible to just uncheck default language, choose a new one");
}
$con = Propel::getWriteConnection(LangTableMap::DATABASE_NAME);
$con->beginTransaction();
try {
LangQuery::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)
{
$this->dispatchEvent(TheliaEvents::BEFORE_CREATELANG, new LangEvent($this));
return true;
}
public function postInsert(ConnectionInterface $con = null)
{
$this->dispatchEvent(TheliaEvents::AFTER_CREATELANG, new LangEvent($this));
}
public function preUpdate(ConnectionInterface $con = null)
{
$this->dispatchEvent(TheliaEvents::BEFORE_UPDATELANG, new LangEvent($this));
return true;
}
public function postUpdate(ConnectionInterface $con = null)
{
$this->dispatchEvent(TheliaEvents::AFTER_UPDATELANG, new LangEvent($this));
}
public function preDelete(ConnectionInterface $con = null)
{
$this->dispatchEvent(TheliaEvents::BEFORE_DELETELANG, new LangEvent($this));
return true;
}
public function postDelete(ConnectionInterface $con = null)
{
$this->dispatchEvent(TheliaEvents::AFTER_DELETELANG, new LangEvent($this));
}
}