Skip to content

Commit 746bc75

Browse files
[Magento Community Engineering] Community Contributions - 2.3-develop
- merged latest code from mainline branch
2 parents a95451f + 485b30f commit 746bc75

File tree

5 files changed

+95
-19
lines changed

5 files changed

+95
-19
lines changed

app/code/Magento/CatalogUrlRewrite/Model/ResourceModel/Category/Product.php

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
7+
declare(strict_types=1);
8+
69
namespace Magento\CatalogUrlRewrite\Model\ResourceModel\Category;
710

811
use Magento\Framework\Model\ResourceModel\Db\AbstractDb;
@@ -49,7 +52,7 @@ protected function _construct()
4952
public function saveMultiple(array $insertData)
5053
{
5154
$connection = $this->getConnection();
52-
if (sizeof($insertData) <= self::CHUNK_SIZE) {
55+
if (count($insertData) <= self::CHUNK_SIZE) {
5356
return $connection->insertMultiple($this->getTable(self::TABLE_NAME), $insertData);
5457
}
5558
$data = array_chunk($insertData, self::CHUNK_SIZE);
@@ -98,10 +101,13 @@ public function removeMultipleByProductCategory(array $filter)
98101
private function prepareSelect($data)
99102
{
100103
$select = $this->getConnection()->select();
101-
$select->from($this->getTable(DbStorage::TABLE_NAME), 'url_rewrite_id');
102-
104+
$select->from(DbStorage::TABLE_NAME);
105+
$select->join(
106+
self::TABLE_NAME,
107+
DbStorage::TABLE_NAME . '.url_rewrite_id = ' . self::TABLE_NAME . '.url_rewrite_id'
108+
);
103109
foreach ($data as $column => $value) {
104-
$select->where($this->getConnection()->quoteIdentifier($column) . ' IN (?)', $value);
110+
$select->where(DbStorage::TABLE_NAME . '.' . $column . ' IN (?)', $value);
105111
}
106112
return $select;
107113
}

app/code/Magento/CustomerImportExport/Model/Import/Customer.php

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -288,9 +288,12 @@ private function getCustomerEntityFieldsToUpdate(array $entitiesToUpdate): array
288288
{
289289
$firstCustomer = reset($entitiesToUpdate);
290290
$columnsToUpdate = array_keys($firstCustomer);
291-
$customerFieldsToUpdate = array_filter($this->customerFields, function ($field) use ($columnsToUpdate) {
292-
return in_array($field, $columnsToUpdate);
293-
});
291+
$customerFieldsToUpdate = array_filter(
292+
$this->customerFields,
293+
function ($field) use ($columnsToUpdate) {
294+
return in_array($field, $columnsToUpdate);
295+
}
296+
);
294297
return $customerFieldsToUpdate;
295298
}
296299

@@ -423,6 +426,9 @@ protected function _prepareDataForUpdate(array $rowData)
423426
$attributeParameters = $this->_attributes[$attributeCode];
424427
if (in_array($attributeParameters['type'], ['select', 'boolean'])) {
425428
$value = $this->getSelectAttrIdByValue($attributeParameters, $value);
429+
if ($attributeCode === CustomerInterface::GENDER && $value === 0) {
430+
$value = null;
431+
}
426432
} elseif ('multiselect' == $attributeParameters['type']) {
427433
$ids = [];
428434
foreach (explode($multiSeparator, mb_strtolower($value)) as $subValue) {
@@ -519,10 +525,8 @@ protected function _importData()
519525
if (!isset($attributesToSave[$tableName])) {
520526
$attributesToSave[$tableName] = [];
521527
}
522-
$attributesToSave[$tableName] = array_diff_key(
523-
$attributesToSave[$tableName],
524-
$customerAttributes
525-
) + $customerAttributes;
528+
$attributes = array_diff_key($attributesToSave[$tableName], $customerAttributes);
529+
$attributesToSave[$tableName] = $attributes + $customerAttributes;
526530
}
527531
}
528532
}
@@ -578,13 +582,9 @@ protected function _validateRowForUpdate(array $rowData, $rowNumber)
578582
$this->addRowError(self::ERROR_INVALID_STORE, $rowNumber);
579583
}
580584
// check password
581-
if (isset(
582-
$rowData['password']
583-
) && strlen(
584-
$rowData['password']
585-
) && $this->string->strlen(
586-
$rowData['password']
587-
) < self::MIN_PASSWORD_LENGTH
585+
if (isset($rowData['password'])
586+
&& strlen($rowData['password'])
587+
&& $this->string->strlen($rowData['password']) < self::MIN_PASSWORD_LENGTH
588588
) {
589589
$this->addRowError(self::ERROR_PASSWORD_LENGTH, $rowNumber);
590590
}

app/code/Magento/Ui/view/base/web/js/grid/columns/expandable.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,11 @@ define([
6767
}
6868
});
6969

