Skip to content

Commit 7d5df6d

Browse files
committed
Merge remote-tracking branch 'mainline/develop' into BUGS
2 parents 70181a7 + 4372961 commit 7d5df6d

File tree

106 files changed

+2578
-677
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

106 files changed

+2578
-677
lines changed

app/code/Magento/Backend/App/AbstractAction.php

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ abstract class AbstractAction extends \Magento\Framework\App\Action\Action
2222
*/
2323
const SESSION_NAMESPACE = 'adminhtml';
2424

25+
/**
26+
* Authorization level of a basic admin session
27+
*/
28+
const ADMIN_RESOURCE = 'Magento_Backend::admin';
29+
2530
/**
2631
* Array of actions which can be processed without secret key validation
2732
*
@@ -97,7 +102,7 @@ public function __construct(Action\Context $context)
97102
*/
98103
protected function _isAllowed()
99104
{
100-
return true;
105+
return $this->_authorization->isAllowed(self::ADMIN_RESOURCE);
101106
}
102107

103108
/**
@@ -228,14 +233,10 @@ public function dispatch(\Magento\Framework\App\RequestInterface $request)
228233
*/
229234
protected function _isUrlChecked()
230235
{
231-
return !$this->_actionFlag->get(
232-
'',
233-
self::FLAG_IS_URLS_CHECKED
234-
) && !$this->getRequest()->getParam(
235-
'forwarded'
236-
) && !$this->_getSession()->getIsUrlNotice(
237-
true
238-
) && !$this->_canUseBaseUrl;
236+
return !$this->_actionFlag->get('', self::FLAG_IS_URLS_CHECKED)
237+
&& !$this->getRequest()->isForwarded()
238+
&& !$this->_getSession()->getIsUrlNotice(true)
239+
&& !$this->_canUseBaseUrl;
239240
}
240241

