protected function _beforeSave()
{
parent::_beforeSave();
$this->_checkState();
if (!$this->getId()) {
$store = $this->getStore();
$name = array($store->getWebsite()->getName(),$store->getGroup()->getName(),$store->getName());
$this->setStoreName(implode("\n", $name));
}
if (!$this->getIncrementId()) {
$incrementId = Mage::getSingleton('eav/config')
->getEntityType('order')
->fetchNewIncrementId($this->getStoreId());
$this->setIncrementId($incrementId);
}
* Process items dependency for new order
*/
if (!$this->getId()) {
$itemsCount = 0;
foreach ($this->getAllItems() as $item) {
$parent = $item->getQuoteParentItemId();
if ($parent && !$item->getParentItem()) {
$item->setParentItem($this->getItemByQuoteItemId($parent));
} elseif (!$parent) {
$itemsCount++;
}
}
$this->setTotalItemCount($itemsCount);
}
if ($this->getCustomer()) {
$this->setCustomerId($this->getCustomer()->getId());
}
if ($this->hasBillingAddressId() && $this->getBillingAddressId() === null) {
$this->unsBillingAddressId();
}
if ($this->hasShippingAddressId() && $this->getShippingAddressId() === null) {
$this->unsShippingAddressId();
}
$this->setData('protect_code', substr(md5(uniqid(mt_rand(), true) . ':' . microtime(true)), 5, 6));
return $this;
}