Skip to content

Commit af1c56d

Browse files
Merge pull request #353 from magento-dragons/PR-9
Fixed issues: - MAGETWO-52974: Configurable product options not saved when editing - MAGETWO-57175: Cannot delete product image - MAGETWO-52309: Configurable Product. Price should not be sent to server while saving. - MAGETWO-51447: CatalogSearch Fulltext Collection not allows to use filters with multiple values - MAGETWO-55847: [GitHub] When tier price qty above 1000 adds a thousand separator in the Admin Panel #5745
2 parents c614b9c + c3cd4eb commit af1c56d

File tree

24 files changed

+482
-122
lines changed

24 files changed

+482
-122
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public function addMediaDataToProduct(Product $product, array $mediaEntries)
7878

7979
foreach ($mediaEntries as $mediaEntry) {
8080
$mediaEntry = $this->substituteNullsWithDefaultValues($mediaEntry);
81-
$value['images'][] = $mediaEntry;
81+
$value['images'][$mediaEntry['value_id']] = $mediaEntry;
8282
}
8383
$product->setData($attrCode, $value);
8484
}

app/code/Magento/Catalog/Model/ResourceModel/Product/Indexer/Eav/AbstractEav.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,8 @@ protected function _getIndexableAttributesCondition()
263263
'ca.is_filterable_in_search > 0',
264264
'ca.is_visible_in_advanced_search > 0',
265265
'ca.is_filterable > 0',
266+
// Visibility is attribute that isn't used by search, but required to determine is product should be shown
267+
"ea.attribute_code = 'visibility'"
266268
];
267269

268270
return implode(' OR ', $conditions);

app/code/Magento/Catalog/Ui/DataProvider/Product/Form/Modifier/General.php

Lines changed: 7 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99
use Magento\Catalog\Model\Locator\LocatorInterface;
1010
use Magento\Ui\Component\Form;
1111
use Magento\Framework\Stdlib\ArrayManager;
12-
use Magento\Store\Model\StoreManagerInterface;
13-
use Magento\Framework\Locale\CurrencyInterface;
1412

1513
/**
1614
* Data provider for main panel of product page
@@ -26,14 +24,9 @@ class General extends AbstractModifier
2624
* @var ArrayManager
2725
*/
2826
protected $arrayManager;
29-
30-
/**
31-
* @var StoreManagerInterface
32-
*/
33-
private $storeManager;
3427

3528
/**
36-
* @var CurrencyInterface
29+
* @var \Magento\Framework\Locale\CurrencyInterface
3730
*/
3831
private $localeCurrency;
3932

@@ -82,7 +75,7 @@ protected function customizeWeightFormat(array $data)
8275
$data = $this->arrayManager->replace(
8376
$path,
8477
$data,
85-
$this->formatNumber($this->arrayManager->get($path, $data))
78+
$this->formatWeight($this->arrayManager->get($path, $data))
8679
);
8780
}
8881

@@ -105,7 +98,7 @@ protected function customizeAdvancedPriceFormat(array $data)
10598
$value[ProductAttributeInterface::CODE_TIER_PRICE_FIELD_PRICE] =
10699
$this->formatPrice($value[ProductAttributeInterface::CODE_TIER_PRICE_FIELD_PRICE]);
107100
$value[ProductAttributeInterface::CODE_TIER_PRICE_FIELD_PRICE_QTY] =
108-
$this->formatNumber((int)$value[ProductAttributeInterface::CODE_TIER_PRICE_FIELD_PRICE_QTY]);
101+
(int)$value[ProductAttributeInterface::CODE_TIER_PRICE_FIELD_PRICE_QTY];
109102
}
110103
}
111104

@@ -373,28 +366,12 @@ protected function customizeNameListeners(array $meta)
373366
private function getLocaleCurrency()
374367
{
375368
if ($this->localeCurrency === null) {
376-
$this->localeCurrency = \Magento\Framework\App\ObjectManager::getInstance()->get(CurrencyInterface::class);
369+
$this->localeCurrency = \Magento\Framework\App\ObjectManager::getInstance()
370+
->get(\Magento\Framework\Locale\CurrencyInterface::class);
377371
}
378372
return $this->localeCurrency;
379373
}
380374

