Skip to content

Commit 91f33ac

Browse files
author
Maksym Aposov
committed
Merge remote-tracking branch 'mainline/develop' into MAGETWO-44516
2 parents 29e5e06 + 1f0b802 commit 91f33ac

File tree

163 files changed

+1137
-538
lines changed

Some content is hidden

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

163 files changed

+1137
-538
lines changed

app/code/Magento/Bundle/Model/Product/Price.php

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,8 @@ public function getTotalBundleItemsPrice($product, $qty = null)
118118
{
119119
$price = 0.0;
120120
if ($product->hasCustomOptions()) {
121-
$customOption = $product->getCustomOption('bundle_selection_ids');
122-
if ($customOption) {
123-
$selectionIds = unserialize($customOption->getValue());
121+
$selectionIds = $this->getBundleSelectionIds($product);
122+
if ($selectionIds) {
124123
$selections = $product->getTypeInstance()->getSelectionsByIds($selectionIds, $product);
125124
$selections->addTierPriceData();
126125
$this->_eventManager->dispatch(
@@ -145,6 +144,24 @@ public function getTotalBundleItemsPrice($product, $qty = null)
145144
return $price;
146145
}
147146

147+
/**
148+
* Retrieve array of bundle selection IDs
149+
*
150+
* @param \Magento\Catalog\Model\Product $product
151+
* @return array
152+
*/
153+
protected function getBundleSelectionIds(\Magento\Catalog\Model\Product $product)
154+
{
155+
$customOption = $product->getCustomOption('bundle_selection_ids');
156+
if ($customOption) {
157+
$selectionIds = unserialize($customOption->getValue());
158+
if (!empty($selectionIds) && is_array($selectionIds)) {
159+
return $selectionIds;
160+
}
161+
}
162+
return [];
163+
}
164+
148165
/**
149166
* Get product final price
150167
*

app/code/Magento/Bundle/Test/Unit/Model/Product/PriceTest.php

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,4 +146,121 @@ public function calculateSpecialPrice()
146146
[10, 100, 1, true, 10],
147147
];
148148
}
149+
150+
public function testGetTotalBundleItemsPriceWithNoCustomOptions()
151+
{
152+
$productMock = $this->getMockBuilder('Magento\Catalog\Model\Product')
153+
->disableOriginalConstructor()
154+
->getMock();
155+
156+
$productMock->expects($this->once())
157+
->method('hasCustomOptions')
158+
->willReturn(false);
159+
160+
$this->assertEquals(0, $this->model->getTotalBundleItemsPrice($productMock));
161+
}
162+
163+
/**
164+
* @param string|null $value
165+
* @dataProvider dataProviderWithEmptyOptions
166+
*/
167+
public function testGetTotalBundleItemsPriceWithEmptyOptions($value)
168+
{
169+
$dataObjectMock = $this->getMockBuilder('Magento\Framework\DataObject')
170+
->setMethods(['getValue'])
171+
->disableOriginalConstructor()
172+
->getMock();
173+
174+
$productMock = $this->getMockBuilder('Magento\Catalog\Model\Product')
175+
->disableOriginalConstructor()
176+
->getMock();
177+
178+
$productMock->expects($this->once())
179+
->method('hasCustomOptions')
180+
->willReturn(true);
181+
$productMock->expects($this->once())
182+
->method('getCustomOption')
183+
->with('bundle_selection_ids')
184+
->willReturn($dataObjectMock);
185+
186+
$dataObjectMock->expects($this->once())
187+
->method('getValue')
188+
->willReturn($value);
189+
190+
$this->assertEquals(0, $this->model->getTotalBundleItemsPrice($productMock));
191+
}
192+
193+
/**
194+
* @return array
195+
*/
196+
public function dataProviderWithEmptyOptions()
197+
{
198+
return [
199+
['a:0:{}'],
200+
[''],
201+
[null],
202+
];
203+
}
204+
205+
public function testGetTotalBundleItemsPriceWithNoItems()
206+
{
207+
$storeId = 1;
208+
209+
$dataObjectMock = $this->getMockBuilder('Magento\Framework\DataObject')
210+
->setMethods(['getValue'])
211+
->disableOriginalConstructor()
212+
->getMock();
213+
214+
$productMock = $this->getMockBuilder('Magento\Catalog\Model\Product')
215+
->disableOriginalConstructor()
216+
->getMock();
217+
218+
$productTypeMock = $this->getMockBuilder('Magento\Bundle\Model\Product\Type')
219+
->disableOriginalConstructor()
220+
->getMock();
221+
222+
$selectionsMock = $this->getMockBuilder('Magento\Bundle\Model\ResourceModel\Selection\Collection')
223+
->disableOriginalConstructor()
224+
->getMock();
225+
226+
$productMock->expects($this->once())
227+
->method('hasCustomOptions')
228+
->willReturn(true);
229+
$productMock->expects($this->once())
230+
->method('getCustomOption')
231+
->with('bundle_selection_ids')
232+
->willReturn($dataObjectMock);
233+
$productMock->expects($this->once())
234+
->method('getTypeInstance')
235+
->willReturn($productTypeMock);
236+
$productMock->expects($this->once())
237+
->method('getStoreId')
238+
->willReturn($storeId);
239+
240+
$dataObjectMock->expects($this->once())
241+
->method('getValue')
242+
->willReturn('a:1:{i:0;s:1:"1";}');
243+
244+
$productTypeMock->expects($this->once())
245+
->method('getSelectionsByIds')
246+
->with([1], $productMock)
247+
->willReturn($selectionsMock);
248+
249+
$selectionsMock->expects($this->once())
250+
->method('addTierPriceData')
251+
->willReturnSelf();
252+
$selectionsMock->expects($this->once())
253+
->method('getItems')
254+
->willReturn([]);
255+
256+
$this->eventManagerMock->expects($this->once())
257+
->method('dispatch')
258+
->with(
259+
'prepare_catalog_product_collection_prices',
260+
['collection' => $selectionsMock, 'store_id' => $storeId]
261+
)
262+
->willReturnSelf();
263+
264+
$this->assertEquals(0, $this->model->getTotalBundleItemsPrice($productMock));
265+
}
149266
}

app/code/Magento/Catalog/Block/Adminhtml/Product/Attribute/Edit.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,9 @@ protected function _construct()
5454
$this->addButton(
5555
'save_in_new_set',
5656
[
57-
'label' => __('Save in New Product Template'),
57+
'label' => __('Save in New Attribute Set'),
5858
'class' => 'save',
59-
'onclick' => 'saveAttributeInNewSet(\'' . __('Enter Name for New Product Template') . '\')'
59+
'onclick' => 'saveAttributeInNewSet(\'' . __('Enter Name for New Attribute Set') . '\')'
6060
],
6161
100
6262
);

app/code/Magento/Catalog/Block/Adminhtml/Product/Attribute/Set/Main.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ protected function _prepareLayout()
129129
'label' => __('Delete'),
130130
'onclick' => 'deleteConfirm(\'' . $this->escapeJsQuote(
131131
__(
132-
'You are about to delete all products in this product template. '
132+
'You are about to delete all products in this attribute set. '
133133
. 'Are you sure you want to do that?'
134134
)
135135
) . '\', \'' . $this->getUrl(
@@ -187,7 +187,7 @@ public function getSetFormHtml()
187187
*/
188188
protected function _getHeader()
189189
{
190-
return __("Edit Product Template '%1'", $this->_getAttributeSet()->getAttributeSetName());
190+
return __("Edit Attribute Set '%1'", $this->_getAttributeSet()->getAttributeSetName());
191191
}
192192

193193
/**

app/code/Magento/Catalog/Block/Adminhtml/Product/Attribute/Set/Main/Formset.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ protected function _prepareForm()
4343

4444
/** @var \Magento\Framework\Data\Form $form */
4545
$form = $this->_formFactory->create();
46-
$fieldset = $form->addFieldset('set_name', ['legend' => __('Edit Product Template Name')]);
46+
$fieldset = $form->addFieldset('set_name', ['legend' => __('Edit Attribute Set Name')]);
4747
$fieldset->addField(
4848
'attribute_set_name',
4949
'text',

app/code/Magento/Catalog/Block/Adminhtml/Product/Attribute/Set/Toolbar/Add.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ protected function _prepareLayout()
5757
*/
5858
protected function _getHeader()
5959
{
60-
return __('Add New Product Template');
60+
return __('Add New Attribute Set');
6161
}
6262

6363
/**

app/code/Magento/Catalog/Block/Adminhtml/Product/Attribute/Set/Toolbar/Main.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ protected function _prepareLayout()
2727
'addButton',
2828
'Magento\Backend\Block\Widget\Button',
2929
[
30-
'label' => __('Add Product Template'),
30+
'label' => __('Add Attribute Set'),
3131
'onclick' => 'setLocation(\'' . $this->getUrl('catalog/*/add') . '\')',
3232
'class' => 'add primary add-set'
3333
]
@@ -48,7 +48,7 @@ public function getNewButtonHtml()
4848
*/
4949
protected function _getHeader()
5050
{
51-
return __('Product Templates');
51+
return __('Attribute Sets');
5252
}
5353

5454
/**

app/code/Magento/Catalog/Block/Adminhtml/Product/Edit/AttributeSet.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public function __construct(
4242
public function getSelectorOptions()
4343
{
4444
return [
45-
'source' => $this->getUrl('catalog/product/suggestProductTemplates'),
45+
'source' => $this->getUrl('catalog/product/suggestAttributeSets'),
4646
'className' => 'category-select',
4747
'showRecent' => true,
4848
'storageKey' => 'product-template-key',

app/code/Magento/Catalog/Block/Adminhtml/Product/Edit/Tab/Crosssell.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ protected function _prepareColumns()
249249
$this->addColumn(
250250
'set_name',
251251
[
252-
'header' => __('Product Template'),
252+
'header' => __('Attribute Set'),
253253
'index' => 'attribute_set_id',
254254
'type' => 'options',
255255
'options' => $sets,

app/code/Magento/Catalog/Block/Adminhtml/Product/Edit/Tab/Related.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ protected function _prepareColumns()
243243
$this->addColumn(
244244
'set_name',
245245
[
246-
'header' => __('Product Template'),
246+
'header' => __('Attribute Set'),
247247
'index' => 'attribute_set_id',
248248
'type' => 'options',
249249
'options' => $sets,

0 commit comments

Comments
 (0)