Skip to content

Commit

Permalink
Merge pull request #353 from magento-dragons/PR-9
Browse files Browse the repository at this point in the history
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
  • Loading branch information
dvoskoboinikov authored Sep 8, 2016
2 parents c614b9c + c3cd4eb commit af1c56d
Show file tree
Hide file tree
Showing 24 changed files with 482 additions and 122 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public function addMediaDataToProduct(Product $product, array $mediaEntries)

foreach ($mediaEntries as $mediaEntry) {
$mediaEntry = $this->substituteNullsWithDefaultValues($mediaEntry);
$value['images'][] = $mediaEntry;
$value['images'][$mediaEntry['value_id']] = $mediaEntry;
}
$product->setData($attrCode, $value);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,8 @@ protected function _getIndexableAttributesCondition()
'ca.is_filterable_in_search > 0',
'ca.is_visible_in_advanced_search > 0',
'ca.is_filterable > 0',
// Visibility is attribute that isn't used by search, but required to determine is product should be shown
"ea.attribute_code = 'visibility'"
];

return implode(' OR ', $conditions);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
use Magento\Catalog\Model\Locator\LocatorInterface;
use Magento\Ui\Component\Form;
use Magento\Framework\Stdlib\ArrayManager;
use Magento\Store\Model\StoreManagerInterface;
use Magento\Framework\Locale\CurrencyInterface;

/**
* Data provider for main panel of product page
Expand All @@ -26,14 +24,9 @@ class General extends AbstractModifier
* @var ArrayManager
*/
protected $arrayManager;

/**
* @var StoreManagerInterface
*/
private $storeManager;

/**
* @var CurrencyInterface
* @var \Magento\Framework\Locale\CurrencyInterface
*/
private $localeCurrency;

Expand Down Expand Up @@ -82,7 +75,7 @@ protected function customizeWeightFormat(array $data)
$data = $this->arrayManager->replace(
$path,
$data,
$this->formatNumber($this->arrayManager->get($path, $data))
$this->formatWeight($this->arrayManager->get($path, $data))
);
}

Expand All @@ -105,7 +98,7 @@ protected function customizeAdvancedPriceFormat(array $data)
$value[ProductAttributeInterface::CODE_TIER_PRICE_FIELD_PRICE] =
$this->formatPrice($value[ProductAttributeInterface::CODE_TIER_PRICE_FIELD_PRICE]);
$value[ProductAttributeInterface::CODE_TIER_PRICE_FIELD_PRICE_QTY] =
$this->formatNumber((int)$value[ProductAttributeInterface::CODE_TIER_PRICE_FIELD_PRICE_QTY]);
(int)$value[ProductAttributeInterface::CODE_TIER_PRICE_FIELD_PRICE_QTY];
}
}

Expand Down Expand Up @@ -373,28 +366,12 @@ protected function customizeNameListeners(array $meta)
private function getLocaleCurrency()
{
if ($this->localeCurrency === null) {
$this->localeCurrency = \Magento\Framework\App\ObjectManager::getInstance()->get(CurrencyInterface::class);
$this->localeCurrency = \Magento\Framework\App\ObjectManager::getInstance()
->get(\Magento\Framework\Locale\CurrencyInterface::class);
}
return $this->localeCurrency;
}

/**
* The getter function to get the store manager for real application code
*
* @return \Magento\Store\Model\StoreManagerInterface
*
* @deprecated
*/
private function getStoreManager()
{
if ($this->storeManager === null) {
$this->storeManager =
\Magento\Framework\App\ObjectManager::getInstance()->get(StoreManagerInterface::class);
}
return $this->storeManager;
}


/**
* Format price according to the locale of the currency
*
Expand All @@ -407,7 +384,7 @@ protected function formatPrice($value)
return null;
}

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

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

$value = (float)$value;
$precision = strlen(substr(strrchr($value, "."), 1));
$store = $this->getStoreManager()->getStore();
$store = $this->locator->getStore();
$currency = $this->getLocaleCurrency()->getCurrency($store->getBaseCurrencyCode());
$value = $currency->toCurrency($value, ['display' => \Magento\Framework\Currency::NO_SYMBOL,
'precision' => $precision]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ public function addFieldToFilter($field, $condition = null)

$this->getSearchCriteriaBuilder();
$this->getFilterBuilder();
if (!is_array($condition) || !in_array(key($condition), ['from', 'to'])) {
if (!is_array($condition) || !in_array(key($condition), ['from', 'to'], true)) {
$this->filterBuilder->setField($field);
$this->filterBuilder->setValue($condition);
$this->searchCriteriaBuilder->addFilter($this->filterBuilder->create());
Expand Down Expand Up @@ -371,7 +371,7 @@ protected function _renderFilters()
public function setOrder($attribute, $dir = Select::SQL_DESC)
{
$this->order = ['field' => $attribute, 'dir' => $dir];
if ($attribute != 'relevance') {
if ($attribute !== 'relevance') {
parent::setOrder($attribute, $dir);
}
return $this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public function build(RequestInterface $request)
ScopeInterface::SCOPE_STORE
);
if ($isShowOutOfStock === false) {
$select->joinLeft(
$select->joinInner(
['stock_index' => $this->resource->getTableName('cataloginventory_stock_status')],
'search_index.entity_id = stock_index.product_id'
. $this->resource->getConnection()->quoteInto(
Expand Down
50 changes: 37 additions & 13 deletions app/code/Magento/CatalogSearch/Model/Search/TableMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@

namespace Magento\CatalogSearch\Model\Search;

use Magento\Catalog\Model\Product;
use Magento\Catalog\Model\ResourceModel\Product\Attribute\CollectionFactory;
use Magento\Eav\Model\Config as EavConfig;
use Magento\Eav\Model\Entity\Attribute\AbstractAttribute;
use Magento\Framework\App\ObjectManager;
use Magento\Framework\App\ResourceConnection as AppResource;
use Magento\Framework\DB\Select;
use Magento\Framework\Search\Request\FilterInterface;
Expand All @@ -33,42 +36,59 @@ class TableMapper
private $storeManager;

/**
* @var \Magento\Catalog\Model\ResourceModel\Product\Attribute\Collection
* @var EavConfig
*/
private $attributeCollection;
private $eavConfig;