241242
/**

app/code/Magento/Backend/App/Action/Plugin/Authentication.php

Lines changed: 16 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -147,46 +147,25 @@ protected function _processNotLoggedInUser(\Magento\Framework\App\RequestInterfa
147147
if ($request->getPost('login') && $this->_performLogin($request)) {
148148
$isRedirectNeeded = $this->_redirectIfNeededAfterLogin($request);
149149
}
150-
if (!$isRedirectNeeded && !$request->getParam('forwarded')) {
150+
if (!$isRedirectNeeded && !$request->isForwarded()) {
151151
if ($request->getParam('isIframe')) {
152-
$request->setParam(
153-
'forwarded',
154-
true
155-
)->setRouteName(
156-
'adminhtml'
157-
)->setControllerName(
158-
'auth'
159-
)->setActionName(
160-
'deniedIframe'
161-
)->setDispatched(
162-
false
163-
);
152+
$request->setForwarded(true)
153+
->setRouteName('adminhtml')
154+
->setControllerName('auth')
155+
->setActionName('deniedIframe')
156+
->setDispatched(false);
164157
} elseif ($request->getParam('isAjax')) {
165-
$request->setParam(
166-
'forwarded',
167-
true
168-
)->setRouteName(
169-
'adminhtml'
170-
)->setControllerName(
171-
'auth'
172-
)->setActionName(
173-
'deniedJson'
174-
)->setDispatched(
175-
false
176-
);
158+
$request->setForwarded(true)
159+
->setRouteName('adminhtml')
160+
->setControllerName('auth')
161+
->setActionName('deniedJson')
162+
->setDispatched(false);
177163
} else {
178-
$request->setParam(
179-
'forwarded',
180-
true
181-
)->setRouteName(
182-
'adminhtml'
183-
)->setControllerName(
184-
'auth'
185-
)->setActionName(
186-
'login'
187-
)->setDispatched(
188-
false
189-
);
164+
$request->setForwarded(true)
165+
->setRouteName('adminhtml')
166+
->setControllerName('auth')
167+
->setActionName('login')
168+
->setDispatched(false);
190169
}
191170
}
192171
}

app/code/Magento/Backend/Test/Unit/App/Action/Plugin/AuthenticationTest.php

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,4 +84,78 @@ public function testAroundDispatchProlongStorage()
8484

8585
$this->assertEquals($expectedResult, $this->plugin->aroundDispatch($subject, $proceed, $request));
8686
}
87+
88+
/**
89+
* Calls aroundDispatch to access protected method _processNotLoggedInUser
90+
*
91+
* Data provider supplies different possibilities of request parameters and properties
92+
* @dataProvider processNotLoggedInUserDataProvider
93+
*/
94+
public function testProcessNotLoggedInUser($isIFrameParam, $isAjaxParam, $isForwardedFlag)
95+
{
96+
$subject = $this->getMockBuilder('Magento\Backend\Controller\Adminhtml\Index')
97+
->disableOriginalConstructor()
98+
->getMock();
99+
$request = $this->getMockBuilder('Magento\Framework\App\Request\Http')
100+
->disableOriginalConstructor()
101+
->getMock();
102+
$storage = $this->getMockBuilder('Magento\Backend\Model\Auth\Session')
103+
->disableOriginalConstructor()
104+
->getMock();
105+
106+
// Stubs to control the flow of execution in aroundDispatch
107+
$this->auth->expects($this->any())->method('getAuthStorage')->will($this->returnValue($storage));
108+
$request->expects($this->once())->method('getActionName')->will($this->returnValue('non/open/action/name'));
109+
$this->auth->expects($this->any())->method('getUser')->willReturn(false);
110+
$this->auth->expects($this->once())->method('isLoggedIn')->will($this->returnValue(false));
111+
$request->expects($this->any())->method('getPost')->willReturn(false);
112+
113+
// Test cases and expectations based on provided data
114+
$request->expects($this->once())->method('isForwarded')->willReturn($isForwardedFlag);
115+
$getParamCalls = 0;
116+
$actionName = '';
117+
118+
// If forwarded flag is set, getParam never gets called
119+
if (!$isForwardedFlag) {
120+
if ($isIFrameParam) {
121+
$getParamCalls = 1;
122+
$actionName = 'deniedIframe';
123+
} else if ($isAjaxParam) {
124+
$getParamCalls = 2;
125+
$actionName = 'deniedJson';
126+
} else {
127+
$getParamCalls = 2;
128+
$actionName = 'login';
129+
}
130+
}
131+
132+
$requestParams = [
133+
['isIframe', null, $isIFrameParam],
134+
['isAjax', null, $isAjaxParam]
135+
];
136+
137+
$setterCalls = $isForwardedFlag ? 0 : 1;
138+
$request->expects($this->exactly($getParamCalls))->method('getParam')->willReturnMap($requestParams);
139+
$request->expects($this->exactly($setterCalls))->method('setForwarded')->with(true)->willReturnSelf();
140+
$request->expects($this->exactly($setterCalls))->method('setRouteName')->with('adminhtml')->willReturnSelf();
141+
$request->expects($this->exactly($setterCalls))->method('setControllerName')->with('auth')->willReturnSelf();
142+
$request->expects($this->exactly($setterCalls))->method('setActionName')->with($actionName)->willReturnSelf();
143+
$request->expects($this->exactly($setterCalls))->method('setDispatched')->with(false)->willReturnSelf();
144+
145+
$expectedResult = 'expectedResult';
146+
$proceed = function ($request) use ($expectedResult) {
147+
return $expectedResult;
148+
};
149+
$this->assertEquals($expectedResult, $this->plugin->aroundDispatch($subject, $proceed, $request));
150+
}
151+
152+
public function processNotLoggedInUserDataProvider()
153+
{
154+
return [
155+
'iFrame' => [true, false, false],
156+
'Ajax' => [false, true, false],
157+
'Neither iFrame nor Ajax' => [false, false, false],
158+
'Forwarded request' => [true, true, true]
159+
];
160+
}
87161
}

app/code/Magento/Bundle/Pricing/Price/BundleRegularPrice.php

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
use Magento\Bundle\Pricing\Adjustment\BundleCalculatorInterface;
1010
use Magento\Catalog\Model\Product;
1111
use Magento\Framework\Pricing\Amount\AmountInterface;
12+
use Magento\Catalog\Pricing\Price\CustomOptionPrice;
13+
use Magento\Bundle\Model\Product\Price;
1214