381-
/**
382-
* The getter function to get the store manager for real application code
383-
*
384-
* @return \Magento\Store\Model\StoreManagerInterface
385-
*
386-
* @deprecated
387-
*/
388-
private function getStoreManager()
389-
{
390-
if ($this->storeManager === null) {
391-
$this->storeManager =
392-
\Magento\Framework\App\ObjectManager::getInstance()->get(StoreManagerInterface::class);
393-
}
394-
return $this->storeManager;
395-
}
396-
397-
398375
/**
399376
* Format price according to the locale of the currency
400377
*
@@ -407,7 +384,7 @@ protected function formatPrice($value)
407384
return null;
408385
}
409386

410-
$store = $this->getStoreManager()->getStore();
387+
$store = $this->locator->getStore();
411388
$currency = $this->getLocaleCurrency()->getCurrency($store->getBaseCurrencyCode());
412389
$value = $currency->toCurrency($value, ['display' => \Magento\Framework\Currency::NO_SYMBOL]);
413390

@@ -428,7 +405,7 @@ protected function formatNumber($value)
428405

429406
$value = (float)$value;
430407
$precision = strlen(substr(strrchr($value, "."), 1));
431-
$store = $this->getStoreManager()->getStore();
408+
$store = $this->locator->getStore();
432409
$currency = $this->getLocaleCurrency()->getCurrency($store->getBaseCurrencyCode());
433410
$value = $currency->toCurrency($value, ['display' => \Magento\Framework\Currency::NO_SYMBOL,
434411
'precision' => $precision]);

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ public function addFieldToFilter($field, $condition = null)
265265

266266
$this->getSearchCriteriaBuilder();
267267
$this->getFilterBuilder();
268-
if (!is_array($condition) || !in_array(key($condition), ['from', 'to'])) {
268+
if (!is_array($condition) || !in_array(key($condition), ['from', 'to'], true)) {
269269
$this->filterBuilder->setField($field);
270270
$this->filterBuilder->setValue($condition);
271271
$this->searchCriteriaBuilder->addFilter($this->filterBuilder->create());
@@ -371,7 +371,7 @@ protected function _renderFilters()
371371
public function setOrder($attribute, $dir = Select::SQL_DESC)
372372
{
373373
$this->order = ['field' => $attribute, 'dir' => $dir];
374-
if ($attribute != 'relevance') {
374+
if ($attribute !== 'relevance') {
375375
parent::setOrder($attribute, $dir);
376376
}
377377
return $this;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ public function build(RequestInterface $request)
123123
ScopeInterface::SCOPE_STORE
124124
);
125125
if ($isShowOutOfStock === false) {
126-
$select->joinLeft(
126+
$select->joinInner(
127127
['stock_index' => $this->resource->getTableName('cataloginventory_stock_status')],
128128
'search_index.entity_id = stock_index.product_id'
129129
. $this->resource->getConnection()->quoteInto(

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

Lines changed: 37 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,11 @@
66

77
namespace Magento\CatalogSearch\Model\Search;
88

9+
use Magento\Catalog\Model\Product;
910
use Magento\Catalog\Model\ResourceModel\Product\Attribute\CollectionFactory;
11+
use Magento\Eav\Model\Config as EavConfig;
1012
use Magento\Eav\Model\Entity\Attribute\AbstractAttribute;
13+
use Magento\Framework\App\ObjectManager;
1114
use Magento\Framework\App\ResourceConnection as AppResource;
1215
use Magento\Framework\DB\Select;
1316
use Magento\Framework\Search\Request\FilterInterface;
@@ -33,42 +36,59 @@ class TableMapper
3336
private $storeManager;
3437

3538
/**
36-
* @var \Magento\Catalog\Model\ResourceModel\Product\Attribute\Collection
39+
* @var EavConfig
3740
*/
38-
private $attributeCollection;
41+
private $eavConfig;
3942

