Skip to content

Fix getReservedOrderId() to use current store instead of default store #11702

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions app/code/Magento/Quote/Model/ResourceModel/Quote.php
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,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 @@ -211,7 +211,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 Expand Up @@ -251,6 +251,21 @@ public function substractProductFromQuotes($product)
return $this;
}

/**
* Subtract product from all quotes quantities
*
* @param \Magento\Catalog\Model\Product $product
*
* @deprecated 101.0.1
* @see \Magento\Quote\Model\ResourceModel\Quote::subtractProductFromQuotes
*
* @return $this
*/
public function substractProductFromQuotes($product)
{
return $this->subtractProductFromQuotes($product);
}

/**
* Mark recollect contain product(s) quotes
*
Expand Down
103 changes: 103 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,103 @@
<?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(): array
{
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 @@ -48,7 +48,7 @@ public function testSubtractQtyFromQuotes()
['getId', 'getStatus', '__wakeup']
);
$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);
}
}