Skip to content

Commit

Permalink
Merge pull request #480 from magento-fearless-kiwis/pull_request_2.0.11
Browse files Browse the repository at this point in the history
Fixed issues:
 - MAGETWO-59102 Bundle Products - The options you selected are not available
 - MAGETWO-58035 [Backport] - Configurable product options not saved when editing
  • Loading branch information
Oleksii Korshenko authored Oct 7, 2016
2 parents 048569a + 4f71645 commit 3376129
Show file tree
Hide file tree
Showing 18 changed files with 349 additions and 164 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 @@ -716,6 +716,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 @@ -888,12 +894,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
148 changes: 21 additions & 127 deletions app/code/Magento/Bundle/Test/Unit/Model/Product/TypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ function ($key) use ($optionCollection, $selectionCollection) {
$resultValue = $selectionCollection;
break;
case '_cache_instance_used_selections_ids':
$resultValue = [2, 5, 14];
$resultValue = [5];
break;
}

Expand All @@ -402,7 +402,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 @@ -431,13 +431,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 @@ -608,7 +608,7 @@ function ($key) use ($optionCollection, $selectionCollection) {
$resultValue = $selectionCollection;
break;
case '_cache_instance_used_selections_ids':
$resultValue = [2, 5, 14];
$resultValue = [5];
break;
}

Expand All @@ -633,7 +633,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 @@ -662,13 +662,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 @@ -827,7 +827,7 @@ function ($key) use ($optionCollection, $selectionCollection) {
$resultValue = $selectionCollection;
break;
case '_cache_instance_used_selections_ids':
$resultValue = [2, 5, 14];
$resultValue = [5];
break;
}

Expand All @@ -852,7 +852,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 @@ -881,13 +881,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 @@ -1112,41 +1112,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 @@ -1255,7 +1243,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 @@ -1901,8 +1889,7 @@ public function testGetSelectionsByIds()
'setPositionOrder',
'addFilterByRequiredOptions',
'setSelectionIdsFilter',
'joinPrices',
'getItems'
'joinPrices'
]
)
->disableOriginalConstructor()
Expand Down Expand Up @@ -1971,9 +1958,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 @@ -1987,96 +1971,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/CustomerData/DefaultItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ protected function doGetItemData()
'item_id' => $this->item->getId(),
'configure_url' => $this->getConfigureUrl(),
'is_visible_in_site_visibility' => $this->item->getProduct()->isVisibleInSiteVisibility(),
'product_id' => $this->item->getProduct()->getId(),
'product_name' => $this->item->getProduct()->getName(),
'product_url' => $this->getProductUrl(),
'product_has_url' => $this->hasProductUrl(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -818,9 +818,15 @@ public function getSelectedAttributesInfo($product)
$value = $value->getSource()->getOptionText($attributeValue);
} else {
$value = '';
$attributeValue = '';
}

$attributes[] = ['label' => $label, 'value' => $value];
$attributes[] = [
'label' => $label,
'value' => $value,
'option_id' => $attributeId,
'option_value' => $attributeValue,
];
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -564,7 +564,14 @@ public function testGetSelectedAttributesInfo()

$this->assertEquals(
$this->_model->getSelectedAttributesInfo($productMock),
[['label' => 'attr_store_label', 'value' => '']]
[
[
'label' => 'attr_store_label',
'value' => '',
'option_id' => 1,
'option_value' => ''
]
]
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
*/
-->
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<head>
<link src="Magento_ConfigurableProduct::js/configurable-customer-data.js"/>
</head>
<update handle="catalog_product_view_type_configurable"/>
<body/>
</page>
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/**
* Copyright © 2016 Magento. All rights reserved.
* See COPYING.txt for license details.
*/

require([
'jquery',
'Magento_ConfigurableProduct/js/options-updater'
], function ($, Updater) {
'use strict';

var selectors = {
formSelector: '#product_addtocart_form'
},
configurableWidgetName = 'mageConfigurable',
widgetInitEvent = 'configurable.initialized',

/**
* Sets all configurable attribute's selected values
*/
updateConfigurableOptions = function () {
var configurableWidget = $(selectors.formSelector).data(configurableWidgetName);

if (!configurableWidget) {
return;
}
configurableWidget.options.values = this.productOptions || {};
configurableWidget._configureForValues();
},
updater = new Updater(widgetInitEvent, updateConfigurableOptions);

updater.listen();
});
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ define([

// Setup/configure values to inputs
this._configureForValues();

$(this.element).trigger('configurable.initialized');
},

/**
Expand Down
Loading

0 comments on commit 3376129

Please sign in to comment.