Skip to content

Commit

Permalink
Merge pull request #429 from magento-folks/checkout
Browse files Browse the repository at this point in the history
[Folks]Bugfix
  • Loading branch information
Shkolyarenko, Serhiy(sshkolyarenko) committed Jul 8, 2015
2 parents c0658ab + f05cacf commit bee47f0
Show file tree
Hide file tree
Showing 39 changed files with 919 additions and 286 deletions.
46 changes: 46 additions & 0 deletions app/code/Magento/Captcha/Test/Unit/Model/Cart/ConfigPluginTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php
/**
* Copyright © 2015 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Captcha\Test\Unit\Model\Cart;

class ConfigPluginTest extends \PHPUnit_Framework_TestCase
{
/**
* @var \Magento\Captcha\Model\Cart\ConfigPlugin
*/
protected $model;

/**
* @var \PHPUnit_Framework_MockObject_MockObject
*/
protected $configProviderMock;

public function setUp()
{
$this->configProviderMock = $this->getMock('\Magento\Captcha\Model\Checkout\ConfigProvider', [], [], '', false);
$this->model = new \Magento\Captcha\Model\Cart\ConfigPlugin(
$this->configProviderMock
);
}

public function testAfterGetConfig()
{
$resultMock = [
'result' => [
'data' => 'resultDataMock'
]
];
$configMock = [
'config' => [
'data' => 'configDataMock'
]
];
$expectedResult = array_merge_recursive($resultMock, $configMock);
$sidebarMock = $this->getMock('\Magento\Checkout\Block\Cart\Sidebar', [], [], '', false);
$this->configProviderMock->expects($this->once())->method('getConfig')->willReturn($configMock);

$this->assertEquals($expectedResult, $this->model->afterGetConfig($sidebarMock, $resultMock));
}
}
3 changes: 2 additions & 1 deletion app/code/Magento/Catalog/Helper/Product/Compare.php
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,8 @@ public function getAddToCartUrl($product)
$beforeCompareUrl = $this->_catalogSession->getBeforeCompareUrl();
$params = [
'product' => $product->getId(),
\Magento\Framework\App\Action\Action::PARAM_NAME_URL_ENCODED => $this->getEncodedUrl($beforeCompareUrl)
\Magento\Framework\App\Action\Action::PARAM_NAME_URL_ENCODED => $this->getEncodedUrl($beforeCompareUrl),
'_secure' => $this->_getRequest()->isSecure()
];

return $this->_getUrl('checkout/cart/add', $params);
Expand Down
53 changes: 48 additions & 5 deletions app/code/Magento/Catalog/Test/Unit/Helper/Product/CompareTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

namespace Magento\Catalog\Test\Unit\Helper\Product;

use Magento\Framework\App\Action\Action;

/**
* Class CompareTest
*/
Expand Down Expand Up @@ -41,12 +43,17 @@ class CompareTest extends \PHPUnit_Framework_TestCase
*/
protected $urlEncoder;

/**
* @var \Magento\Catalog\Model\Session | \PHPUnit_Framework_MockObject_MockObject
*/
protected $catalogSessionMock;

public function setUp()
{
$objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);

$this->urlBuilder = $this->getMock('Magento\Framework\Url', ['getUrl'], [], '', false);
$this->request = $this->getMock('Magento\Framework\App\Request\Http', ['getServer'], [], '', false);
$this->request = $this->getMock('Magento\Framework\App\Request\Http', ['getServer', 'isSecure'], [], '', false);
/** @var \Magento\Framework\App\Helper\Context $context */
$this->context = $this->getMock(
'Magento\Framework\App\Helper\Context',
Expand All @@ -58,7 +65,9 @@ public function setUp()
$this->urlEncoder = $this->getMockBuilder('Magento\Framework\Url\EncoderInterface')->getMock();
$this->urlEncoder->expects($this->any())
->method('encode')
->will($this->returnArgument(0));
->willReturnCallback(function ($url) {
return strtr(base64_encode($url), '+/=', '-_,');
});
$this->context->expects($this->once())
->method('getUrlBuilder')
->will($this->returnValue($this->urlBuilder));
Expand All @@ -75,10 +84,21 @@ public function setUp()
'',
false
);
$this->catalogSessionMock = $this->getMock(
'\Magento\Catalog\Model\Session',
['getBeforeCompareUrl'],
[],
'',
false
);

$this->compareHelper = $objectManager->getObject(
'Magento\Catalog\Helper\Product\Compare',
['context' => $this->context, 'postHelper' => $this->postDataHelper]
[
'context' => $this->context,
'postHelper' => $this->postDataHelper,
'catalogSession' => $this->catalogSessionMock
]
);
}

Expand All @@ -89,7 +109,7 @@ public function testGetPostDataRemove()
$removeUrl = 'catalog/product_compare/remove';
$compareListUrl = 'catalog/product_compare';
$postParams = [
\Magento\Framework\App\Action\Action::PARAM_NAME_URL_ENCODED => $compareListUrl,
Action::PARAM_NAME_URL_ENCODED => strtr(base64_encode($compareListUrl), '+/=', '-_,'),
'product' => $productId
];

Expand Down Expand Up @@ -136,7 +156,7 @@ public function testGetPostDataClearList()
$refererUrl = 'home/';
$clearUrl = 'catalog/product_compare/clear';
$postParams = [
\Magento\Framework\App\Action\Action::PARAM_NAME_URL_ENCODED => $refererUrl
Action::PARAM_NAME_URL_ENCODED => strtr(base64_encode($refererUrl), '+/=', '-_,')
];

