Skip to content

Commit

Permalink
Merge pull request #607 from magento-dragons/PR-4
Browse files Browse the repository at this point in the history
[Dragons] Bugfixes
  • Loading branch information
Bomko, Alex(abomko) committed May 12, 2016
2 parents 964f540 + 2680b71 commit fc32492
Show file tree
Hide file tree
Showing 30 changed files with 602 additions and 50 deletions.
3 changes: 2 additions & 1 deletion app/code/Magento/Bundle/Model/Product/Price.php
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,9 @@ public function getFinalPrice($qty, $product)
$finalPrice = $this->_applyOptionsPrice($product, $qty, $finalPrice);
$finalPrice += $this->getTotalBundleItemsPrice($product, $qty);

$finalPrice = max(0, $finalPrice);
$product->setFinalPrice($finalPrice);
return max(0, $product->getData('final_price'));
return $finalPrice;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,11 @@ protected function _prepareForm()
}
$this->_coreRegistry->register('attribute_type_hidden_fields', $_hiddenFields);

$this->_eventManager->dispatch('product_attribute_form_build_main_tab', ['form' => $form]);

$frontendInputValues = array_merge($frontendInputElm->getValues(), $additionalTypes);
$frontendInputElm->setValues($frontendInputValues);

$this->_eventManager->dispatch('product_attribute_form_build_main_tab', ['form' => $form]);