1315
/**
1416
* Bundle product regular price model
@@ -48,7 +50,13 @@ public function __construct(
4850
public function getAmount()
4951
{
5052
if (null === $this->amount) {
51-
$this->amount = $this->calculator->getMinRegularAmount($this->getValue(), $this->product);
53+
$price = $this->getValue();
54+
if ($this->product->getPriceType() == Price::PRICE_TYPE_FIXED) {
55+
/** @var \Magento\Catalog\Pricing\Price\CustomOptionPrice $customOptionPrice */
56+
$customOptionPrice = $this->priceInfo->getPrice(CustomOptionPrice::PRICE_CODE);
57+
$price += $customOptionPrice->getCustomOptionRange(true);
58+
}
59+
$this->amount = $this->calculator->getMinRegularAmount($price, $this->product);
5260
}
5361
return $this->amount;
5462
}
@@ -61,7 +69,13 @@ public function getAmount()
6169
public function getMaximalPrice()
6270
{
6371
if (null === $this->maximalPrice) {
64-
$this->maximalPrice = $this->calculator->getMaxRegularAmount($this->getValue(), $this->product);
72+
$price = $this->getValue();
73+
if ($this->product->getPriceType() == Price::PRICE_TYPE_FIXED) {
74+
/** @var \Magento\Catalog\Pricing\Price\CustomOptionPrice $customOptionPrice */
75+
$customOptionPrice = $this->priceInfo->getPrice(CustomOptionPrice::PRICE_CODE);
76+
$price += $customOptionPrice->getCustomOptionRange(false);
77+
}
78+
$this->maximalPrice = $this->calculator->getMaxRegularAmount($price, $this->product);
6579
}
6680
return $this->maximalPrice;
6781
}

app/code/Magento/Bundle/Pricing/Price/FinalPrice.php

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
use Magento\Catalog\Model\Product;
1010
use Magento\Framework\Pricing\Adjustment\CalculatorInterface;
11+
use Magento\Catalog\Pricing\Price\CustomOptionPrice;
12+
use Magento\Bundle\Model\Product\Price;
1113

1214
/**
1315
* Final price model
@@ -68,7 +70,13 @@ public function getValue()
6870
public function getMaximalPrice()
6971
{
7072
if (!$this->maximalPrice) {
71-
$this->maximalPrice = $this->calculator->getMaxAmount($this->getBasePrice()->getValue(), $this->product);
73+
$price = $this->getBasePrice()->getValue();
74+
if ($this->product->getPriceType() == Price::PRICE_TYPE_FIXED) {
75+
/** @var \Magento\Catalog\Pricing\Price\CustomOptionPrice $customOptionPrice */
76+
$customOptionPrice = $this->priceInfo->getPrice(CustomOptionPrice::PRICE_CODE);
77+
$price += $customOptionPrice->getCustomOptionRange(false);
78+
}
79+
$this->maximalPrice = $this->calculator->getMaxAmount($price, $this->product);
7280
}
7381
return $this->maximalPrice;
7482
}
@@ -91,7 +99,13 @@ public function getMinimalPrice()
9199
public function getAmount()
92100
{
93101
if (!$this->minimalPrice) {
94-
$this->minimalPrice = $this->calculator->getAmount(parent::getValue(), $this->product);
102+
$price = parent::getValue();
103+
if ($this->product->getPriceType() == Price::PRICE_TYPE_FIXED) {
104+
/** @var \Magento\Catalog\Pricing\Price\CustomOptionPrice $customOptionPrice */
105+
$customOptionPrice = $this->priceInfo->getPrice(CustomOptionPrice::PRICE_CODE);
106+
$price += $customOptionPrice->getCustomOptionRange(true);
107+
}
108+
$this->minimalPrice = $this->calculator->getAmount($price, $this->product);
95109
}
96110
return $this->minimalPrice;
97111
}

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
namespace Magento\Bundle\Pricing\Price;
88

99
use Magento\Catalog\Pricing\Price\RegularPrice;
10+
use Magento\Framework\Pricing\Amount\AmountInterface;
1011

1112
/**
1213
* Bundle tier prices model
@@ -89,4 +90,13 @@ public function isPercentageDiscount()
8990
{
9091
return true;
9192
}
93+
94+
/**
95+
* @param AmountInterface $amount
96+
* @return float
97+
*/
98+
public function getSavePercent(AmountInterface $amount)
99+
{
100+
return round($amount->getBaseAmount());
101+
}
92102
}

0 commit comments

Comments
 (0)