Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…gento2ce into MAGETWO-42140
  • Loading branch information
rganin committed Jan 6, 2016
2 parents e0fdccd + 11dcb28 commit dab098e
Show file tree
Hide file tree
Showing 21 changed files with 150 additions and 159 deletions.
12 changes: 6 additions & 6 deletions app/code/Magento/Bundle/Model/Product/Type.php
Original file line number Diff line number Diff line change
Expand Up @@ -636,6 +636,12 @@ protected function _prepareProduct(\Magento\Framework\DataObject $buyRequest, $p
if (!empty($selectionIds)) {
$selections = $this->getSelectionsByIds($selectionIds, $product);

if (count($selections->getItems()) !== count($selectionIds)) {
throw new \Magento\Framework\Exception\LocalizedException(
__('The options you selected are not available.')
);
}

// Check if added selections are still on sale
$this->checkSelectionsIsSale(
$selections,
Expand Down Expand Up @@ -808,12 +814,6 @@ public function getSelectionsByIds($selectionIds, $product)
->addFilterByRequiredOptions()
->setSelectionIdsFilter($selectionIds);

if (count($usedSelections->getItems()) !== count($selectionIds)) {
throw new \Magento\Framework\Exception\LocalizedException(
__('The options you selected are not available.')
);
}

if (!$this->_catalogData->isPriceGlobal() && $storeId) {
$websiteId = $this->_storeManager->getStore($storeId)
->getWebsiteId();
Expand Down
150 changes: 22 additions & 128 deletions app/code/Magento/Bundle/Test/Unit/Model/Product/TypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ function ($key) use ($optionCollection, $selectionCollection) {
->willReturn('options');
$option->expects($this->at(3))
->method('getId')
->willReturn(10);
->willReturn(3);
$option->expects($this->once())
->method('getRequired')
->willReturn(true);
Expand Down Expand Up @@ -379,7 +379,7 @@ function ($key) use ($optionCollection, $selectionCollection) {
$resultValue = $selectionCollection;
break;
case '_cache_instance_used_selections_ids':
$resultValue = [2, 5, 14];
$resultValue = [5];
break;
}

Expand All @@ -404,7 +404,7 @@ function ($key) use ($optionCollection, $selectionCollection) {
->method('setStoreFilter');
$buyRequest->expects($this->once())
->method('getBundleOption')
->willReturn([3 => 5, 10 => [7 => 2, 11 => 14]]);
->willReturn([3 => 5]);
$selectionCollection->expects($this->any())
->method('getItems')
->willReturn([$selection]);
Expand Down Expand Up @@ -433,13 +433,13 @@ function ($key) use ($optionCollection, $selectionCollection) {
->willReturn($productType);
$option->expects($this->at(3))
->method('getId')
->willReturn(10);
->willReturn(3);
$option->expects($this->at(9))
->method('getId')
->willReturn(10);
->willReturn(3);
$option->expects($this->once())
->method('getRequired')
->willReturn(true);
->willReturn(false);
$option->expects($this->once())
->method('isMultiSelection')
->willReturn(true);
Expand Down Expand Up @@ -611,7 +611,7 @@ function ($key) use ($optionCollection, $selectionCollection) {
$resultValue = $selectionCollection;
break;
case '_cache_instance_used_selections_ids':
$resultValue = [2, 5, 14];
$resultValue = [5];
break;
}

Expand All @@ -636,7 +636,7 @@ function ($key) use ($optionCollection, $selectionCollection) {
->method('setStoreFilter');
$buyRequest->expects($this->once())
->method('getBundleOption')
->willReturn([3 => 5, 10 => [7 => 2, 11 => 14]]);
->willReturn([3 => 5]);
$selectionCollection->expects($this->any())
->method('getItems')
->willReturn([$selection]);
Expand Down Expand Up @@ -665,13 +665,13 @@ function ($key) use ($optionCollection, $selectionCollection) {
->willReturn($productType);
$option->expects($this->at(3))
->method('getId')
->willReturn(10);
->willReturn(3);
$option->expects($this->at(9))
->method('getId')
->willReturn(10);
->willReturn(3);
$option->expects($this->once())
->method('getRequired')
->willReturn(true);
->willReturn(false);
$option->expects($this->once())
->method('isMultiSelection')
->willReturn(true);
Expand Down Expand Up @@ -831,7 +831,7 @@ function ($key) use ($optionCollection, $selectionCollection) {
$resultValue = $selectionCollection;
break;
case '_cache_instance_used_selections_ids':
$resultValue = [2, 5, 14];
$resultValue = [5];
break;
}

Expand All @@ -856,7 +856,7 @@ function ($key) use ($optionCollection, $selectionCollection) {
->method('setStoreFilter');
$buyRequest->expects($this->once())
->method('getBundleOption')
->willReturn([3 => 5, 10 => [7 => 2, 11 => 14]]);
->willReturn([3 => 5]);
$selectionCollection->expects($this->any())
->method('getItems')
->willReturn([$selection]);
Expand Down Expand Up @@ -885,13 +885,13 @@ function ($key) use ($optionCollection, $selectionCollection) {
->willReturn($productType);
$option->expects($this->at(3))
->method('getId')
->willReturn(10);
->willReturn(3);
$option->expects($this->at(9))
->method('getId')
->willReturn(10);
->willReturn(3);
$option->expects($this->once())
->method('getRequired')
->willReturn(true);
->willReturn(false);
$option->expects($this->once())
->method('isMultiSelection')
->willReturn(true);
Expand Down Expand Up @@ -1118,41 +1118,29 @@ function ($key) use ($optionCollection, $selectionCollection) {
$resultValue = $selectionCollection;
break;
case '_cache_instance_used_selections_ids':
$resultValue = [2, 5, 14];
$resultValue = [5];
break;
}

return $resultValue;
}
);
$optionCollection->expects($this->once())
->method('getItemById')
->willReturn($option);
$optionCollection->expects($this->once())
->method('appendSelections');
$productType->expects($this->once())
->method('setStoreFilter');
$buyRequest->expects($this->once())
->method('getBundleOption')
->willReturn([3 => 5, 10 => [7 => 2, 11 => 14]]);
->willReturn([3 => 5]);
$selectionCollection->expects($this->at(0))
->method('getItems')
->willReturn([$selection]);
$selectionCollection->expects($this->at(1))
->method('getItems')
->willReturn([]);
$selection->expects($this->once())
->method('isSalable')
->willReturn(false);
$option->expects($this->at(3))
$option->expects($this->any())
->method('getId')
->willReturn(10);
$option->expects($this->once())
->method('getRequired')
->willReturn(true);
$option->expects($this->once())
->method('isMultiSelection')
->willReturn(true);
->willReturn(3);

$result = $this->model->prepareForCartAdvanced($buyRequest, $product);
$this->assertEquals('Please specify product option(s).', $result);
Expand Down Expand Up @@ -1262,7 +1250,7 @@ function ($key) use ($optionCollection, $selectionCollection) {
$buyRequest->expects($this->once())
->method('getBundleOption')
->willReturn([3 => 5]);
$selectionCollection->expects($this->once())
$selectionCollection->expects($this->any())
->method('getItems')
->willReturn([$selection]);
$selection->expects($this->once())
Expand Down Expand Up @@ -1921,8 +1909,7 @@ public function testGetSelectionsByIds()
'setPositionOrder',
'addFilterByRequiredOptions',
'setSelectionIdsFilter',
'joinPrices',
'getItems'
'joinPrices'
]
)
->disableOriginalConstructor()
Expand Down Expand Up @@ -1991,9 +1978,6 @@ public function testGetSelectionsByIds()
->method('setSelectionIdsFilter')
->with($selectionIds)
->will($this->returnSelf());
$usedSelectionsMock->expects($this->once())
->method('getItems')
->willReturn($usedSelectionsIds);

$usedSelectionsMock->expects($this->once())
->method('joinPrices')
Expand All @@ -2007,96 +1991,6 @@ public function testGetSelectionsByIds()
$this->model->getSelectionsByIds($selectionIds, $productMock);
}

/**
* @expectedException \Magento\Framework\Exception\LocalizedException
* @expectedExceptionMessage The options you selected are not available.
*
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
public function testGetSelectionsByIdsException()
{
$selectionIds = [1, 2, 3];
$usedSelectionsIds = [4, 5];
$storeId = 2;
$storeFilter = 'store_filter';
$productMock = $this->getMockBuilder('Magento\Catalog\Model\Product')
->disableOriginalConstructor()
->getMock();
$usedSelectionsMock = $this->getMockBuilder('Magento\Bundle\Model\ResourceModel\Selection\Collection')
->setMethods(
[
'addAttributeToSelect',
'setFlag',
'addStoreFilter',
'setStoreId',
'setPositionOrder',
'addFilterByRequiredOptions',
'setSelectionIdsFilter',
'joinPrices',
'getItems'
]
)
->disableOriginalConstructor()
->getMock();
$productGetMap = [
['_cache_instance_used_selections', null, null],
['_cache_instance_used_selections_ids', null, $usedSelectionsIds],
['_cache_instance_store_filter', null, $storeFilter],
];
$productMock->expects($this->any())
->method('getData')
->will($this->returnValueMap($productGetMap));
$productSetMap = [
['_cache_instance_used_selections', $usedSelectionsMock, $productMock],
['_cache_instance_used_selections_ids', $selectionIds, $productMock],
];
$productMock->expects($this->any())
->method('setData')
->will($this->returnValueMap($productSetMap));
$productMock->expects($this->once())
->method('getStoreId')
->will($this->returnValue($storeId));

$this->bundleCollection->expects($this->once())
->method('create')
->will($this->returnValue($usedSelectionsMock));

$usedSelectionsMock->expects($this->once())
->method('addAttributeToSelect')
->with('*')
->will($this->returnSelf());
$flagMap = [
['require_stock_items', true, $usedSelectionsMock],
['product_children', true, $usedSelectionsMock],
];
$usedSelectionsMock->expects($this->any())
->method('setFlag')
->will($this->returnValueMap($flagMap));
$usedSelectionsMock->expects($this->once())
->method('addStoreFilter')
->with($storeFilter)
->will($this->returnSelf());
$usedSelectionsMock->expects($this->once())
->method('setStoreId')
->with($storeId)
->will($this->returnSelf());
$usedSelectionsMock->expects($this->once())
->method('setPositionOrder')
->will($this->returnSelf());
$usedSelectionsMock->expects($this->once())
->method('addFilterByRequiredOptions')
->will($this->returnSelf());
$usedSelectionsMock->expects($this->once())
->method('setSelectionIdsFilter')
->with($selectionIds)
->will($this->returnSelf());
$usedSelectionsMock->expects($this->once())
->method('getItems')
->willReturn($usedSelectionsIds);


$this->model->getSelectionsByIds($selectionIds, $productMock);
}
/**
* @return void
*/
Expand Down
1 change: 1 addition & 0 deletions app/code/Magento/Checkout/Block/Cart/LayoutProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ public function process($jsLayout)
$fieldSetPointer = &$jsLayout['components']['block-summary']['children']['block-shipping']
['children']['address-fieldsets']['children'];
$fieldSetPointer = $this->merger->merge($elements, 'checkoutProvider', 'shippingAddress', $fieldSetPointer);
$fieldSetPointer['region_id']['config']['skipValidation'] = true;
}
return $jsLayout;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
namespace Magento\Checkout\Model;

use Magento\Quote\Api\CartRepositoryInterface;
use Magento\Framework\Exception\CouldNotSaveException;

class GuestPaymentInformationManagement implements \Magento\Checkout\Api\GuestPaymentInformationManagementInterface
{
Expand Down Expand Up @@ -76,7 +77,12 @@ public function savePaymentInformationAndPlaceOrder(
\Magento\Quote\Api\Data\AddressInterface $billingAddress = null
) {
$this->savePaymentInformation($cartId, $email, $paymentMethod, $billingAddress);
return $this->cartManagement->placeOrder($cartId);
try {
$orderId = $this->cartManagement->placeOrder($cartId);
} catch (\Exception $e) {
throw new CouldNotSaveException(__('Cannot place order'), $e);
}
return $orderId;
}

/**
Expand Down
11 changes: 8 additions & 3 deletions app/code/Magento/Checkout/Model/PaymentInformationManagement.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
* Copyright © 2015 Magento. All rights reserved.
* See COPYING.txt for license details.
*/

namespace Magento\Checkout\Model;

use Magento\Framework\Exception\CouldNotSaveException;

class PaymentInformationManagement implements \Magento\Checkout\Api\PaymentInformationManagementInterface
{

/**
* @var \Magento\Quote\Api\BillingAddressManagementInterface
*/
Expand Down Expand Up @@ -67,7 +67,12 @@ public function savePaymentInformationAndPlaceOrder(
\Magento\Quote\Api\Data\AddressInterface $billingAddress = null
) {
$this->savePaymentInformation($cartId, $paymentMethod, $billingAddress);
return $this->cartManagement->placeOrder($cartId);
try {
$orderId = $this->cartManagement->placeOrder($cartId);
} catch (\Exception $e) {
throw new CouldNotSaveException(__('Cannot place order'), $e);
}
return $orderId;
}

/**
Expand Down
Loading

0 comments on commit dab098e

Please sign in to comment.