modification of model Order to not insert two times the order_version (when we insert for the first time an order object)

This commit is contained in:
Guillaume Barral
2014-06-19 12:02:58 +02:00
parent e5691b9793
commit 60124feb17

View File

@@ -17,6 +17,8 @@ class Order extends BaseOrder
protected $choosenDeliveryAddress = null; protected $choosenDeliveryAddress = null;
protected $choosenInvoiceAddress = null; protected $choosenInvoiceAddress = null;
protected $disableVersioning = false;
/** /**
* @param null $choosenDeliveryAddress * @param null $choosenDeliveryAddress
*/ */
@@ -27,6 +29,30 @@ class Order extends BaseOrder
return $this; return $this;
} }
/**
* @param boolean $disableVersionning
*/
public function setDisableVersioning($disableVersioning)
{
$this->disableVersioning = (bool) $disableVersioning;
return $this;
}
public function isVersioningDisable()
{
return $this->disableVersioning;
}
public function isVersioningNecessary($con = null)
{
if ($this->isVersioningDisable()) {
return false;
} else {
return parent::isVersioningNecessary($con);
}
}
/** /**
* @return null * @return null
*/ */
@@ -69,6 +95,7 @@ class Order extends BaseOrder
public function postInsert(ConnectionInterface $con = null) public function postInsert(ConnectionInterface $con = null)
{ {
$this->setRef($this->generateRef()) $this->setRef($this->generateRef())
->setDisableVersioning(true)
->save($con); ->save($con);
$this->dispatchEvent(TheliaEvents::ORDER_AFTER_CREATE, new OrderEvent($this)); $this->dispatchEvent(TheliaEvents::ORDER_AFTER_CREATE, new OrderEvent($this));
} }
@@ -84,7 +111,7 @@ class Order extends BaseOrder
public function generateRef() public function generateRef()
{ {
return sprintf('ORD%s', str_pad($this->getId(), 12, 0, STR_PAD_LEFT)); return sprintf('ORD%s', str_pad($this->getId(), 12, 0, STR_PAD_LEFT));
} }
/** /**