4043
/**
44+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
4145
* @param AppResource $resource
4246
* @param StoreManagerInterface $storeManager
4347
* @param CollectionFactory $attributeCollectionFactory
48+
* @param EavConfig $eavConfig
4449
*/
4550
public function __construct(
4651
AppResource $resource,
4752
StoreManagerInterface $storeManager,
48-
CollectionFactory $attributeCollectionFactory
53+
CollectionFactory $attributeCollectionFactory,
54+
EavConfig $eavConfig = null
4955
) {
5056
$this->resource = $resource;
5157
$this->storeManager = $storeManager;
52-
$this->attributeCollection = $attributeCollectionFactory->create();
58+
$this->eavConfig = $eavConfig !== null ? $eavConfig : ObjectManager::getInstance()->get(EavConfig::class);
5359
}
5460

5561
/**
5662
* @param Select $select
5763
* @param RequestInterface $request
5864
* @return Select
65+
* @throws \LogicException
5966
*/
6067
public function addTables(Select $select, RequestInterface $request)
6168
{
6269
$mappedTables = [];
6370
$filters = $this->getFilters($request->getQuery());
6471
foreach ($filters as $filter) {
65-
list($alias, $table, $mapOn, $mappedFields) = $this->getMappingData($filter);
72+
list($alias, $table, $mapOn, $mappedFields, $joinType) = $this->getMappingData($filter);
6673
if (!array_key_exists($alias, $mappedTables)) {
67-
$select->joinLeft(
68-
[$alias => $table],
69-
$mapOn,
70-
$mappedFields
71-
);
74+
switch ($joinType) {
75+
case \Magento\Framework\DB\Select::INNER_JOIN:
76+
$select->joinInner(
77+
[$alias => $table],
78+
$mapOn,
79+
$mappedFields
80+
);
81+
break;
82+
case \Magento\Framework\DB\Select::LEFT_JOIN:
83+
$select->joinLeft(
84+
[$alias => $table],
85+
$mapOn,
86+
$mappedFields
87+
);
88+
break;
89+
default:
90+
throw new \LogicException(__('Unsupported join type: %1', $joinType));
91+
}
7292
$mappedTables[$alias] = $table;
7393
}
7494
}
@@ -90,7 +110,8 @@ public function getMappingAlias(FilterInterface $filter)
90110
* 'table_alias',
91111
* 'table',
92112
* 'join_condition',
93-
* ['fields']
113+
* ['fields'],
114+
* 'joinType'
94115
* ]
95116
* @param FilterInterface $filter
96117
* @return array
@@ -102,6 +123,7 @@ private function getMappingData(FilterInterface $filter)
102123
$mapOn = null;
103124
$mappedFields = null;
104125
$field = $filter->getField();
126+
$joinType = \Magento\Framework\DB\Select::INNER_JOIN;
105127
$fieldToTableMap = $this->getFieldToTableMap($field);
106128
if ($fieldToTableMap) {
107129
list($alias, $table, $mapOn, $mappedFields) = $fieldToTableMap;
@@ -110,6 +132,7 @@ private function getMappingData(FilterInterface $filter)
110132
if ($filter->getType() === FilterInterface::TYPE_TERM
111133
&& in_array($attribute->getFrontendInput(), ['select', 'multiselect'], true)
112134
) {
135+
$joinType = \Magento\Framework\DB\Select::LEFT_JOIN;
113136
$table = $this->resource->getTableName('catalog_product_index_eav');
114137
$alias = $field . RequestGenerator::FILTER_SUFFIX;
115138
$mapOn = sprintf(
@@ -127,7 +150,7 @@ private function getMappingData(FilterInterface $filter)
127150
}
128151
}
129152

130-
return [$alias, $table, $mapOn, $mappedFields];
153+
return [$alias, $table, $mapOn, $mappedFields, $joinType];
131154
}
132155

133156
/**
@@ -242,10 +265,11 @@ private function getFieldToTableMap($field)
242265
/**
243266
* @param string $field
244267
* @return \Magento\Catalog\Model\ResourceModel\Eav\Attribute
268+
* @throws \Magento\Framework\Exception\LocalizedException
245269
*/
246270
private function getAttributeByCode($field)
247271
{
248-
$attribute = $this->attributeCollection->getItemByColumnValue('attribute_code', $field);
272+
$attribute = $this->eavConfig->getAttribute(Product::ENTITY, $field);
249273
return $attribute;
250274
}
251275
}

0 commit comments

Comments
 (0)