Skip to content

Commit b884072

Browse files
Merge branch 'MAGETWO-55937' into 'SPRINT-40'
MAGETWO-55937: [Complex product/Grouped productsl] Tax Amount and Custom Prices … …isnt displayed on Slide Panel (admin panel) See merge request !262
2 parents aa7a60c + dac8bfb commit b884072

File tree

8 files changed

+215
-5
lines changed

8 files changed

+215
-5
lines changed

app/code/Magento/Catalog/Pricing/Price/TierPrice.php

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use Magento\Framework\Pricing\Price\AbstractPrice;
1717
use Magento\Framework\Pricing\Price\BasePriceProviderInterface;
1818
use Magento\Framework\Pricing\PriceInfoInterface;
19+
use Magento\Customer\Model\Group\RetrieverInterface as CustomerGroupRetrieverInterface;
1920

2021
/**
2122
* @api
@@ -29,6 +30,7 @@ class TierPrice extends AbstractPrice implements TierPriceInterface, BasePricePr
2930

3031
/**
3132
* @var Session
33+
* @deprecated
3234
*/
3335
protected $customerSession;
3436

@@ -56,30 +58,39 @@ class TierPrice extends AbstractPrice implements TierPriceInterface, BasePricePr
5658
*/
5759
protected $groupManagement;
5860

61+
/**
62+
* @var CustomerGroupRetrieverInterface
63+
*/
64+
private $customerGroupRetriever;
65+
5966
/**
6067
* @param Product $saleableItem
6168
* @param float $quantity
6269
* @param CalculatorInterface $calculator
6370
* @param \Magento\Framework\Pricing\PriceCurrencyInterface $priceCurrency
6471
* @param Session $customerSession
6572
* @param GroupManagementInterface $groupManagement
73+
* @param CustomerGroupRetrieverInterface|null $customerGroupRetriever
6674
*/
6775
public function __construct(
6876
Product $saleableItem,
6977
$quantity,
7078
CalculatorInterface $calculator,
7179
\Magento\Framework\Pricing\PriceCurrencyInterface $priceCurrency,
7280
Session $customerSession,
73-
GroupManagementInterface $groupManagement
81+
GroupManagementInterface $groupManagement,
82+
CustomerGroupRetrieverInterface $customerGroupRetriever = null
7483
) {
7584
$quantity = $quantity ?: 1;
7685
parent::__construct($saleableItem, $quantity, $calculator, $priceCurrency);
7786
$this->customerSession = $customerSession;
7887
$this->groupManagement = $groupManagement;
88+
$this->customerGroupRetriever = $customerGroupRetriever
89+
?? \Magento\Framework\App\ObjectManager::getInstance()->get(CustomerGroupRetrieverInterface::class);
7990
if ($saleableItem->hasCustomerGroupId()) {
8091
$this->customerGroup = (int) $saleableItem->getCustomerGroupId();
8192
} else {
82-
$this->customerGroup = (int) $this->customerSession->getCustomerGroupId();
93+
$this->customerGroup = (int) $this->customerGroupRetriever->getCustomerGroupId();
8394
}
8495
}
8596

app/code/Magento/Catalog/Test/Unit/Pricing/Price/TierPriceTest.php

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,11 @@ class TierPriceTest extends \PHPUnit_Framework_TestCase
6767
*/
6868
protected $groupManagement;
6969

70+
/**
71+
* @var \Magento\Customer\Model\Group\RetrieverInterface|\PHPUnit_Framework_MockObject_MockObject
72+
*/
73+
protected $customerGroupRetriever;
74+
7075
/**
7176
* Initialize base dependencies
7277
*/
@@ -82,9 +87,11 @@ protected function setUp()
8287
false
8388
);
8489
$this->product->expects($this->any())->method('getPriceInfo')->will($this->returnValue($this->priceInfo));
90+
$this->customerGroupRetriever = $this->getMockBuilder(\Magento\Customer\Model\Group\RetrieverInterface::class)
91+
->disableOriginalConstructor()->getMock();
8592

