Skip to content

Commit 342ffcc

Browse files
author
valdislav
committed
MAGETWO-36882: Stabilizing branch
1 parent f951933 commit 342ffcc

File tree

2 files changed

+33
-5
lines changed

2 files changed

+33
-5
lines changed

app/code/Magento/Sales/Model/Resource/EntityAbstract.php

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -231,12 +231,38 @@ public function save(\Magento\Framework\Model\AbstractModel $object)
231231
$this->objectRelationProcessor->validateDataIntegrity($this->getMainTable(), $object->getData());
232232
if ($object->getId() !== null && (!$this->_useIsObjectNew || !$object->isObjectNew())) {
233233
$condition = $this->_getWriteAdapter()->quoteInto($this->getIdFieldName() . '=?', $object->getId());
234-
$data = $this->_prepareDataForSave($object);
235-
unset($data[$this->getIdFieldName()]);
236-
$this->_getWriteAdapter()->update($this->getMainTable(), $data, $condition);
234+
/**
235+
* Not auto increment primary key support
236+
*/
237+
if ($this->_isPkAutoIncrement) {
238+
$data = $this->prepareDataForUpdate($object);
239+
if (!empty($data)) {
240+
$this->_getWriteAdapter()->update($this->getMainTable(), $data, $condition);
241+
}
242+
} else {
243+
$select = $this->_getWriteAdapter()->select()->from(
244+
$this->getMainTable(),
245+
[$this->getIdFieldName()]
246+
)->where(
247+
$condition
248+
);
249+
if ($this->_getWriteAdapter()->fetchOne($select) !== false) {
250+
$data = $this->prepareDataForUpdate($object);
251+
if (!empty($data)) {
252+
$this->_getWriteAdapter()->update($this->getMainTable(), $data, $condition);
253+
}
254+
} else {
255+
$this->_getWriteAdapter()->insert(
256+
$this->getMainTable(),
257+
$this->_prepareDataForSave($object)
258+
);
259+
}
260+
}
237261
} else {
238262
$bind = $this->_prepareDataForSave($object);
239-
unset($bind[$this->getIdFieldName()]);
263+
if ($this->_isPkAutoIncrement) {
264+
unset($bind[$this->getIdFieldName()]);
265+
}
240266
$this->_getWriteAdapter()->insert($this->getMainTable(), $bind);
241267

242268
$object->setId($this->_getWriteAdapter()->lastInsertId($this->getMainTable()));
@@ -245,9 +271,10 @@ public function save(\Magento\Framework\Model\AbstractModel $object)
245271
$object->isObjectNew(false);
246272
}
247273
}
274+
248275
$this->unserializeFields($object);
249276
$this->_afterSave($object);
250-
$this->entitySnapshot->registerSnapshot($object);
277+
251278
$object->afterSave();
252279
$this->processRelations($object);
253280
}

dev/tests/integration/testsuite/Magento/Sales/_files/order.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
$orderItem->setBasePrice($product->getPrice());
3030
$orderItem->setPrice($product->getPrice());
3131
$orderItem->setRowTotal($product->getPrice());
32+
$orderItem->setProductType('simple');
3233

3334
/** @var \Magento\Sales\Model\Order $order */
3435
$order = $objectManager->create('Magento\Sales\Model\Order');

0 commit comments

Comments
 (0)