return $this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ protected function createActionPage($title = null)
/** @var \Magento\Backend\Model\View\Result\Page $resultPage */
$resultPage = $this->resultPageFactory->create();
if ($this->getRequest()->getParam('popup')) {
if ($this->getRequest()->getParam('product_tab') == 'variations') {
if ($this->getRequest()->getParam('product_tab') === 'variations') {
$resultPage->addHandle(['popup', 'catalog_product_attribute_edit_product_tab_variations_popup']);
} else {
$resultPage->addHandle(['popup', 'catalog_product_attribute_edit_popup']);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class StockDataFilter
/**
* The greatest value which could be stored in CatalogInventory Qty field
*/
const MAX_QTY_VALUE = 99999999.9999;
const MAX_QTY_VALUE = 99999999;

/**
* @var ScopeConfigInterface
Expand Down
6 changes: 1 addition & 5 deletions app/code/Magento/Catalog/Model/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,11 +142,6 @@ class Product extends \Magento\Catalog\Model\AbstractModel implements
*/
protected $optionInstance;

/**
* @var bool
*/
protected $optionsInitialized = false;

/**
* @var array
*/
Expand Down Expand Up @@ -1901,6 +1896,7 @@ public function addOption(Product\Option $option)
{
$options = (array)$this->getData('options');
$options[] = $option;
$option->setProduct($this);
$this->setData('options', $options);
return $this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/
namespace Magento\CatalogInventory\Ui\DataProvider\Product\Form\Modifier;

use Magento\Catalog\Controller\Adminhtml\Product\Initialization\StockDataFilter;
use Magento\Catalog\Model\Locator\LocatorInterface;
use Magento\Catalog\Ui\DataProvider\Product\Form\Modifier\AbstractModifier;
use Magento\CatalogInventory\Api\StockRegistryInterface;
Expand Down Expand Up @@ -213,6 +214,7 @@ private function prepareMeta()
'validation' => [
'validate-number' => true,
'validate-digits' => true,
'less-than-equals-to' => StockDataFilter::MAX_QTY_VALUE,
],
'imports' => [
'handleChanges' => '${$.provider}:data.product.stock_data.is_qty_decimal',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@
<item name="validation" xsi:type="array">
<item name="validate-number" xsi:type="boolean">true</item>
<item name="validate-digits" xsi:type="boolean">true</item>
<item name="less-than-equals-to" xsi:type="number">99999999</item>
</item>
<item name="sortOrder" xsi:type="number">200</item>
<item name="scopeLabel" xsi:type="string">[GLOBAL]</item>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ define([

this.validation['validate-number'] = !isDigits;
this.validation['validate-digits'] = isDigits;
this.validation['less-than-equals-to'] = isDigits ? 99999999 : 99999999.9999;
this.validate();
}
});
Expand Down
11 changes: 8 additions & 3 deletions app/code/Magento/CatalogSearch/Model/Layer/Filter/Attribute.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,12 @@ protected function _getItemsData()
->getProductCollection();
$optionsFacetedData = $productCollection->getFacetedData($attribute->getAttributeCode());

if (count($optionsFacetedData) === 0
&& $this->getAttributeIsFilterable($attribute) !== static::ATTRIBUTE_OPTIONS_ONLY_WITH_RESULTS
) {
return $this->itemDataBuilder->build();
}

$productSize = $productCollection->getSize();

$options = $attribute->getFrontend()
Expand All @@ -100,9 +106,8 @@ protected function _getItemsData()
: 0;
// Check filter type
if (
$count === 0
&& $this->getAttributeIsFilterable($attribute) === static::ATTRIBUTE_OPTIONS_ONLY_WITH_RESULTS
&& !$this->isOptionReducesResults($count, $productSize)
$this->getAttributeIsFilterable($attribute) === static::ATTRIBUTE_OPTIONS_ONLY_WITH_RESULTS
&& (!$this->isOptionReducesResults($count, $productSize) || $count === 0)
) {
continue;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/
namespace Magento\CatalogSearch\Model\ResourceModel\Fulltext;

use Magento\CatalogSearch\Model\Search\RequestGenerator;
use Magento\Framework\DB\Select;
use Magento\Framework\Exception\StateException;
use Magento\Framework\Search\Adapter\Mysql\TemporaryStorage;
Expand Down Expand Up @@ -398,14 +399,17 @@ public function getFacetedData($field)
$this->_renderFilters();
$result = [];
$aggregations = $this->searchResult->getAggregations();
$bucket = $aggregations->getBucket($field . '_bucket');
if ($bucket) {
foreach ($bucket->getValues() as $value) {
$metrics = $value->getMetrics();
$result[$metrics['value']] = $metrics;
// This behavior is for case with empty object when we got EmptyRequestDataException
if (null !== $aggregations) {
$bucket = $aggregations->getBucket($field . RequestGenerator::BUCKET_SUFFIX);
if ($bucket) {
foreach ($bucket->getValues() as $value) {
$metrics = $value->getMetrics();
$result[$metrics['value']] = $metrics;
}
} else {
throw new StateException(__('Bucket does not exist'));
}
} else {
throw new StateException(__('Bucket do not exists'));
}
return $result;
}
Expand Down
7 changes: 5 additions & 2 deletions app/code/Magento/CatalogSearch/Model/Search/TableMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
use Magento\Framework\Search\Request\QueryInterface as RequestQueryInterface;
use Magento\Store\Model\StoreManagerInterface;

/**
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*/
class TableMapper
{
/**
Expand Down Expand Up @@ -108,7 +111,7 @@ private function getMappingData(FilterInterface $filter)
&& in_array($attribute->getFrontendInput(), ['select', 'multiselect'], true)
) {
$table = $this->resource->getTableName('catalog_product_index_eav');
$alias = $field . '_filter';
$alias = $field . RequestGenerator::FILTER_SUFFIX;
$mapOn = sprintf(
'search_index.entity_id = %1$s.entity_id AND %1$s.attribute_id = %2$d AND %1$s.store_id = %3$d',
$alias,
Expand All @@ -118,7 +121,7 @@ private function getMappingData(FilterInterface $filter)
$mappedFields = [];
} elseif ($attribute->getBackendType() === AbstractAttribute::TYPE_STATIC) {
$table = $attribute->getBackendTable();
$alias = $field . '_filter';
$alias = $field . RequestGenerator::FILTER_SUFFIX;
$mapOn = 'search_index.entity_id = ' . $alias . '.entity_id';
$mappedFields = null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

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

use Magento\Catalog\Model\Layer\Filter\AbstractFilter;
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper;
use PHPUnit_Framework_MockObject_MockObject as MockObject;

Expand Down Expand Up @@ -104,9 +105,6 @@ protected function setUp()
->disableOriginalConstructor()
->setMethods(['getAttributeCode', 'getFrontend', 'getIsFilterable'])
->getMock();
$this->attribute->expects($this->atLeastOnce())
->method('getFrontend')
->will($this->returnValue($this->frontend));

$this->request = $this->getMockBuilder('\Magento\Framework\App\RequestInterface')
->setMethods(['getParam'])
Expand Down Expand Up @@ -143,6 +141,9 @@ public function testApplyFilter()
$this->attribute->expects($this->exactly(2))
->method('getAttributeCode')
->will($this->returnValue($attributeCode));
$this->attribute->expects($this->atLeastOnce())
->method('getFrontend')
->will($this->returnValue($this->frontend));

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

Expand Down Expand Up @@ -202,6 +203,9 @@ public function testGetItemsWithApply()
$this->attribute->expects($this->exactly(2))
->method('getAttributeCode')
->will($this->returnValue($attributeCode));
$this->attribute->expects($this->atLeastOnce())
->method('getFrontend')
->will($this->returnValue($this->frontend));

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

Expand Down Expand Up @@ -283,6 +287,9 @@ public function testGetItemsWithoutApply()
$this->attribute->expects($this->exactly(2))
->method('getAttributeCode')
->will($this->returnValue($attributeCode));
$this->attribute->expects($this->atLeastOnce())
->method('getFrontend')
->will($this->returnValue($this->frontend));

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

Expand Down Expand Up @@ -329,6 +336,105 @@ public function testGetItemsWithoutApply()
$this->assertEquals($expectedFilterItems, $result);
}

/**
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
public function testGetItemsOnlyWithResults()
{
$attributeCode = 'attributeCode';
$selectedOptions = [
[
'label' => 'selectedOptionLabel1',
'value' => 'selectedOptionValue1',
],
[
'label' => 'selectedOptionLabel2',
'value' => 'selectedOptionValue2',
],
];
$facetedData = [
'selectedOptionValue1' => ['count' => 10],
'selectedOptionValue2' => ['count' => 0],
];
$builtData = [
[
'label' => $selectedOptions[0]['label'],
'value' => $selectedOptions[0]['value'],
'count' => $facetedData[$selectedOptions[0]['value']]['count'],
],
];

$this->attribute->expects($this->atLeastOnce())
->method('getAttributeCode')
->willReturn($attributeCode);
$this->attribute->expects($this->atLeastOnce())
->method('getIsFilterable')
->willReturn(AbstractFilter::ATTRIBUTE_OPTIONS_ONLY_WITH_RESULTS);
$this->attribute->expects($this->atLeastOnce())
->method('getFrontend')
->will($this->returnValue($this->frontend));

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

$this->frontend->expects($this->once())
->method('getSelectOptions')
->willReturn($selectedOptions);

$this->fulltextCollection->expects($this->once())
->method('getFacetedData')
->willReturn($facetedData);
$this->fulltextCollection->expects($this->once())
->method('getSize')
->will($this->returnValue(50));

$this->itemDataBuilder->expects($this->once())
->method('addItemData')
->with(
$selectedOptions[0]['label'],
$selectedOptions[0]['value'],
$facetedData[$selectedOptions[0]['value']]['count']
)
->will($this->returnSelf());

$this->itemDataBuilder->expects($this->once())
->method('build')
->willReturn($builtData);

$expectedFilterItems = [
$this->createFilterItem(0, $builtData[0]['label'], $builtData[0]['value'], $builtData[0]['count']),
];
$result = $this->target->getItems();

$this->assertEquals($expectedFilterItems, $result);
}

/**
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
public function testGetItemsIfFacetedDataIsEmpty()
{
$attributeCode = 'attributeCode';

$this->attribute->expects($this->atLeastOnce())
->method('getAttributeCode')
->willReturn($attributeCode);
$this->attribute->expects($this->atLeastOnce())
->method('getIsFilterable')
->willReturn(0);

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

$this->fulltextCollection->expects($this->once())
->method('getFacetedData')
->willReturn([]);

$this->itemDataBuilder->expects($this->once())
->method('build')
->willReturn([]);

$this->assertEquals([], $this->target->getItems());
}

/**
* @param int $index
* @param string $label
Expand Down
Loading

0 comments on commit fc32492

Please sign in to comment.