/** * test check order - set state processing */ public function testCheckSetStateProcessing() { $this->orderMock->expects($this->once())->method('getId')->will($this->returnValue(1)); $this->orderMock->expects($this->once())->method('isCanceled')->will($this->returnValue(false)); $this->orderMock->expects($this->once())->method('canUnhold')->will($this->returnValue(false)); $this->orderMock->expects($this->once())->method('canInvoice')->will($this->returnValue(false)); $this->orderMock->expects($this->once())->method('canShip')->will($this->returnValue(true)); $this->orderMock->expects($this->once())->method('getState')->will($this->returnValue(Order::STATE_NEW)); $this->orderMock->expects($this->once())->method('getIsInProcess')->will($this->returnValue(true)); $this->orderMock->expects($this->once())->method('setState')->with(Order::STATE_PROCESSING)->will($this->returnSelf()); $this->assertEquals($this->state, $this->state->check($this->orderMock)); }
/** * @param \Magento\Framework\Model\AbstractModel $object * @return $this */ protected function _beforeSave(\Magento\Framework\Model\AbstractModel $object) { /** @var \Magento\Sales\Model\Order $object */ $this->stateHandler->check($object); if (!$object->getId()) { /** @var \Magento\Store\Model\Store $store */ $store = $object->getStore(); $name = [$store->getWebsite()->getName(), $store->getGroup()->getName(), $store->getName()]; $object->setStoreName(implode(PHP_EOL, $name)); $object->setTotalItemCount($this->calculateItems($object)); } $object->setData('protect_code', substr(md5(uniqid(Random::getRandomNumber(), true) . ':' . microtime(true)), 5, 6)); $isNewCustomer = !$object->getCustomerId() || $object->getCustomerId() === true; if ($isNewCustomer && $object->getCustomer()) { $object->setCustomerId($object->getCustomer()->getId()); } return parent::_beforeSave($object); }
/** * {@inheritdoc} */ public function save(\Magento\Framework\Model\AbstractModel $object) { /** @var \Magento\Sales\Model\Order $object */ $this->stateHandler->check($object); return parent::save($object); }