8693
$this->session = $this->getMock(\Magento\Customer\Model\Session::class, [], [], '', false);
87-
$this->session->expects($this->any())->method('getCustomerGroupId')
94+
$this->customerGroupRetriever->expects($this->any())->method('getCustomerGroupId')
8895
->will($this->returnValue($this->customerGroup));
8996

9097
$this->calculator = $this->getMock(\Magento\Framework\Pricing\Adjustment\Calculator::class, [], [], '', false);
@@ -104,7 +111,8 @@ protected function setUp()
104111
$this->calculator,
105112
$this->priceCurrencyMock,
106113
$this->session,
107-
$this->groupManagement
114+
$this->groupManagement,
115+
$this->customerGroupRetriever
108116
);
109117
}
110118

@@ -248,7 +256,8 @@ public function testGetterStoredTierPrices()
248256
$this->calculator,
249257
$this->priceCurrencyMock,
250258
$this->session,
251-
$this->groupManagement
259+
$this->groupManagement,
260+
$this->customerGroupRetriever
252261
);
253262
$group = $this->getMock(
254263
\Magento\Customer\Model\Data\Group::class,
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Catalog\Model;
7+
8+
use Magento\Customer\Model\Session;
9+
10+
/**
11+
* Class for getting current customer group from customer session.
12+
*/
13+
class Retriever implements \Magento\Customer\Model\Group\RetrieverInterface
14+
{
15+
/**
16+
* @var Session
17+
*/
18+
private $customerSession;
19+
20+
/**
21+
* @param Session $customerSession
22+
*/
23+
public function __construct(Session $customerSession)
24+
{
25+
$this->customerSession = $customerSession;
26+
}
27+
28+
/**
29+
* @inheritdoc
30+
*/
31+
public function getCustomerGroupId()
32+
{
33+
return $this->customerSession->getCustomerGroupId();
34+
}
35+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Customer\Model\Group;
7+
8+
/**
9+
* Interface for getting current customer group from session.
10+
*
11+
* @api
12+
*/
13+
interface RetrieverInterface
14+
{
15+
/**
16+
* Retrieve customer group id.
17+
*
18+
* @return int
19+
*/
20+
public function getCustomerGroupId();
21+
}

app/code/Magento/Customer/etc/di.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@
5959
type="Magento\Customer\Model\Customer\Attribute\Source\Group"/>
6060
<preference for="Magento\Customer\Block\Account\SortLinkInterface"
6161
type="Magento\Customer\Block\Account\SortLink"/>
62+
<preference for="Magento\Customer\Model\Group\RetrieverInterface"
63+
type="Magento\Customer\Model\Group\Retriever"/>
6264
<type name="Magento\Customer\Model\Session">
6365
<arguments>
6466
<argument name="configShare" xsi:type="object">Magento\Customer\Model\Config\Share\Proxy</argument>
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Sales\Model;
7+
8+
use Magento\Backend\Model\Session\Quote;
9+
use Magento\Customer\Api\GroupManagementInterface;
10+
11+
/**
12+
* Class for getting customer group from quote session for adminhtml area.
13+
*/
14+
class CustomerGroupRetriever implements \Magento\Customer\Model\Group\RetrieverInterface
15+
{
16+
/**
17+
* @var Quote
18+
*/
19+
private $quoteSession;
20+
21+
/**
22+
* @var GroupManagementInterface
23+
*/
24+
private $groupManagement;
25+
26+
/**
27+
* @param Quote $quoteSession
28+
* @param GroupManagementInterface $groupManagement
29+
*/
30+
public function __construct(Quote $quoteSession, GroupManagementInterface $groupManagement)
31+
{
32+
$this->quoteSession = $quoteSession;
33+
$this->groupManagement = $groupManagement;
34+
}
35+
36+
/**
37+
* @inheritdoc
38+
*/
39+
public function getCustomerGroupId()
40+
{
41+
if ($this->quoteSession->getQuoteId() && $this->quoteSession->getQuote()) {
42+
return $this->quoteSession->getQuote()->getCustomerGroupId();
43+
}
44+
return $this->groupManagement->getNotLoggedInGroup()->getId();
45+
}
46+
}
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Sales\Test\Unit\Model;
7+
8+
use Magento\Backend\Model\Session\Quote;
9+
use Magento\Customer\Api\GroupManagementInterface;
10+
11+
/**
12+
* Test for class CustomerGroupRetriever.
13+
*/
14+
class CustomerGroupRetrieverTest extends \PHPUnit_Framework_TestCase
15+
{
16+
/**
17+
* @var \Magento\Sales\Model\CustomerGroupRetriever
18+
*/
19+
private $retriever;
20+
21+
/**
22+
* @var Quote|\PHPUnit_Framework_MockObject_MockObject
23+
*/
24+
private $quoteSession;
25+
26+
/**
27+
* @var GroupManagementInterface|\PHPUnit_Framework_MockObject_MockObject
28+
*/
29+
private $groupManagement;
30+
31+
/**
32+
* @inheritdoc
33+
*/
34+
protected function setUp()
35+
{
36+
$this->quoteSession = $this->getMockBuilder(Quote::class)
37+
->disableOriginalConstructor()
38+
->setMethods(['getQuoteId', 'getQuote'])
39+
->getMock();
40+
$this->groupManagement = $this->getMockBuilder(GroupManagementInterface::class)
41+
->disableOriginalConstructor()
42+
->getMockForAbstractClass();
43+
44+
$helper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
45+
$this->retriever = $helper->getObject(
46+
\Magento\Sales\Model\CustomerGroupRetriever::class,
47+
[
48+
'quoteSession' => $this->quoteSession,
49+
'groupManagement' => $this->groupManagement
50+
]
51+
);
52+
}
53+
54+
/**
55+
* Test method getCustomerGroupId with quote session.
56+
*/
57+
public function testGetCustomerGroupIdQuote()
58+
{
59+
$this->quoteSession->expects($this->atLeastOnce())->method('getQuoteId')->willReturn(1);
60+
$quote = $this->getMockBuilder(\Magento\Quote\Model\Quote::class)
61+
->disableOriginalConstructor()
62+
->getMock();
63+
$this->quoteSession->expects($this->atLeastOnce())->method('getQuote')->willReturn($quote);
64+
$quote->expects($this->once())->method('getCustomerGroupId')->willReturn(2);
65+
66+
$this->assertEquals(2, $this->retriever->getCustomerGroupId());
67+
}
68+
69+
/**
70+
* Test method getCustomerGroupId without quote session.
71+
*/
72+
public function testGetCustomerGroupIdDefault()
73+
{
74+
$this->quoteSession->expects($this->atLeastOnce())->method('getQuoteId')->willReturn(0);
75+
$this->quoteSession->expects($this->never())->method('getQuote');
76+
$group = $this->getMockBuilder(\Magento\Customer\Api\Data\GroupInterface::class)
77+
->disableOriginalConstructor()
78+
->getMockForAbstractClass();
79+
$this->groupManagement->expects($this->once())->method('getNotLoggedInGroup')->willReturn($group);
80+
$group->expects($this->once())->method('getId')->willReturn(2);
81+
82+
$this->assertEquals(2, $this->retriever->getCustomerGroupId());
83+
}
84+
}

app/code/Magento/Sales/etc/adminhtml/di.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
*/
77
-->
88
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
9+
<preference for="Magento\Customer\Model\Group\RetrieverInterface"
10+
type="Magento\Sales\Model\CustomerGroupRetriever"/>
911
<type name="Magento\Framework\App\Rss\RssManagerInterface">
1012
<arguments>
1113
<argument name="dataProviders" xsi:type="array">

0 commit comments

Comments
 (0)