Skip to content

Commit

Permalink
Merge pull request #1836 from magento-engcom/2.2-develop-prs
Browse files Browse the repository at this point in the history
[EngCom] Public Pull Requests - 2.2-develop

Public Pull Requests
 - magento-engcom#980 10123: Wrong invoice entity_model in table eav_entity_type. by @nmalevanec
 - magento-engcom#964 8507: There is invalid type in PHPDoc block of \Magento\Framework\Data\Tree::getNodeById() by @RomaKis
 - #11702 Fix getReservedOrderId() to use current store instead of default store by @tdgroot

Fixed Public Issues
 - #10123 Invoice entity_model in table eav_entity_type
 - #8507 There is invalid type in PHPDoc block of \Magento\Framework\Data\Tree::getNodeById()
 - #9055 Default Store is always used when retrieving sequence value's for sales entity's.
  • Loading branch information
Oleksii Korshenko authored Dec 12, 2017
2 parents 5f763a9 + c027c65 commit b9ab1ea
Show file tree
Hide file tree
Showing 7 changed files with 139 additions and 17 deletions.
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);
}
}
8 changes: 8 additions & 0 deletions app/code/Magento/Sales/Setup/UpgradeData.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,14 @@ public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface
[$setup]
);
}
if (version_compare($context->getVersion(), '2.0.9', '<')) {
//Correct wrong source model for "invoice" entity type, introduced by mistake in 2.0.1 upgrade.
$salesSetup->updateEntityType(
'invoice',
'entity_model',
\Magento\Sales\Model\ResourceModel\Order\Invoice::class
);
}
$this->eavConfig->clear();
}

Expand Down
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);
}
}
2 changes: 1 addition & 1 deletion app/code/Magento/Sales/etc/module.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Magento_Sales" setup_version="2.0.8">
<module name="Magento_Sales" setup_version="2.0.9">
<sequence>
<module name="Magento_Rule"/>
<module name="Magento_Catalog"/>
Expand Down
16 changes: 6 additions & 10 deletions lib/internal/Magento/Framework/Data/Tree.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,13 @@ class Tree
*/
protected $_nodes;

/**
* Enter description here...
*
*/
public function __construct()
{
$this->_nodes = new NodeCollection($this);
}

/**
* Enter description here...
* Get Tree.
*
* @return \Magento\Framework\Data\Tree
*/
Expand All @@ -43,7 +39,7 @@ public function getTree()
}

/**
* Enter description here...
* Load Tree.
*
* @param Node $parentNode
* @return void
Expand All @@ -54,7 +50,7 @@ public function load($parentNode = null)
}

/**
* Enter description here...
* Load Node by Node id.
*
* @param int|string $nodeId
* @return void
Expand Down Expand Up @@ -177,7 +173,7 @@ public function getChildren($node)
}

/**
* Enter description here...
* Get Nodes.
*
* @return NodeCollection
*/
Expand All @@ -187,9 +183,9 @@ public function getNodes()
}

/**
* Enter description here...
* Get Node by id.
*
* @param Node $nodeId
* @param string|int $nodeId
* @return Node
*/
public function getNodeById($nodeId)
Expand Down

0 comments on commit b9ab1ea

Please sign in to comment.