Skip to content

Commit f757b46

Browse files
author
Sergii Kovalenko
authored
Merge pull request magento#1449 from magento-honey-badgers/bugs
Fixed issues: - MAGETWO-71841 Caching issue with tier prices - MAGETWO-70603 Impossible add gift options on order level if use secure url
2 parents 28d4287 + c102785 commit f757b46

File tree

4 files changed

+132
-9
lines changed

4 files changed

+132
-9
lines changed

app/code/Magento/ConfigurableProduct/Block/Product/View/Type/Configurable.php

+12-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
use Magento\ConfigurableProduct\Model\ConfigurableAttributeData;
1111
use Magento\Customer\Helper\Session\CurrentCustomer;
12+
use Magento\Customer\Model\Session;
1213
use Magento\Framework\App\ObjectManager;
1314
use Magento\Framework\Locale\Format;
1415
use Magento\Framework\Pricing\PriceCurrencyInterface;
@@ -31,6 +32,7 @@ class Configurable extends \Magento\Catalog\Block\Product\View\AbstractView
3132
/**
3233
* Current customer
3334
*
35+
* @deprecated, as unused property
3436
* @var CurrentCustomer
3537
*/
3638
protected $currentCustomer;
@@ -67,6 +69,11 @@ class Configurable extends \Magento\Catalog\Block\Product\View\AbstractView
6769
*/
6870
private $localeFormat;
6971

