Skip to content

Commit

Permalink
Merge pull request magento#4382 from magento-epam/EPAM-PR-58
Browse files Browse the repository at this point in the history
- fixed  [Product grid] SC's values aren't sorted alphabetically in the tooltip
- fixed  Slow query delete on sub SELECT query
- fixed Import Customer ("gender" field) issue
  • Loading branch information
irenelagno authored Jun 21, 2019
2 parents 5177344 + 28dcad4 commit 485b30f
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

declare(strict_types=1);

namespace Magento\CatalogUrlRewrite\Model\ResourceModel\Category;

use Magento\Framework\Model\ResourceModel\Db\AbstractDb;
Expand Down Expand Up @@ -49,7 +52,7 @@ protected function _construct()
public function saveMultiple(array $insertData)
{
$connection = $this->getConnection();
if (sizeof($insertData) <= self::CHUNK_SIZE) {
if (count($insertData) <= self::CHUNK_SIZE) {
return $connection->insertMultiple($this->getTable(self::TABLE_NAME), $insertData);
}
$data = array_chunk($insertData, self::CHUNK_SIZE);
Expand Down Expand Up @@ -98,10 +101,13 @@ public function removeMultipleByProductCategory(array $filter)
private function prepareSelect($data)
{
$select = $this->getConnection()->select();
$select->from($this->getTable(DbStorage::TABLE_NAME), 'url_rewrite_id');

$select->from(DbStorage::TABLE_NAME);
$select->join(
self::TABLE_NAME,
DbStorage::TABLE_NAME . '.url_rewrite_id = ' . self::TABLE_NAME . '.url_rewrite_id'
);
foreach ($data as $column => $value) {
$select->where($this->getConnection()->quoteIdentifier($column) . ' IN (?)', $value);
$select->where(DbStorage::TABLE_NAME . '.' . $column . ' IN (?)', $value);
}
return $select;
}
Expand Down
28 changes: 14 additions & 14 deletions app/code/Magento/CustomerImportExport/Model/Import/Customer.php
Original file line number Diff line number Diff line change
Expand Up @@ -288,9 +288,12 @@ private function getCustomerEntityFieldsToUpdate(array $entitiesToUpdate): array
{
$firstCustomer = reset($entitiesToUpdate);
$columnsToUpdate = array_keys($firstCustomer);
$customerFieldsToUpdate = array_filter($this->customerFields, function ($field) use ($columnsToUpdate) {
return in_array($field, $columnsToUpdate);
});
$customerFieldsToUpdate = array_filter(
$this->customerFields,
function ($field) use ($columnsToUpdate) {
return in_array($field, $columnsToUpdate);
}
);
return $customerFieldsToUpdate;
}

Expand Down Expand Up @@ -423,6 +426,9 @@ protected function _prepareDataForUpdate(array $rowData)
$attributeParameters = $this->_attributes[$attributeCode];
if (in_array($attributeParameters['type'], ['select', 'boolean'])) {
$value = $this->getSelectAttrIdByValue($attributeParameters, $value);
if ($attributeCode === CustomerInterface::GENDER && $value === 0) {
$value = null;
}
} elseif ('multiselect' == $attributeParameters['type']) {
$ids = [];
foreach (explode($multiSeparator, mb_strtolower($value)) as $subValue) {
Expand Down Expand Up @@ -519,10 +525,8 @@ protected function _importData()
if (!isset($attributesToSave[$tableName])) {
$attributesToSave[$tableName] = [];
}
$attributesToSave[$tableName] = array_diff_key(
$attributesToSave[$tableName],
$customerAttributes
) + $customerAttributes;
$attributes = array_diff_key($attributesToSave[$tableName], $customerAttributes);
$attributesToSave[$tableName] = $attributes + $customerAttributes;
}
}
}
Expand Down Expand Up @@ -578,13 +582,9 @@ protected function _validateRowForUpdate(array $rowData, $rowNumber)
$this->addRowError(self::ERROR_INVALID_STORE, $rowNumber);
}
// check password
if (isset(
$rowData['password']
) && strlen(
$rowData['password']
) && $this->string->strlen(
$rowData['password']
) < self::MIN_PASSWORD_LENGTH
if (isset($rowData['password'])
&& strlen($rowData['password'])
&& $this->string->strlen($rowData['password']) < self::MIN_PASSWORD_LENGTH
) {
$this->addRowError(self::ERROR_PASSWORD_LENGTH, $rowNumber);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,11 @@ define([
}
});

return labels.sort();
return labels.sort(
function (labelFirst, labelSecond) {
return labelFirst.toLowerCase().localeCompare(labelSecond.toLowerCase());
}
);
},

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@

use Magento\Catalog\Api\CategoryRepositoryInterface;
use Magento\Catalog\Model\Category;
use Magento\Catalog\Model\CategoryRepository;
use Magento\Catalog\Model\ProductRepository;
use Magento\CatalogUrlRewrite\Model\ResourceModel\Category\Product;
use Magento\Framework\Exception\CouldNotSaveException;
use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\Exception\NoSuchEntityException;
Expand Down Expand Up @@ -318,6 +320,53 @@ public function testGenerateUrlRewritesWithoutGenerateProductRewrites()
$this->assertResults($productExpectedResult, $actualResults);
}

/**
* Check number of records after removing product
*
* @magentoDataFixture Magento/CatalogUrlRewrite/_files/categories_with_products.php
* @magentoConfigFixture default/catalog/seo/generate_category_product_rewrites 1
* @magentoDbIsolation enabled
* @magentoAppIsolation enabled
*
* @return void
*/
public function testRemoveCatalogUrlRewrites()
{
/** @var CategoryRepository $categoryRepository */
$categoryRepository = $this->objectManager->create(CategoryRepository::class);
$category = $categoryRepository->get(5);
$categoryId = $category->getId();

/** @var ProductRepository $productRepository */
$productRepository = $this->objectManager->create(ProductRepository::class);
$product = $productRepository->get('12345');
$productId = $product->getId();

$countBeforeRemoving = $this->getCountOfRewrites($productId, $categoryId);
$productRepository->delete($product);
$countAfterRemoving = $this->getCountOfRewrites($productId, $categoryId);
$this->assertEquals($countBeforeRemoving - 1, $countAfterRemoving);
}

/**
* Get count of records in table
*
* @param $productId
* @param $categoryId
* @return string
*/
private function getCountOfRewrites($productId, $categoryId): string
{
/** @var Product $model */
$model = $this->objectManager->get(Product::class);
$connection = $model->getConnection();
$select = $connection->select();
$select->from(Product::TABLE_NAME, 'COUNT(*)');
$select->where('category_id = ?', $categoryId);
$select->where('product_id = ?', $productId);
return $connection->fetchOne($select);
}

/**
* @param array $expected
* @param array $actual
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,5 +69,22 @@ define([
expect(expandable.getLabel).toHaveBeenCalled();
});
});

describe('getLabelsArray method', function () {
it('check if label array sort alphabetically case insensitive', function () {
record['shared_catalog'].push(1, 2, 3);
expandable.options.push({
label: 'Default',
value: '1'
}, {
label: 'Label',
value: '2'
}, {
label: 'default',
value: '3'
});
expect(expandable.getLabelsArray(record)).toEqual(['Default', 'default', 'Label']);
});
});
});
});

0 comments on commit 485b30f

Please sign in to comment.