diff --git a/app/code/Magento/Checkout/Controller/Cart/Configure.php b/app/code/Magento/Checkout/Controller/Cart/Configure.php index 1a0fc1f3148f3..0c09470858bd3 100644 --- a/app/code/Magento/Checkout/Controller/Cart/Configure.php +++ b/app/code/Magento/Checkout/Controller/Cart/Configure.php @@ -44,18 +44,19 @@ public function execute() { // Extract item and product to configure $id = (int)$this->getRequest()->getParam('id'); + $productId = (int)$this->getRequest()->getParam('product_id'); $quoteItem = null; if ($id) { $quoteItem = $this->cart->getQuote()->getItemById($id); } - if (!$quoteItem) { - $this->messageManager->addError(__("We can't find the quote item.")); - $this->_redirect('checkout/cart'); - return; - } - try { + if (!$quoteItem || $productId != $quoteItem->getProduct()->getId()) { + $this->messageManager->addError(__("We can't find the quote item.")); + $this->_redirect('checkout/cart'); + return; + } + $params = new \Magento\Framework\Object(); $params->setCategoryId(false); $params->setConfigureMode(true); diff --git a/app/code/Magento/Checkout/view/frontend/layout/checkout_onepage_success.xml b/app/code/Magento/Checkout/view/frontend/layout/checkout_onepage_success.xml index 22ca2df12cec6..3fdbfc2c3cabc 100644 --- a/app/code/Magento/Checkout/view/frontend/layout/checkout_onepage_success.xml +++ b/app/code/Magento/Checkout/view/frontend/layout/checkout_onepage_success.xml @@ -6,6 +6,9 @@ */ --> + + Success Page + diff --git a/app/code/Magento/Multishipping/view/frontend/layout/multishipping_checkout_success.xml b/app/code/Magento/Multishipping/view/frontend/layout/multishipping_checkout_success.xml index 5ea53255269ed..e9bca9477d829 100644 --- a/app/code/Magento/Multishipping/view/frontend/layout/multishipping_checkout_success.xml +++ b/app/code/Magento/Multishipping/view/frontend/layout/multishipping_checkout_success.xml @@ -7,6 +7,9 @@ --> + + Success Page + diff --git a/app/code/Magento/SalesRule/Model/Rule/Action/Discount/ByPercent.php b/app/code/Magento/SalesRule/Model/Rule/Action/Discount/ByPercent.php index 59bc27a01ce7f..19e2f81d657c3 100644 --- a/app/code/Magento/SalesRule/Model/Rule/Action/Discount/ByPercent.php +++ b/app/code/Magento/SalesRule/Model/Rule/Action/Discount/ByPercent.php @@ -57,7 +57,9 @@ protected function _calculate($rule, $item, $qty, $rulePercent) $discountData->setAmount(($qty * $itemPrice - $item->getDiscountAmount()) * $_rulePct); $discountData->setBaseAmount(($qty * $baseItemPrice - $item->getBaseDiscountAmount()) * $_rulePct); $discountData->setOriginalAmount(($qty * $itemOriginalPrice - $item->getDiscountAmount()) * $_rulePct); - $discountData->setBaseOriginalAmount(($qty * $baseItemOriginalPrice - $item->getDiscountAmount()) * $_rulePct); + $discountData->setBaseOriginalAmount( + ($qty * $baseItemOriginalPrice - $item->getBaseDiscountAmount()) * $_rulePct + ); if (!$rule->getDiscountQty() || $rule->getDiscountQty() > $qty) { $discountPercent = min(100, $item->getDiscountPercent() + $rulePercent); diff --git a/dev/tests/unit/testsuite/Magento/Checkout/Controller/Cart/ConfigureTest.php b/dev/tests/unit/testsuite/Magento/Checkout/Controller/Cart/ConfigureTest.php new file mode 100644 index 0000000000000..716661bd022b1 --- /dev/null +++ b/dev/tests/unit/testsuite/Magento/Checkout/Controller/Cart/ConfigureTest.php @@ -0,0 +1,250 @@ +getMockBuilder('Magento\Framework\Event\ManagerInterface') + ->disableOriginalConstructor() + ->setMethods([]) + ->getMockForAbstractClass(); + $urlMock = $this->getMockBuilder('Magento\Framework\UrlInterface') + ->disableOriginalConstructor() + ->setMethods([]) + ->getMockForAbstractClass(); + $actionFlagMock = $this->getMockBuilder('Magento\Framework\App\ActionFlag') + ->disableOriginalConstructor() + ->setMethods([]) + ->getMockForAbstractClass(); + $viewMock = $this->getMockBuilder('Magento\Framework\App\ViewInterface') + ->disableOriginalConstructor() + ->setMethods([]) + ->getMockForAbstractClass(); + $this->objectManagerMock = $this->getMockBuilder('Magento\Framework\ObjectManagerInterface') + ->disableOriginalConstructor() + ->setMethods([]) + ->getMockForAbstractClass(); + $this->responseMock = $this->getMockBuilder('Magento\Framework\App\ResponseInterface') + ->disableOriginalConstructor() + ->setMethods([]) + ->getMockForAbstractClass(); + $this->requestMock = $this->getMockBuilder('Magento\Framework\App\RequestInterface') + ->disableOriginalConstructor() + ->setMethods(['getParam']) + ->getMockForAbstractClass(); + $this->messageManagerMock = $this->getMockBuilder('Magento\Framework\Message\ManagerInterface') + ->disableOriginalConstructor() + ->setMethods([]) + ->getMockForAbstractClass(); + $this->redirectMock = $this->getMockBuilder('Magento\Framework\App\Response\RedirectInterface') + ->disableOriginalConstructor() + ->setMethods([]) + ->getMock(); + + $this->contextMock = $this->getMockBuilder('Magento\Framework\App\Action\Context') + ->setConstructorArgs( + [ + $this->requestMock, + $this->responseMock, + $this->objectManagerMock, + $eventManagerMock, + $urlMock, + $this->redirectMock, + $actionFlagMock, + $viewMock, + $this->messageManagerMock + ] + ) + ->setMethods([]) + ->getMock(); + $this->contextMock->expects($this->any())->method('getObjectManager')->willReturn($this->objectManagerMock); + $this->contextMock->expects($this->any())->method('getRequest')->willReturn($this->requestMock); + $this->contextMock->expects($this->any())->method('getResponse')->willReturn($this->responseMock); + $this->contextMock->expects($this->any())->method('getMessageManager')->willReturn($this->messageManagerMock); + $this->contextMock->expects($this->any())->method('getRedirect')->willReturn($this->redirectMock); + $scopeConfig = $this->getMockBuilder('Magento\Framework\App\Config\ScopeConfigInterface') + ->disableOriginalConstructor() + ->getMock(); + $session = $this->getMockBuilder('Magento\Checkout\Model\Session') + ->disableOriginalConstructor() + ->getMock(); + $storeManager = $this->getMockBuilder('Magento\Store\Model\StoreManagerInterface') + ->disableOriginalConstructor() + ->getMockForAbstractClass(); + $formKeyValidator = $this->getMockBuilder('Magento\Core\App\Action\FormKeyValidator') + ->disableOriginalConstructor() + ->getMockForAbstractClass(); + $this->cartMock = $this->getMockBuilder('Magento\Checkout\Model\Cart') + ->disableOriginalConstructor() + ->getMock(); + $this->resultPageFactoryMock = $this->getMockBuilder('Magento\Framework\View\Result\PageFactory') + ->disableOriginalConstructor() + ->getMock(); + + $this->configureController = new \Magento\Checkout\Controller\Cart\Configure( + $this->contextMock, + $scopeConfig, + $session, + $storeManager, + $formKeyValidator, + $this->cartMock, + $this->resultPageFactoryMock + ); + } + + /** + * Test checks controller call product view and send parameter to it + * + * @return void + */ + public function testPrepareAndRenderCall() + { + $quoteId = 1; + $actualProductId = 1; + $quoteMock = $this->getMockBuilder('Magento\Quote\Model\Quote') + ->disableOriginalConstructor() + ->getMock(); + $quoteItemMock = $this->getMockBuilder('Magento\Quote\Model\Quote\Item') + ->disableOriginalConstructor() + ->getMock(); + $productMock = $this->getMockBuilder('Magento\Catalog\Model\Product') + ->disableOriginalConstructor() + ->getMock(); + $viewMock = $this->getMockBuilder('Magento\Catalog\Helper\Product\View') + ->disableOriginalConstructor() + ->getMock(); + $pageMock = $this->getMockBuilder('Magento\Framework\View\Result\Page') + ->disableOriginalConstructor() + ->getMock(); + $buyRequestMock = $this->getMockBuilder('Magento\Framework\Object') + ->disableOriginalConstructor() + ->getMock(); + //expects + $this->requestMock->expects($this->at(0)) + ->method('getParam') + ->with('id') + ->willReturn($quoteId); + $this->requestMock->expects($this->at(1)) + ->method('getParam') + ->with('product_id') + ->willReturn($actualProductId); + $this->cartMock->expects($this->any())->method('getQuote')->willReturn($quoteMock); + + $quoteItemMock->expects($this->exactly(1))->method('getBuyRequest')->willReturn($buyRequestMock); + + $this->resultPageFactoryMock->expects($this->once())->method('create')->willReturn($pageMock); + $this->objectManagerMock->expects($this->at(0)) + ->method('get') + ->with('Magento\Catalog\Helper\Product\View') + ->willReturn($viewMock); + + $viewMock->expects($this->once())->method('prepareAndRender')->with( + $pageMock, + $actualProductId, + $this->configureController, + $this->callback( + function ($subject) use ($buyRequestMock) { + return $subject->getBuyRequest() === $buyRequestMock; + } + ) + )->willReturn($pageMock); + + $quoteMock->expects($this->once())->method('getItemById')->willReturn($quoteItemMock); + $quoteItemMock->expects($this->exactly(2))->method('getProduct')->willReturn($productMock); + + $productMock->expects($this->exactly(2))->method('getId')->willReturn($actualProductId); + + $this->assertSame($pageMock, $this->configureController->execute()); + } + + /** + * Test checks controller redirect user to cart + * if user request product id in cart edit page is not same as quota product id + * + * @return void + */ + public function testRedirectWithWrongProductId() + { + $quotaId = 1; + $productIdInQuota = 1; + $productIdInRequest = null; + $quoteItemMock = $this->getMockBuilder('Magento\Quote\Model\Quote\Item') + ->disableOriginalConstructor() + ->getMock(); + $quoteMock = $this->getMockBuilder('Magento\Quote\Model\Quote') + ->disableOriginalConstructor() + ->getMock(); + $productMock = $this->getMockBuilder('Magento\Catalog\Model\Product') + ->disableOriginalConstructor() + ->getMock(); + $this->requestMock->expects($this->at(0)) + ->method('getParam') + ->with('id') + ->willReturn($quotaId); + $this->requestMock->expects($this->at(1)) + ->method('getParam') + ->with('product_id') + ->willReturn($productIdInRequest); + $this->cartMock->expects($this->any())->method('getQuote')->willReturn($quoteMock); + $quoteMock->expects($this->once())->method('getItemById')->willReturn($quoteItemMock); + $quoteItemMock->expects($this->exactly(1))->method('getProduct')->willReturn($productMock); + $productMock->expects($this->exactly(1))->method('getId')->willReturn($productIdInQuota); + $this->messageManagerMock->expects($this->once())->method('addError'); + $this->redirectMock->expects($this->once())->method('redirect')->with($this->responseMock, 'checkout/cart', []); + $this->configureController->execute(); + } +} diff --git a/dev/tests/unit/testsuite/Magento/SalesRule/Model/Rule/Action/Discount/ByPercentTest.php b/dev/tests/unit/testsuite/Magento/SalesRule/Model/Rule/Action/Discount/ByPercentTest.php index 3a8f64727c33d..b770464aa8d2a 100644 --- a/dev/tests/unit/testsuite/Magento/SalesRule/Model/Rule/Action/Discount/ByPercentTest.php +++ b/dev/tests/unit/testsuite/Magento/SalesRule/Model/Rule/Action/Discount/ByPercentTest.php @@ -209,7 +209,7 @@ public function calculateDataProvider() 'amount' => 42, 'baseAmount' => 25.5, 'originalAmount' => 51, - 'baseOriginalAmount' => 46.5, + 'baseOriginalAmount' => 34.5, ], ] ]; diff --git a/dev/tests/unit/testsuite/Magento/SalesRule/Model/Rule/Action/Discount/ToPercentTest.php b/dev/tests/unit/testsuite/Magento/SalesRule/Model/Rule/Action/Discount/ToPercentTest.php index 7163d2680c9a3..13bec6ff79e5a 100644 --- a/dev/tests/unit/testsuite/Magento/SalesRule/Model/Rule/Action/Discount/ToPercentTest.php +++ b/dev/tests/unit/testsuite/Magento/SalesRule/Model/Rule/Action/Discount/ToPercentTest.php @@ -209,7 +209,7 @@ public function calculateDataProvider() 'amount' => 98, 'baseAmount' => 59.5, 'originalAmount' => 119, - 'baseOriginalAmount' => 108.5, + 'baseOriginalAmount' => 80.5, ], ] ]; diff --git a/lib/web/mage/adminhtml/form.js b/lib/web/mage/adminhtml/form.js index c6fed3aa5fc4f..e266ece372ac4 100644 --- a/lib/web/mage/adminhtml/form.js +++ b/lib/web/mage/adminhtml/form.js @@ -458,7 +458,7 @@ FormElementDependenceController.prototype = { } } else { $(idTo).show(); - if (isAnInputOrSelect) { + if (isAnInputOrSelect && !isInheritCheckboxChecked) { $(idTo).disabled = false; jQuery('#' + idTo).removeClass('ignore-validate'); }