public function orderSave(Replicate\Request\OrderSave $req) { $result = new Response\OrderSave(); /** @var \Magento\Sales\Api\Data\OrderInterface $mageOrder */ $mageOrder = $req->getSaleOrder(); $orderIdMage = $mageOrder->getEntityId(); /** @var $registeredOrder */ $registeredOrder = $this->_repoEntitySaleOrder->getById($orderIdMage); if ($orderIdMage && !$registeredOrder) { $odooOrder = $this->_subCollector->getSaleOrder($mageOrder); $def = $this->_manTrans->begin(); try { /* save order into Odoo repo */ $resp = $this->_repoOdooSaleOrder->save($odooOrder); $result->setOdooResponse($resp); if ($resp instanceof \Praxigento\Odoo\Data\Odoo\SaleOrder\Response) { $mageId = $mageOrder->getEntityId(); $odooId = $resp->getIdOdoo(); /* mark order as replicated */ $registry = new \Praxigento\Odoo\Data\Entity\SaleOrder(); $registry->setMageRef($mageId); $registry->setOdooRef($odooId); $this->_repoEntitySaleOrder->create($registry); /* finalize transaction */ $this->_manTrans->commit($def); $result->markSucceed(); } } finally { // transaction will be rolled back if commit is not done (otherwise - do nothing) $this->_manTrans->end($def); } } return $result; }
public function test_orderSave() { $req = new Request\OrderSave(); /* load Magento order */ $mageOrder = $this->_mageRepoSaleOrder->get(70); $req->setSaleOrder($mageOrder); $resp = $this->obj->orderSave($req); $this->assertNotNull($resp); }