72+
/**
73+
* @var Session
74+
*/
75+
private $customerSession;
76+
7077
/**
7178
* @param \Magento\Catalog\Block\Product\Context $context
7279
* @param \Magento\Framework\Stdlib\ArrayUtils $arrayUtils
@@ -78,6 +85,7 @@ class Configurable extends \Magento\Catalog\Block\Product\View\AbstractView
7885
* @param ConfigurableAttributeData $configurableAttributeData
7986
* @param array $data
8087
* @param Format|null $localeFormat
88+
* @param Session|null $customerSession
8189
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
8290
*/
8391
public function __construct(
@@ -90,7 +98,8 @@ public function __construct(
9098
PriceCurrencyInterface $priceCurrency,
9199
ConfigurableAttributeData $configurableAttributeData,
92100
array $data = [],
93-
Format $localeFormat = null
101+
Format $localeFormat = null,
102+
Session $customerSession = null
94103
) {
95104
$this->priceCurrency = $priceCurrency;
96105
$this->helper = $helper;
@@ -99,6 +108,7 @@ public function __construct(
99108
$this->currentCustomer = $currentCustomer;
100109
$this->configurableAttributeData = $configurableAttributeData;
101110
$this->localeFormat = $localeFormat ?: ObjectManager::getInstance()->get(Format::class);
111+
$this->customerSession = $customerSession ?: ObjectManager::getInstance()->get(Session::class);
102112

103113
parent::__construct(
104114
$context,
@@ -117,6 +127,7 @@ public function getCacheKeyInfo()
117127
{
118128
$parentData = parent::getCacheKeyInfo();
119129
$parentData[] = $this->priceCurrency->getCurrencySymbol();
130+
$parentData[] = $this->customerSession->getCustomerGroupId();
120131
return $parentData;
121132
}
122133

app/code/Magento/ConfigurableProduct/Test/Unit/Block/Product/View/Type/ConfigurableTest.php

+117-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
*/
66
namespace Magento\ConfigurableProduct\Test\Unit\Block\Product\View\Type;
77

8+
use Magento\Customer\Model\Session;
9+
use Magento\Framework\App\State;
10+
811
/**
912
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
1013
*/
@@ -65,6 +68,11 @@ class ConfigurableTest extends \PHPUnit\Framework\TestCase
6568
*/
6669
private $storeManager;
6770

71+
/**
72+
* @var \PHPUnit_Framework_MockObject_MockObject
73+
*/
74+
private $customerSession;
75+
6876
protected function setUp()
6977
{
7078
$this->mockContextObject();
@@ -92,6 +100,28 @@ protected function setUp()
92100
->disableOriginalConstructor()
93101
->getMock();
94102

103+
$appState = $this->getMockBuilder(State::class)
104+
->disableOriginalConstructor()
105+
->getMock();
106+
$this->context->expects($this->once())
107+
->method('getAppState')
108+
->willReturn($appState);
109+
$appState->expects($this->any())
110+
->method('getAreaCode')
111+
->willReturn('frontend');
112+
$urlBuilder = $this->getMockBuilder(\Magento\Framework\UrlInterface::class)
113+
->disableOriginalConstructor()
114+
->getMock();
115+
$this->context->expects($this->once())
116+
->method('getUrlBuilder')
117+
->willReturn($urlBuilder);
118+
$fileResolverMock = $this
119+
->getMockBuilder(\Magento\Framework\View\Element\Template\File\Resolver::class)
120+
->disableOriginalConstructor()
121+
->getMock();
122+
$this->context->expects($this->once())
123+
->method('getResolver')
124+
->willReturn($fileResolverMock);
95125
$this->configurableAttributeData = $this->getMockBuilder(
96126
\Magento\ConfigurableProduct\Model\ConfigurableAttributeData::class
97127
)
@@ -102,6 +132,10 @@ protected function setUp()
102132
->disableOriginalConstructor()
103133
->getMock();
104134

135+
$this->customerSession = $this->getMockBuilder(Session::class)
136+
->disableOriginalConstructor()
137+
->getMock();
138+
105139
$this->block = new \Magento\ConfigurableProduct\Block\Product\View\Type\Configurable(
106140
$this->context,
107141
$this->arrayUtils,
@@ -112,10 +146,92 @@ protected function setUp()
112146
$this->priceCurrency,
113147
$this->configurableAttributeData,
114148
[],
115-
$this->localeFormat
149+
$this->localeFormat,
150+
$this->customerSession
116151
);
117152
}
118153

154+
/**
155+
* Provide cache key info
156+
*
157+
* @return array
158+
*/
159+
public function cacheKeyProvider() : array
160+
{
161+
return [
162+
'without_currency_and_customer_group' => [
163+
[
164+
0 => 'BLOCK_TPL',
165+
1 => 'default',
166+
2 => null,
167+
'base_url' => null,
168+
'template' => null,
169+
3 => null,
170+
4 => null,
171+
],
172+
null,
173+
null,
174+
],
175+
'with_customer_group' => [
176+
[
177+
0 => 'BLOCK_TPL',
178+
1 => 'default',
179+
2 => null,
180+
'base_url' => null,
181+
'template' => null,
182+
3 => null,
183+
4 => 1,
184+
],
185+
null,
186+
1,
187+
],
188+
'with_price_currency' => [
189+
[
190+
0 => 'BLOCK_TPL',
191+
1 => 'default',
192+
2 => null,
193+
'base_url' => null,
194+
'template' => null,
195+
3 => '$',
196+
4 => null,
197+
],
198+
'$',
199+
null,
200+
]
201+
];
202+
}
203+
204+
/**
205+
* Test cache Tags
206+
* @dataProvider cacheKeyProvider
207+
* @param array $expected
208+
* @param string|null $priceCurrency
209+
* @param string|null $customerGroupId
210+
*/
211+
public function testGetCacheKeyInfo(array $expected, string $priceCurrency = null, string $customerGroupId = null)
212+
{
213+
$storeMock = $this->getMockBuilder(\Magento\Store\Api\Data\StoreInterface::class)
214+
->setMethods([
215+
'getCurrentCurrency',
216+
])
217+
->getMockForAbstractClass();
218+
$storeMock->expects($this->any())
219+
->method('getCode')
220+
->willReturn('default');
221+
222+
$this->storeManager->expects($this->any())
223+
->method('getStore')
224+
->willReturn($storeMock);
225+
$this->priceCurrency->expects($this->once())
226+
->method('getCurrencySymbol')
227+
->willReturn($priceCurrency);
228+
$this->customerSession->expects($this->once())
229+
->method('getCustomerGroupId')
230+
->willReturn($customerGroupId);
231+
$actual = $this->block->getCacheKeyInfo();
232+
$this->assertEquals($expected, $actual);
233+
}
234+
119235
/**
120236
* Check that getJsonConfig() method returns expected value
121237
*/

app/code/Magento/GiftMessage/Model/GiftMessageConfigProvider.php

+1-3
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,7 @@ public function getConfig()
119119
$configuration['isCustomerLoggedIn'] = $this->isCustomerLoggedIn();
120120
$configuration['formKey'] = $this->formKey->getFormKey();
121121
$store = $this->storeManager->getStore();
122-
$configuration['baseUrl'] = $store->isFrontUrlSecure()
123-
? $store->getBaseUrl(UrlInterface::URL_TYPE_LINK, true)
124-
: $store->getBaseUrl(UrlInterface::URL_TYPE_LINK, false);
122+
$configuration['baseUrl'] = $store->getBaseUrl(UrlInterface::URL_TYPE_LINK);
125123
return $configuration;
126124
}
127125

app/code/Magento/GiftMessage/Test/Unit/Model/GiftMessageConfigProviderTest.php

+2-4
Original file line numberDiff line numberDiff line change
@@ -98,13 +98,12 @@ public function testGetConfig()
9898
$storeCode = 4;
9999
$messageDataMock = ['from' => 'John Doe', 'to' => 'Jane Doe'];
100100
$formKey = 'ABCDEFGHIJKLMNOP';
101-
$isFrontUrlSecure = true;
102101
$baseUrl = 'https://magento.com/';
103102
$quoteItemMock = $this->createMock(\Magento\Quote\Model\Quote\Item::class);
104103
$productMock = $this->createMock(\Magento\Catalog\Model\Product::class);
105104
$storeMock = $this->createPartialMock(
106105
\Magento\Store\Model\Store::class,
107-
['isFrontUrlSecure', 'getBaseUrl', 'getCode']
106+
['getBaseUrl', 'getCode']
108107
);
109108
$quoteMock = $this->createPartialMock(
110109
\Magento\Quote\Model\Quote::class,
@@ -142,8 +141,7 @@ public function testGetConfig()
142141
->willReturn($isCustomerLoggedIn);
143142
$this->formKeyMock->expects($this->once())->method('getFormKey')->willReturn($formKey);
144143
$this->storeManagerMock->expects($this->once())->method('getStore')->willReturn($storeMock);
145-
$storeMock->expects($this->once())->method('isFrontUrlSecure')->willReturn($isFrontUrlSecure);
146-
$storeMock->expects($this->once())->method('getBaseUrl')->with(UrlInterface::URL_TYPE_LINK, $isFrontUrlSecure)
144+
$storeMock->expects($this->once())->method('getBaseUrl')->with(UrlInterface::URL_TYPE_LINK)
147145
->willReturn($baseUrl);
148146

149147
$expectedResult = [

0 commit comments

Comments
 (0)