70-
return labels.sort();
70+
return labels.sort(
71+
function (labelFirst, labelSecond) {
72+
return labelFirst.toLowerCase().localeCompare(labelSecond.toLowerCase());
73+
}
74+
);
7175
},
7276

7377
/**

dev/tests/integration/testsuite/Magento/CatalogUrlRewrite/Model/CategoryUrlRewriteGeneratorTest.php

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88

99
use Magento\Catalog\Api\CategoryRepositoryInterface;
1010
use Magento\Catalog\Model\Category;
11+
use Magento\Catalog\Model\CategoryRepository;
1112
use Magento\Catalog\Model\ProductRepository;
13+
use Magento\CatalogUrlRewrite\Model\ResourceModel\Category\Product;
1214
use Magento\Framework\Exception\CouldNotSaveException;
1315
use Magento\Framework\Exception\LocalizedException;
1416
use Magento\Framework\Exception\NoSuchEntityException;
@@ -318,6 +320,53 @@ public function testGenerateUrlRewritesWithoutGenerateProductRewrites()
318320
$this->assertResults($productExpectedResult, $actualResults);
319321
}
320322

323+
/**
324+
* Check number of records after removing product
325+
*
326+
* @magentoDataFixture Magento/CatalogUrlRewrite/_files/categories_with_products.php
327+
* @magentoConfigFixture default/catalog/seo/generate_category_product_rewrites 1
328+
* @magentoDbIsolation enabled
329+
* @magentoAppIsolation enabled
330+
*
331+
* @return void
332+
*/
333+
public function testRemoveCatalogUrlRewrites()
334+
{
335+
/** @var CategoryRepository $categoryRepository */
336+
$categoryRepository = $this->objectManager->create(CategoryRepository::class);
337+
$category = $categoryRepository->get(5);
338+
$categoryId = $category->getId();
339+
340+
/** @var ProductRepository $productRepository */
341+
$productRepository = $this->objectManager->create(ProductRepository::class);
342+
$product = $productRepository->get('12345');
343+
$productId = $product->getId();
344+
345+
$countBeforeRemoving = $this->getCountOfRewrites($productId, $categoryId);
346+
$productRepository->delete($product);
347+
$countAfterRemoving = $this->getCountOfRewrites($productId, $categoryId);
348+
$this->assertEquals($countBeforeRemoving - 1, $countAfterRemoving);
349+
}
350+
351+
/**
352+
* Get count of records in table
353+
*
354+
* @param $productId
355+
* @param $categoryId
356+
* @return string
357+
*/
358+
private function getCountOfRewrites($productId, $categoryId): string
359+
{
360+
/** @var Product $model */
361+
$model = $this->objectManager->get(Product::class);
362+
$connection = $model->getConnection();
363+
$select = $connection->select();
364+
$select->from(Product::TABLE_NAME, 'COUNT(*)');
365+
$select->where('category_id = ?', $categoryId);
366+
$select->where('product_id = ?', $productId);
367+
return $connection->fetchOne($select);
368+
}
369+
321370
/**
322371
* @param array $expected
323372
* @param array $actual

dev/tests/js/jasmine/tests/app/code/Magento/Ui/base/js/grid/columns/expandable.test.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,5 +69,22 @@ define([
6969
expect(expandable.getLabel).toHaveBeenCalled();
7070
});
7171
});
72+
73+
describe('getLabelsArray method', function () {
74+
it('check if label array sort alphabetically case insensitive', function () {
75+
record['shared_catalog'].push(1, 2, 3);
76+
expandable.options.push({
77+
label: 'Default',
78+
value: '1'
79+
}, {
80+
label: 'Label',
81+
value: '2'
82+
}, {
83+
label: 'default',
84+
value: '3'
85+
});
86+
expect(expandable.getLabelsArray(record)).toEqual(['Default', 'default', 'Label']);
87+
});
88+
});
7289
});
7390
});

0 commit comments

Comments
 (0)