Ejemplo n.º 1
0
 public function testGetSequence()
 {
     $entityType = 'order';
     $storeId = 1;
     $this->resourceSequenceMeta->expects($this->once())->method('loadByEntityTypeAndStore')->with($entityType, $storeId)->willReturn($this->meta);
     $this->sequenceFactory->expects($this->once())->method('create')->with(['meta' => $this->meta])->willReturn($this->sequence);
     $this->assertSame($this->sequence, $this->sequenceManager->getSequence($entityType, $storeId));
 }
Ejemplo n.º 2
0
 public function testSave()
 {
     $this->orderMock->expects($this->exactly(3))->method('getId')->willReturn(null);
     $this->orderItemMock->expects($this->once())->method('getChildrenItems')->willReturn([]);
     $this->orderItemMock->expects($this->once())->method('getQuoteParentItemId')->willReturn(null);
     $this->orderMock->expects($this->once())->method('setTotalItemCount')->with(1);
     $this->storeGroupMock->expects($this->once())->method('getDefaultStoreId')->willReturn(1);
     $this->orderMock->expects($this->once())->method('getAllItems')->willReturn([$this->orderItemMock]);
     $this->orderMock->expects($this->once())->method('validateBeforeSave')->willReturnSelf();
     $this->orderMock->expects($this->once())->method('beforeSave')->willReturnSelf();
     $this->orderMock->expects($this->once())->method('isSaveAllowed')->willReturn(true);
     $this->orderMock->expects($this->once())->method('getEntityType')->willReturn('order');
     $this->orderMock->expects($this->exactly(2))->method('getStore')->willReturn($this->storeMock);
     $this->storeMock->expects($this->exactly(2))->method('getGroup')->willReturn($this->storeGroupMock);
     $this->storeMock->expects($this->once())->method('getWebsite')->willReturn($this->websiteMock);
     $this->storeGroupMock->expects($this->once())->method('getDefaultStoreId')->willReturn(1);
     $this->salesSequenceManagerMock->expects($this->once())->method('getSequence')->with('order', 1)->willReturn($this->salesSequenceMock);
     $this->salesSequenceMock->expects($this->once())->method('getNextValue')->willReturn('10000001');
     $this->orderMock->expects($this->once())->method('setIncrementId')->with('10000001')->willReturnSelf();
     $this->orderMock->expects($this->once())->method('getIncrementId')->willReturn(null);
     $this->orderMock->expects($this->once())->method('getData')->willReturn(['increment_id' => '10000001']);
     $this->objectRelationProcessorMock->expects($this->once())->method('validateDataIntegrity')->with(null, ['increment_id' => '10000001']);
     $this->relationCompositeMock->expects($this->once())->method('processRelations')->with($this->orderMock);
     $this->resourceMock->expects($this->any())->method('getConnection')->willReturn($this->adapterMock);
     $this->adapterMock->expects($this->any())->method('quoteInto');
     $this->adapterMock->expects($this->any())->method('describeTable')->will($this->returnValue([]));
     $this->adapterMock->expects($this->any())->method('update');
     $this->adapterMock->expects($this->any())->method('lastInsertId');
     $this->orderMock->expects($this->any())->method('getId')->will($this->returnValue(1));
     $this->entitySnapshotMock->expects($this->once())->method('isModified')->with($this->orderMock)->will($this->returnValue(true));
     $this->resource->save($this->orderMock);
 }
Ejemplo n.º 3
0
 /**
  * Perform actions before object save
  * Perform actions before object save, calculate next sequence value for increment Id
  *
  * @param \Magento\Framework\Model\AbstractModel|\Magento\Framework\DataObject $object
  * @return $this
  */
 protected function _beforeSave(\Magento\Framework\Model\AbstractModel $object)
 {
     /** @var \Magento\Sales\Model\AbstractModel $object */
     if ($object instanceof EntityInterface && $object->getIncrementId() == null) {
         $object->setIncrementId($this->sequenceManager->getSequence($object->getEntityType(), $object->getStore()->getGroup()->getDefaultStoreId())->getNextValue());
     }
     parent::_beforeSave($object);
     return $this;
 }
Ejemplo n.º 4
0
 /**
  * Get reserved order id
  *
  * @param \Magento\Quote\Model\Quote $quote
  * @return string
  */
 public function getReservedOrderId($quote)
 {
     return $this->sequenceManager->getSequence(\Magento\Sales\Model\Order::ENTITY, $quote->getStore()->getGroup()->getDefaultStoreId())->getNextValue();
 }