Skip to content

Commit fc32492

Browse files
author
Bomko, Alex(abomko)
committed
Merge pull request #607 from magento-dragons/PR-4
[Dragons] Bugfixes
2 parents 964f540 + 2680b71 commit fc32492

File tree

30 files changed

+602
-50
lines changed

30 files changed

+602
-50
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,8 +183,9 @@ public function getFinalPrice($qty, $product)
183183
$finalPrice = $this->_applyOptionsPrice($product, $qty, $finalPrice);
184184
$finalPrice += $this->getTotalBundleItemsPrice($product, $qty);
185185

186+
$finalPrice = max(0, $finalPrice);
186187
$product->setFinalPrice($finalPrice);
187-
return max(0, $product->getData('final_price'));
188+
return $finalPrice;
188189
}
189190

190191
/**

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,11 @@ protected function _prepareForm()
7070
}
7171
$this->_coreRegistry->register('attribute_type_hidden_fields', $_hiddenFields);
7272

73-
$this->_eventManager->dispatch('product_attribute_form_build_main_tab', ['form' => $form]);
74-
7573
$frontendInputValues = array_merge($frontendInputElm->getValues(), $additionalTypes);
7674
$frontendInputElm->setValues($frontendInputValues);
7775

76+
$this->_eventManager->dispatch('product_attribute_form_build_main_tab', ['form' => $form]);
77+
7878
return $this;
7979
}
8080

app/code/Magento/Catalog/Controller/Adminhtml/Product/Attribute.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ protected function createActionPage($title = null)
8888
/** @var \Magento\Backend\Model\View\Result\Page $resultPage */
8989
$resultPage = $this->resultPageFactory->create();
9090
if ($this->getRequest()->getParam('popup')) {
91-
if ($this->getRequest()->getParam('product_tab') == 'variations') {
91+
if ($this->getRequest()->getParam('product_tab') === 'variations') {
9292
$resultPage->addHandle(['popup', 'catalog_product_attribute_edit_product_tab_variations_popup']);
9393
} else {
9494
$resultPage->addHandle(['popup', 'catalog_product_attribute_edit_popup']);

app/code/Magento/Catalog/Controller/Adminhtml/Product/Initialization/StockDataFilter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class StockDataFilter
1616
/**
1717
* The greatest value which could be stored in CatalogInventory Qty field
1818
*/
19-
const MAX_QTY_VALUE = 99999999.9999;
19+
const MAX_QTY_VALUE = 99999999;
2020

2121
/**
2222
* @var ScopeConfigInterface

app/code/Magento/Catalog/Model/Product.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -142,11 +142,6 @@ class Product extends \Magento\Catalog\Model\AbstractModel implements
142142
*/
143143
protected $optionInstance;
144144

145-
/**
146-
* @var bool
147-
*/
148-
protected $optionsInitialized = false;
149-
150145
/**
151146
* @var array
152147
*/
@@ -1901,6 +1896,7 @@ public function addOption(Product\Option $option)
19011896
{
19021897
$options = (array)$this->getData('options');
19031898
$options[] = $option;
1899+
$option->setProduct($this);
19041900
$this->setData('options', $options);
19051901
return $this;
19061902
}

app/code/Magento/CatalogInventory/Ui/DataProvider/Product/Form/Modifier/AdvancedInventory.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*/
66
namespace Magento\CatalogInventory\Ui\DataProvider\Product\Form\Modifier;
77

8+
use Magento\Catalog\Controller\Adminhtml\Product\Initialization\StockDataFilter;
89
use Magento\Catalog\Model\Locator\LocatorInterface;
910
use Magento\Catalog\Ui\DataProvider\Product\Form\Modifier\AbstractModifier;
1011
use Magento\CatalogInventory\Api\StockRegistryInterface;
@@ -213,6 +214,7 @@ private function prepareMeta()
213214
'validation' => [
214215
'validate-number' => true,
215216
'validate-digits' => true,
217+
'less-than-equals-to' => StockDataFilter::MAX_QTY_VALUE,
216218
],
217219
'imports' => [
218220
'handleChanges' => '${$.provider}:data.product.stock_data.is_qty_decimal',

app/code/Magento/CatalogInventory/view/adminhtml/ui_component/product_form.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@
9696
<item name="validation" xsi:type="array">
9797
<item name="validate-number" xsi:type="boolean">true</item>
9898
<item name="validate-digits" xsi:type="boolean">true</item>
99+
<item name="less-than-equals-to" xsi:type="number">99999999</item>
99100
</item>
100101
<item name="sortOrder" xsi:type="number">200</item>
101102
<item name="scopeLabel" xsi:type="string">[GLOBAL]</item>

app/code/Magento/CatalogInventory/view/adminhtml/web/js/components/qty-validator-changer.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ define([
2121

2222
this.validation['validate-number'] = !isDigits;
2323
this.validation['validate-digits'] = isDigits;
24+
this.validation['less-than-equals-to'] = isDigits ? 99999999 : 99999999.9999;
2425
this.validate();
2526
}
2627
});

app/code/Magento/CatalogSearch/Model/Layer/Filter/Attribute.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,12 @@ protected function _getItemsData()
8484
->getProductCollection();
8585
$optionsFacetedData = $productCollection->getFacetedData($attribute->getAttributeCode());
8686

87+
if (count($optionsFacetedData) === 0
88+
&& $this->getAttributeIsFilterable($attribute) !== static::ATTRIBUTE_OPTIONS_ONLY_WITH_RESULTS
89+
) {
90+
return $this->itemDataBuilder->build();
91+
}
92+
8793
$productSize = $productCollection->getSize();
8894

8995
$options = $attribute->getFrontend()
@@ -100,9 +106,8 @@ protected function _getItemsData()
100106
: 0;
101107
// Check filter type
102108
if (
103-
$count === 0
104-
&& $this->getAttributeIsFilterable($attribute) === static::ATTRIBUTE_OPTIONS_ONLY_WITH_RESULTS
105-
&& !$this->isOptionReducesResults($count, $productSize)
109+
$this->getAttributeIsFilterable($attribute) === static::ATTRIBUTE_OPTIONS_ONLY_WITH_RESULTS
110+
&& (!$this->isOptionReducesResults($count, $productSize) || $count === 0)
106111
) {
107112
continue;
108113
}

app/code/Magento/CatalogSearch/Model/ResourceModel/Fulltext/Collection.php

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*/
66
namespace Magento\CatalogSearch\Model\ResourceModel\Fulltext;
77

8+
use Magento\CatalogSearch\Model\Search\RequestGenerator;
89
use Magento\Framework\DB\Select;
910
use Magento\Framework\Exception\StateException;
1011
use Magento\Framework\Search\Adapter\Mysql\TemporaryStorage;
@@ -398,14 +399,17 @@ public function getFacetedData($field)
398399
$this->_renderFilters();
399400
$result = [];
400401
$aggregations = $this->searchResult->getAggregations();
401-
$bucket = $aggregations->getBucket($field . '_bucket');
402-
if ($bucket) {
403-
foreach ($bucket->getValues() as $value) {
404-
$metrics = $value->getMetrics();
405-
$result[$metrics['value']] = $metrics;
402+
// This behavior is for case with empty object when we got EmptyRequestDataException
403+
if (null !== $aggregations) {
404+
$bucket = $aggregations->getBucket($field . RequestGenerator::BUCKET_SUFFIX);
405+
if ($bucket) {
406+
foreach ($bucket->getValues() as $value) {
407+
$metrics = $value->getMetrics();
408+
$result[$metrics['value']] = $metrics;
409+
}
410+
} else {
411+
throw new StateException(__('Bucket does not exist'));
406412
}
407-
} else {
408-
throw new StateException(__('Bucket do not exists'));
409413
}
410414
return $result;
411415
}

app/code/Magento/CatalogSearch/Model/Search/TableMapper.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717
use Magento\Framework\Search\Request\QueryInterface as RequestQueryInterface;
1818
use Magento\Store\Model\StoreManagerInterface;
1919

20+
/**
21+
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
22+
*/
2023
class TableMapper
2124
{
2225
/**
@@ -108,7 +111,7 @@ private function getMappingData(FilterInterface $filter)
108111
&& in_array($attribute->getFrontendInput(), ['select', 'multiselect'], true)
109112
) {
110113
$table = $this->resource->getTableName('catalog_product_index_eav');
111-
$alias = $field . '_filter';
114+
$alias = $field . RequestGenerator::FILTER_SUFFIX;
112115
$mapOn = sprintf(
113116
'search_index.entity_id = %1$s.entity_id AND %1$s.attribute_id = %2$d AND %1$s.store_id = %3$d',
114117
$alias,
@@ -118,7 +121,7 @@ private function getMappingData(FilterInterface $filter)
118121
$mappedFields = [];
119122
} elseif ($attribute->getBackendType() === AbstractAttribute::TYPE_STATIC) {
120123
$table = $attribute->getBackendTable();
121-
$alias = $field . '_filter';
124+
$alias = $field . RequestGenerator::FILTER_SUFFIX;
122125
$mapOn = 'search_index.entity_id = ' . $alias . '.entity_id';
123126
$mappedFields = null;
124127
}

app/code/Magento/CatalogSearch/Test/Unit/Model/Layer/Filter/AttributeTest.php

Lines changed: 109 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
namespace Magento\CatalogSearch\Test\Unit\Model\Layer\Filter;
88

9+
use Magento\Catalog\Model\Layer\Filter\AbstractFilter;
910
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper;
1011
use PHPUnit_Framework_MockObject_MockObject as MockObject;
1112

@@ -104,9 +105,6 @@ protected function setUp()
104105
->disableOriginalConstructor()
105106
->setMethods(['getAttributeCode', 'getFrontend', 'getIsFilterable'])
106107
->getMock();
107-
$this->attribute->expects($this->atLeastOnce())
108-
->method('getFrontend')
109-
->will($this->returnValue($this->frontend));
110108

111109
$this->request = $this->getMockBuilder('\Magento\Framework\App\RequestInterface')
112110
->setMethods(['getParam'])
@@ -143,6 +141,9 @@ public function testApplyFilter()
143141
$this->attribute->expects($this->exactly(2))
144142
->method('getAttributeCode')
145143
->will($this->returnValue($attributeCode));
144+
$this->attribute->expects($this->atLeastOnce())
145+
->method('getFrontend')
146+
->will($this->returnValue($this->frontend));
146147

147148
$this->target->setAttributeModel($this->attribute);
148149

@@ -202,6 +203,9 @@ public function testGetItemsWithApply()
202203
$this->attribute->expects($this->exactly(2))
203204
->method('getAttributeCode')
204205
->will($this->returnValue($attributeCode));
206+
$this->attribute->expects($this->atLeastOnce())
207+
->method('getFrontend')
208+
->will($this->returnValue($this->frontend));
205209

206210
$this->target->setAttributeModel($this->attribute);
207211

@@ -283,6 +287,9 @@ public function testGetItemsWithoutApply()
283287
$this->attribute->expects($this->exactly(2))
284288
->method('getAttributeCode')
285289
->will($this->returnValue($attributeCode));
290+
$this->attribute->expects($this->atLeastOnce())
291+
->method('getFrontend')
292+
->will($this->returnValue($this->frontend));
286293

287294
$this->target->setAttributeModel($this->attribute);
288295

@@ -329,6 +336,105 @@ public function testGetItemsWithoutApply()
329336
$this->assertEquals($expectedFilterItems, $result);
330337
}
331338

339+
/**
340+
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
341+
*/
342+
public function testGetItemsOnlyWithResults()
343+
{
344+
$attributeCode = 'attributeCode';
345+
$selectedOptions = [
346+
[
347+
'label' => 'selectedOptionLabel1',
348+
'value' => 'selectedOptionValue1',
349+
],
350+
[
351+
'label' => 'selectedOptionLabel2',
352+
'value' => 'selectedOptionValue2',
353+
],
354+
];
355+
$facetedData = [
356+
'selectedOptionValue1' => ['count' => 10],
357+
'selectedOptionValue2' => ['count' => 0],
358+
];
359+
$builtData = [
360+
[
361+
'label' => $selectedOptions[0]['label'],
362+
'value' => $selectedOptions[0]['value'],
363+
'count' => $facetedData[$selectedOptions[0]['value']]['count'],
364+
],
365+
];
366+
367+
$this->attribute->expects($this->atLeastOnce())
368+
->method('getAttributeCode')
369+
->willReturn($attributeCode);
370+
$this->attribute->expects($this->atLeastOnce())
371+
->method('getIsFilterable')
372+
->willReturn(AbstractFilter::ATTRIBUTE_OPTIONS_ONLY_WITH_RESULTS);
373+
$this->attribute->expects($this->atLeastOnce())
374+
->method('getFrontend')
375+
->will($this->returnValue($this->frontend));
376+
377+
$this->target->setAttributeModel($this->attribute);
378+
379+
$this->frontend->expects($this->once())
380+
->method('getSelectOptions')
381+
->willReturn($selectedOptions);
382+
383+
$this->fulltextCollection->expects($this->once())
384+
->method('getFacetedData')
385+
->willReturn($facetedData);
386+
$this->fulltextCollection->expects($this->once())
387+
->method('getSize')
388+
->will($this->returnValue(50));
389+
390+
$this->itemDataBuilder->expects($this->once())
391+
->method('addItemData')
392+
->with(
393+
$selectedOptions[0]['label'],
394+
$selectedOptions[0]['value'],
395+
$facetedData[$selectedOptions[0]['value']]['count']
396+
)
397+
->will($this->returnSelf());
398+
399+
$this->itemDataBuilder->expects($this->once())
400+
->method('build')
401+
->willReturn($builtData);
402+
403+
$expectedFilterItems = [
404+
$this->createFilterItem(0, $builtData[0]['label'], $builtData[0]['value'], $builtData[0]['count']),
405+
];
406+
$result = $this->target->getItems();
407+
408+
$this->assertEquals($expectedFilterItems, $result);
409+
}
410+
411+
/**
412+
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
413+
*/
414+
public function testGetItemsIfFacetedDataIsEmpty()
415+
{
416+
$attributeCode = 'attributeCode';
417+
418+
$this->attribute->expects($this->atLeastOnce())
419+
->method('getAttributeCode')
420+
->willReturn($attributeCode);
421+
$this->attribute->expects($this->atLeastOnce())
422+
->method('getIsFilterable')
423+
->willReturn(0);
424+
425+
$this->target->setAttributeModel($this->attribute);
426+
427+
$this->fulltextCollection->expects($this->once())
428+
->method('getFacetedData')
429+
->willReturn([]);
430+
431+
$this->itemDataBuilder->expects($this->once())
432+
->method('build')
433+
->willReturn([]);
434+
435+
$this->assertEquals([], $this->target->getItems());
436+
}
437+
332438
/**
333439
* @param int $index
334440
* @param string $label

0 commit comments

Comments
 (0)