Skip to content

Commit

Permalink
ENGCOM-2031: [Backport] #14063 - Wrong invoice prefix in multistore s…
Browse files Browse the repository at this point in the history
…etup due to default store id (fix order increment id)
  • Loading branch information
IvanPletnyov committed Jun 19, 2018
1 parent b82653b commit 957cb34
Show file tree
Hide file tree
Showing 4 changed files with 105 additions and 6 deletions.
4 changes: 2 additions & 2 deletions app/code/Magento/Quote/Model/ResourceModel/Quote.php
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ public function getReservedOrderId($quote)
{
return $this->sequenceManager->getSequence(
\Magento\Sales\Model\Order::ENTITY,
$quote->getStore()->getGroup()->getDefaultStoreId()
$quote->getStoreId()
)
->getNextValue();
}
Expand Down Expand Up @@ -236,7 +236,7 @@ public function markQuotesRecollectOnCatalogRules()
* @param \Magento\Catalog\Model\Product $product
* @return $this
*/
public function substractProductFromQuotes($product)
public function subtractProductFromQuotes($product)
{
$productId = (int)$product->getId();
if (!$productId) {
Expand Down
99 changes: 99 additions & 0 deletions app/code/Magento/Quote/Test/Unit/Model/ResourceModel/QuoteTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

namespace Magento\Quote\Test\Unit\Model\ResourceModel;

use Magento\Framework\DB\Sequence\SequenceInterface;
use Magento\Framework\Model\ResourceModel\Db\Context;
use Magento\Framework\Model\ResourceModel\Db\VersionControl\RelationComposite;
use Magento\Framework\Model\ResourceModel\Db\VersionControl\Snapshot;
use Magento\Quote\Model\Quote;
use Magento\SalesSequence\Model\Manager;

class QuoteTest extends \PHPUnit_Framework_TestCase
{
/**
* @var Quote|\PHPUnit_Framework_MockObject_MockObject
*/
private $quoteMock;
/**
* @var Manager|\PHPUnit_Framework_MockObject_MockObject
*/
private $sequenceManagerMock;
/**
* @var SequenceInterface|\PHPUnit_Framework_MockObject_MockObject
*/
private $sequenceMock;
/**
* @var \Magento\Quote\Model\ResourceModel\Quote
*/
private $quote;

/**
* {@inheritdoc}
*/
protected function setUp()
{
$context = $this->getMockBuilder(Context::class)
->disableOriginalConstructor()
->getMock();
$snapshot = $this->getMockBuilder(Snapshot::class)
->disableOriginalConstructor()
->getMock();
$relationComposite = $this->getMockBuilder(RelationComposite::class)
->disableOriginalConstructor()
->getMock();
$this->quoteMock = $this->getMockBuilder(Quote::class)
->disableOriginalConstructor()
->getMock();
$this->sequenceManagerMock = $this->getMockBuilder(Manager::class)
->disableOriginalConstructor()
->getMock();
$this->sequenceMock = $this->getMockBuilder(SequenceInterface::class)
->disableOriginalConstructor()
->getMock();
$this->quote = new \Magento\Quote\Model\ResourceModel\Quote(
$context,
$snapshot,
$relationComposite,
$this->sequenceManagerMock,
null
);
}

/**
* @param $entityType
* @param $storeId
* @param $reservedOrderId
* @dataProvider getReservedOrderIdDataProvider
*/
public function testGetReservedOrderId($entityType, $storeId, $reservedOrderId)
{
$this->sequenceManagerMock->expects($this->once())
->method('getSequence')
->with($entityType, $storeId)
->willReturn($this->sequenceMock);
$this->quoteMock->expects($this->once())
->method('getStoreId')
->willReturn($storeId);
$this->sequenceMock->expects($this->once())
->method('getNextValue')
->willReturn($reservedOrderId);
$this->assertEquals($reservedOrderId, $this->quote->getReservedOrderId($this->quoteMock));
}

/**
* @return array
*/
public function getReservedOrderIdDataProvider()
{
return [
[\Magento\Sales\Model\Order::ENTITY, 1, '1000000001'],
[\Magento\Sales\Model\Order::ENTITY, 2, '2000000001'],
[\Magento\Sales\Model\Order::ENTITY, 3, '3000000001']
];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,6 @@ public function __construct(\Magento\Quote\Model\ResourceModel\Quote $quote)
public function execute(\Magento\Framework\Event\Observer $observer)
{
$product = $observer->getEvent()->getProduct();
$this->_quote->substractProductFromQuotes($product);
$this->_quote->subtractProductFromQuotes($product);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ class SubtractQtyFromQuotesObserverTest extends \PHPUnit_Framework_TestCase
protected $_model;

/**
* @var \PHPUnit_Framework_MockObject_MockObject
* @var \Magento\Quote\Model\ResourceModel\Quote|\PHPUnit_Framework_MockObject_MockObject
*/
protected $_quoteMock;

/**
* @var \PHPUnit_Framework_MockObject_MockObject
* @var \Magento\Framework\Event\Observer|\PHPUnit_Framework_MockObject_MockObject
*/
protected $_observerMock;

Expand Down Expand Up @@ -54,7 +54,7 @@ public function testSubtractQtyFromQuotes()
false
);
$this->_eventMock->expects($this->once())->method('getProduct')->will($this->returnValue($productMock));
$this->_quoteMock->expects($this->once())->method('substractProductFromQuotes')->with($productMock);
$this->_quoteMock->expects($this->once())->method('subtractProductFromQuotes')->with($productMock);
$this->_model->execute($this->_observerMock);
}
}

0 comments on commit 957cb34

Please sign in to comment.