public function beforeSave()
{
$this->total_price = $this->getProductsCost();
if ($this->getIsNewRecord()) {
$this->url = md5(uniqid(time(), true));
$this->ip = Yii::app()->getRequest()->userHostAddress;
if ($this->getScenario() === self::SCENARIO_USER) {
$this->delivery_price = $this->delivery ? $this->delivery->getCost($this->total_price) : 0;
$this->separate_delivery = $this->delivery ? $this->delivery->separate_payment : null;
}
}
$this->delivery_price = $this->getDeliveryCost();
return parent::beforeSave();
}