/**
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
* @param AppResource $resource
* @param StoreManagerInterface $storeManager
* @param CollectionFactory $attributeCollectionFactory
* @param EavConfig $eavConfig
*/
public function __construct(
AppResource $resource,
StoreManagerInterface $storeManager,
CollectionFactory $attributeCollectionFactory
CollectionFactory $attributeCollectionFactory,
EavConfig $eavConfig = null
) {
$this->resource = $resource;
$this->storeManager = $storeManager;
$this->attributeCollection = $attributeCollectionFactory->create();
$this->eavConfig = $eavConfig !== null ? $eavConfig : ObjectManager::getInstance()->get(EavConfig::class);
}

/**
* @param Select $select
* @param RequestInterface $request
* @return Select
* @throws \LogicException
*/
public function addTables(Select $select, RequestInterface $request)
{
$mappedTables = [];
$filters = $this->getFilters($request->getQuery());
foreach ($filters as $filter) {
list($alias, $table, $mapOn, $mappedFields) = $this->getMappingData($filter);
list($alias, $table, $mapOn, $mappedFields, $joinType) = $this->getMappingData($filter);
if (!array_key_exists($alias, $mappedTables)) {
$select->joinLeft(
[$alias => $table],
$mapOn,
$mappedFields
);
switch ($joinType) {
case \Magento\Framework\DB\Select::INNER_JOIN:
$select->joinInner(
[$alias => $table],
$mapOn,
$mappedFields
);
break;
case \Magento\Framework\DB\Select::LEFT_JOIN:
$select->joinLeft(
[$alias => $table],
$mapOn,
$mappedFields
);
break;
default:
throw new \LogicException(__('Unsupported join type: %1', $joinType));
}
$mappedTables[$alias] = $table;
}
}
Expand All @@ -90,7 +110,8 @@ public function getMappingAlias(FilterInterface $filter)
* 'table_alias',
* 'table',
* 'join_condition',
* ['fields']
* ['fields'],
* 'joinType'
* ]
* @param FilterInterface $filter
* @return array
Expand All @@ -102,6 +123,7 @@ private function getMappingData(FilterInterface $filter)
$mapOn = null;
$mappedFields = null;
$field = $filter->getField();
$joinType = \Magento\Framework\DB\Select::INNER_JOIN;
$fieldToTableMap = $this->getFieldToTableMap($field);
if ($fieldToTableMap) {
list($alias, $table, $mapOn, $mappedFields) = $fieldToTableMap;
Expand All @@ -110,6 +132,7 @@ private function getMappingData(FilterInterface $filter)
if ($filter->getType() === FilterInterface::TYPE_TERM
&& in_array($attribute->getFrontendInput(), ['select', 'multiselect'], true)
) {
$joinType = \Magento\Framework\DB\Select::LEFT_JOIN;
$table = $this->resource->getTableName('catalog_product_index_eav');
$alias = $field . RequestGenerator::FILTER_SUFFIX;
$mapOn = sprintf(
Expand All @@ -127,7 +150,7 @@ private function getMappingData(FilterInterface $filter)
}
}

return [$alias, $table, $mapOn, $mappedFields];
return [$alias, $table, $mapOn, $mappedFields, $joinType];
}

/**
Expand Down Expand Up @@ -242,10 +265,11 @@ private function getFieldToTableMap($field)
/**
* @param string $field
* @return \Magento\Catalog\Model\ResourceModel\Eav\Attribute
* @throws \Magento\Framework\Exception\LocalizedException
*/
private function getAttributeByCode($field)
{
$attribute = $this->attributeCollection->getItemByColumnValue('attribute_code', $field);
$attribute = $this->eavConfig->getAttribute(Product::ENTITY, $field);
return $attribute;
}
}
Loading

0 comments on commit af1c56d

Please sign in to comment.