//Verification
Expand All @@ -157,4 +177,27 @@ public function testGetPostDataClearList()

$this->assertTrue($this->compareHelper->getPostDataClearList());
}

public function testGetAddToCartUrl()
{
$productId = 42;
$isRequestSecure = false;
$beforeCompareUrl = 'http://magento.com/compare/before';
$encodedCompareUrl = strtr(base64_encode($beforeCompareUrl), '+/=', '-_,');
$expectedResult = [
'product' => $productId,
Action::PARAM_NAME_URL_ENCODED => $encodedCompareUrl,
'_secure' => $isRequestSecure
];

$productMock = $this->getMock('\Magento\Catalog\Model\Product', [], [], '', false);
$this->catalogSessionMock->expects($this->once())->method('getBeforeCompareUrl')->willReturn($beforeCompareUrl);
$productMock->expects($this->once())->method('getId')->willReturn($productId);
$this->urlEncoder->expects($this->once())->method('encode')->with($beforeCompareUrl)
->willReturn($encodedCompareUrl);
$this->request->expects($this->once())->method('isSecure')->willReturn($isRequestSecure);

$this->urlBuilder->expects($this->once())->method('getUrl')->with('checkout/cart/add', $expectedResult);
$this->compareHelper->getAddToCartUrl($productMock);
}
}
8 changes: 5 additions & 3 deletions app/code/Magento/Checkout/Block/Checkout/TotalsProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,18 @@ public function __construct(
public function process($jsLayout)
{
$configData = $this->scopeConfig->getValue('sales/totals_sort');
$totals = $jsLayout['components']['checkout']['children']['summary']['children']['totals']['children'];
$totals = $jsLayout['components']['checkout']['children']['sidebar']['children']['summary']
['children']['totals']['children'];
foreach ($totals as $code => &$total) {
//convert JS naming style to config naming style
$code = str_replace('-', '_', $code);
if (array_key_exists($code, $configData)) {
$total['sortOrder'] = $configData[$code];
}
}
$jsLayout['components']['checkout']['children']['summary']['children']['totals']['children'] = $totals;
$jsLayout['components']['checkout']['children']['sidebar']['children']['summary']
['children']['totals']['children'] = $totals;

return array_merge_recursive($jsLayout, $totals);
return $jsLayout;
}
}
8 changes: 4 additions & 4 deletions app/code/Magento/Checkout/Controller/Index/Index.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,20 @@ class Index extends \Magento\Checkout\Controller\Onepage
*/
public function execute()
{
/** @var \Magento\Checkout\Helper\Data $checkoutHelper */
$checkoutHelper = $this->_objectManager->get('Magento\Checkout\Helper\Data');
if (!$checkoutHelper->canOnepageCheckout()) {
$this->messageManager->addError(__('One-page checkout is turned off.'));
return $this->resultRedirectFactory->create()->setPath('checkout/cart');
}

$quote = $this->getOnepage()->getQuote();

if (!$this->_customerSession->isLoggedIn() && !$checkoutHelper->isAllowedGuestCheckout($quote)) {
$this->messageManager->addError(__('Guest checkout is disabled.'));
if (!$quote->hasItems() || $quote->getHasError() || !$quote->validateMinimumAmount()) {
return $this->resultRedirectFactory->create()->setPath('checkout/cart');
}

if (!$quote->hasItems() || $quote->getHasError() || !$quote->validateMinimumAmount()) {
if (!$this->_customerSession->isLoggedIn() && !$checkoutHelper->isAllowedGuestCheckout($quote)) {
$this->messageManager->addError(__('Guest checkout is disabled.'));
return $this->resultRedirectFactory->create()->setPath('checkout/cart');
}

Expand Down
6 changes: 5 additions & 1 deletion app/code/Magento/Checkout/Helper/Cart.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,11 @@ public function getAddUrl($product, $additional = [])
$continueUrl = $this->urlEncoder->encode($this->_urlBuilder->getCurrentUrl());
$urlParamName = \Magento\Framework\App\Action\Action::PARAM_NAME_URL_ENCODED;

$routeParams = [$urlParamName => $continueUrl, 'product' => $product->getEntityId()];
$routeParams = [
$urlParamName => $continueUrl,
'product' => $product->getEntityId(),
'_secure' => $this->_getRequest()->isSecure()
];

if (!empty($additional)) {
$routeParams = array_merge($routeParams, $additional);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ public function saveAddressInformation(
$this->validateQuote($quote);

$saveInAddressBook = $address->getSaveInAddressBook() ? 1 : 0;
$sameAsBilling = $address->getSameAsBilling() ? 1 : 0;
$customerAddressId = $address->getCustomerAddressId();
$this->addressValidator->validate($address);
$quote->setShippingAddress($address);
Expand All @@ -119,7 +118,7 @@ public function saveAddressInformation(
$addressData = $this->addressRepository->getById($customerAddressId);
$address = $quote->getShippingAddress()->importCustomerAddressData($addressData);
}
$address->setSameAsBilling($sameAsBilling);

$address->setSaveInAddressBook($saveInAddressBook);
$address->setCollectShippingRates(true);

Expand Down
Loading

0 comments on commit bee47f0

Please sign in to comment.