diff --git a/app/code/Magento/ConfigurableProduct/view/frontend/web/js/configurable.js b/app/code/Magento/ConfigurableProduct/view/frontend/web/js/configurable.js
index 8fd1d761040d7..f705b6a95987c 100644
--- a/app/code/Magento/ConfigurableProduct/view/frontend/web/js/configurable.js
+++ b/app/code/Magento/ConfigurableProduct/view/frontend/web/js/configurable.js
@@ -33,7 +33,7 @@ define([
mediaGallerySelector: '[data-gallery-role=gallery-placeholder]',
mediaGalleryInitial: null,
slyOldPriceSelector: '.sly-old-price',
- normalPriceLabelSelector: '.normal-price .price-label',
+ normalPriceLabelSelector: '.product-info-main .normal-price .price-label',
/**
* Defines the mechanism of how images of a gallery should be
diff --git a/app/code/Magento/Cron/etc/db_schema.xml b/app/code/Magento/Cron/etc/db_schema.xml
index 206b8f64f3ae7..f26b6feea3b3b 100644
--- a/app/code/Magento/Cron/etc/db_schema.xml
+++ b/app/code/Magento/Cron/etc/db_schema.xml
@@ -8,7 +8,7 @@
-
diff --git a/app/code/Magento/Cron/etc/di.xml b/app/code/Magento/Cron/etc/di.xml
index bc321c2a1e2b6..e7286169359bd 100644
--- a/app/code/Magento/Cron/etc/di.xml
+++ b/app/code/Magento/Cron/etc/di.xml
@@ -68,14 +68,6 @@
- {magentoRoot}bin/magento cron:run | grep -v "Ran jobs by schedule" >> {magentoLog}magento.cron.log
- false
- -
-
- {magentoRoot}update/cron.php >> {magentoLog}update.cron.log
- - true
-
- -
-
- {magentoRoot}bin/magento setup:cron:run >> {magentoLog}setup.cron.log
- - true
-
diff --git a/app/code/Magento/Customer/Controller/Adminhtml/Index/Save.php b/app/code/Magento/Customer/Controller/Adminhtml/Index/Save.php
index a65bfa5d77f9e..977d3753ded65 100644
--- a/app/code/Magento/Customer/Controller/Adminhtml/Index/Save.php
+++ b/app/code/Magento/Customer/Controller/Adminhtml/Index/Save.php
@@ -248,7 +248,7 @@ protected function _extractData(
* @param array $extractedCustomerData
* @return array
*/
- protected function saveDefaultFlags(array $addressIdList, array & $extractedCustomerData)
+ protected function saveDefaultFlags(array $addressIdList, array &$extractedCustomerData)
{
$result = [];
$extractedCustomerData[CustomerInterface::DEFAULT_BILLING] = null;
@@ -290,7 +290,7 @@ protected function saveDefaultFlags(array $addressIdList, array & $extractedCust
* @param array $extractedCustomerData
* @return array
*/
- protected function _extractCustomerAddressData(array & $extractedCustomerData)
+ protected function _extractCustomerAddressData(array &$extractedCustomerData)
{
$addresses = $this->getRequest()->getPost('address');
$result = [];
@@ -380,6 +380,12 @@ public function execute()
$this->_coreRegistry->register(RegistryConstants::CURRENT_CUSTOMER_ID, $customerId);
$this->messageManager->addSuccessMessage(__('You saved the customer.'));
$returnToEdit = (bool)$this->getRequest()->getParam('back', false);
+ } catch (NoSuchEntityException $exception) {
+ $this->messageManager->addExceptionMessage(
+ $exception,
+ __('Something went wrong while saving the customer.')
+ );
+ $returnToEdit = false;
} catch (\Magento\Framework\Validator\Exception $exception) {
$messages = $exception->getMessages();
if (empty($messages)) {
diff --git a/app/code/Magento/Customer/Model/Customer/DataProviderWithDefaultAddresses.php b/app/code/Magento/Customer/Model/Customer/DataProviderWithDefaultAddresses.php
index fbf9cf4cbbf9a..604295cc0c078 100644
--- a/app/code/Magento/Customer/Model/Customer/DataProviderWithDefaultAddresses.php
+++ b/app/code/Magento/Customer/Model/Customer/DataProviderWithDefaultAddresses.php
@@ -9,17 +9,20 @@
use Magento\Customer\Model\Address;
use Magento\Customer\Model\Customer;
use Magento\Customer\Model\ResourceModel\Customer\CollectionFactory as CustomerCollectionFactory;
+use Magento\Directory\Model\CountryFactory;
use Magento\Eav\Model\Config;
use Magento\Eav\Model\Entity\Attribute\AbstractAttribute;
use Magento\Eav\Model\Entity\Type;
+use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\Session\SessionManagerInterface;
use Magento\Customer\Model\FileUploaderDataResolver;
use Magento\Customer\Model\AttributeMetadataResolver;
+use Magento\Ui\DataProvider\AbstractDataProvider;
/**
* Refactored version of Magento\Customer\Model\Customer\DataProvider with eliminated usage of addresses collection.
*/
-class DataProviderWithDefaultAddresses extends \Magento\Ui\DataProvider\AbstractDataProvider
+class DataProviderWithDefaultAddresses extends AbstractDataProvider
{
/**
* @var array
@@ -49,7 +52,7 @@ class DataProviderWithDefaultAddresses extends \Magento\Ui\DataProvider\Abstract
private $allowToShowHiddenAttributes;
/**
- * @var \Magento\Directory\Model\CountryFactory
+ * @var CountryFactory
*/
private $countryFactory;
@@ -69,14 +72,14 @@ class DataProviderWithDefaultAddresses extends \Magento\Ui\DataProvider\Abstract
* @param string $requestFieldName
* @param CustomerCollectionFactory $customerCollectionFactory
* @param Config $eavConfig
- * @param \Magento\Directory\Model\CountryFactory $countryFactory
+ * @param CountryFactory $countryFactory
* @param SessionManagerInterface $session
* @param FileUploaderDataResolver $fileUploaderDataResolver
* @param AttributeMetadataResolver $attributeMetadataResolver
* @param bool $allowToShowHiddenAttributes
* @param array $meta
* @param array $data
- * @throws \Magento\Framework\Exception\LocalizedException
+ * @throws LocalizedException
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
*/
public function __construct(
@@ -85,7 +88,7 @@ public function __construct(
string $requestFieldName,
CustomerCollectionFactory $customerCollectionFactory,
Config $eavConfig,
- \Magento\Directory\Model\CountryFactory $countryFactory,
+ CountryFactory $countryFactory,
SessionManagerInterface $session,
FileUploaderDataResolver $fileUploaderDataResolver,
AttributeMetadataResolver $attributeMetadataResolver,
@@ -158,17 +161,21 @@ public function getData(): array
*/
private function prepareDefaultAddress($address): array
{
- $addressData = [];
-
- if (!empty($address)) {
- $addressData = $address->getData();
- if (isset($addressData['street']) && !\is_array($address['street'])) {
- $addressData['street'] = explode("\n", $addressData['street']);
- }
- $countryId = $addressData['country_id'] ?? null;
- $addressData['country'] = $this->countryFactory->create()->loadByCode($countryId)->getName();
+ if (!$address) {
+ return [];
}
+ $addressData = $address->getData();
+ if (isset($addressData['street']) && !is_array($addressData['street'])) {
+ $addressData['street'] = explode("\n", $addressData['street']);
+ }
+ if (!empty($addressData['country_id'])) {
+ $addressData['country'] = $this->countryFactory->create()
+ ->loadByCode($addressData['country_id'])
+ ->getName();
+ }
+ $addressData['region'] = $address->getRegion();
+
return $addressData;
}
@@ -177,7 +184,7 @@ private function prepareDefaultAddress($address): array
*
* @param Type $entityType
* @return array
- * @throws \Magento\Framework\Exception\LocalizedException
+ * @throws LocalizedException
*/
private function getAttributesMeta(Type $entityType): array
{
diff --git a/app/code/Magento/Customer/Model/CustomerExtractor.php b/app/code/Magento/Customer/Model/CustomerExtractor.php
index 5d6f3245a0439..b9739ce0424a1 100644
--- a/app/code/Magento/Customer/Model/CustomerExtractor.php
+++ b/app/code/Magento/Customer/Model/CustomerExtractor.php
@@ -93,13 +93,15 @@ public function extract(
$customerData,
\Magento\Customer\Api\Data\CustomerInterface::class
);
-
+
$store = $this->storeManager->getStore();
$storeId = $store->getId();
-
+
if ($isGroupIdEmpty) {
+ $groupId = isset($customerData['group_id']) ? $customerData['group_id']
+ : $this->customerGroupManagement->getDefaultGroup($storeId)->getId();
$customerDataObject->setGroupId(
- $this->customerGroupManagement->getDefaultGroup($storeId)->getId()
+ $groupId
);
}
diff --git a/app/code/Magento/Customer/Model/ResourceModel/Address/Grid/Collection.php b/app/code/Magento/Customer/Model/ResourceModel/Address/Grid/Collection.php
index 4e0347059086f..0e2eb3e1d8e65 100644
--- a/app/code/Magento/Customer/Model/ResourceModel/Address/Grid/Collection.php
+++ b/app/code/Magento/Customer/Model/ResourceModel/Address/Grid/Collection.php
@@ -6,53 +6,84 @@
*/
namespace Magento\Customer\Model\ResourceModel\Address\Grid;
+use Magento\Framework\Api\ExtensibleDataInterface;
use Magento\Framework\Api\Search\SearchResultInterface;
use Magento\Framework\Api\Search\AggregationInterface;
+use Magento\Framework\Api\SearchCriteriaInterface;
+use Magento\Framework\Data\Collection\Db\FetchStrategyInterface;
+use Magento\Framework\Data\Collection\EntityFactoryInterface;
+use Magento\Framework\DB\Adapter\AdapterInterface;
+use Magento\Framework\Event\ManagerInterface;
+use Magento\Framework\Locale\ResolverInterface;
+use Magento\Framework\Model\ResourceModel\Db\AbstractDb;
use Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection;
+use Magento\Framework\View\Element\UiComponent\DataProvider\Document;
+use Psr\Log\LoggerInterface;
/**
* Class getting collection of addresses assigned to customer
*/
class Collection extends AbstractCollection implements SearchResultInterface
{
+ /**
+ * List of fields to fulltext search
+ */
+ private const FIELDS_TO_FULLTEXT_SEARCH = [
+ 'firstname',
+ 'lastname',
+ 'street',
+ 'city',
+ 'region',
+ 'postcode',
+ 'telephone',
+ ];
+
/**
* @var AggregationInterface
*/
private $aggregations;
/**
- * @param \Magento\Framework\Data\Collection\EntityFactoryInterface $entityFactory
- * @param \Psr\Log\LoggerInterface $logger
- * @param \Magento\Framework\Data\Collection\Db\FetchStrategyInterface $fetchStrategy
- * @param \Magento\Framework\Event\ManagerInterface $eventManager
+ * @var ResolverInterface
+ */
+ private $localeResolver;
+
+ /**
+ * @param EntityFactoryInterface $entityFactory
+ * @param LoggerInterface $logger
+ * @param FetchStrategyInterface $fetchStrategy
+ * @param ManagerInterface $eventManager
* @param string $mainTable
* @param string $eventPrefix
* @param string $eventObject
* @param string $resourceModel
+ * @param ResolverInterface $localeResolver
* @param string $model
- * @param \Magento\Framework\DB\Adapter\AdapterInterface|string|null $connection
- * @param \Magento\Framework\Model\ResourceModel\Db\AbstractDb $resource
+ * @param AdapterInterface|string|null $connection
+ * @param AbstractDb $resource
*
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
*/
public function __construct(
- \Magento\Framework\Data\Collection\EntityFactoryInterface $entityFactory,
- \Psr\Log\LoggerInterface $logger,
- \Magento\Framework\Data\Collection\Db\FetchStrategyInterface $fetchStrategy,
- \Magento\Framework\Event\ManagerInterface $eventManager,
+ EntityFactoryInterface $entityFactory,
+ LoggerInterface $logger,
+ FetchStrategyInterface $fetchStrategy,
+ ManagerInterface $eventManager,
$mainTable,
$eventPrefix,
$eventObject,
$resourceModel,
- $model = \Magento\Framework\View\Element\UiComponent\DataProvider\Document::class,
+ ResolverInterface $localeResolver,
+ $model = Document::class,
$connection = null,
- \Magento\Framework\Model\ResourceModel\Db\AbstractDb $resource = null
+ AbstractDb $resource = null
) {
$this->_eventPrefix = $eventPrefix;
$this->_eventObject = $eventObject;
+ $this->_idFieldName = 'entity_id';
+ $this->localeResolver = $localeResolver;
$this->_init($model, $resourceModel);
$this->setMainTable($mainTable);
- $this->_idFieldName = 'entity_id';
parent::__construct(
$entityFactory,
$logger,
@@ -65,8 +96,17 @@ public function __construct(
/**
* @inheritdoc
- *
- * @return AggregationInterface
+ */
+ protected function _initSelect()
+ {
+ parent::_initSelect();
+ $this->joinRegionNameTable();
+
+ return $this;
+ }
+
+ /**
+ * @inheritdoc
*/
public function getAggregations()
{
@@ -75,9 +115,6 @@ public function getAggregations()
/**
* @inheritdoc
- *
- * @param AggregationInterface $aggregations
- * @return $this
*/
public function setAggregations($aggregations)
{
@@ -88,7 +125,7 @@ public function setAggregations($aggregations)
/**
* Get search criteria.
*
- * @return \Magento\Framework\Api\SearchCriteriaInterface|null
+ * @return SearchCriteriaInterface|null
*/
public function getSearchCriteria()
{
@@ -98,11 +135,11 @@ public function getSearchCriteria()
/**
* Set search criteria.
*
- * @param \Magento\Framework\Api\SearchCriteriaInterface $searchCriteria
+ * @param SearchCriteriaInterface $searchCriteria
* @return $this
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
- public function setSearchCriteria(\Magento\Framework\Api\SearchCriteriaInterface $searchCriteria = null)
+ public function setSearchCriteria(SearchCriteriaInterface $searchCriteria = null)
{
return $this;
}
@@ -132,7 +169,7 @@ public function setTotalCount($totalCount)
/**
* Set items list.
*
- * @param \Magento\Framework\Api\ExtensibleDataInterface[] $items
+ * @param ExtensibleDataInterface[] $items
* @return $this
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
@@ -140,4 +177,97 @@ public function setItems(array $items = null)
{
return $this;
}
+
+ /**
+ * @inheritdoc
+ */
+ public function addFieldToFilter($field, $condition = null)
+ {
+ if ($field === 'region') {
+ $conditionSql = $this->_getConditionSql(
+ $this->getRegionNameExpresion(),
+ $condition
+ );
+ $this->getSelect()->where($conditionSql);
+ return $this;
+ }
+
+ if (is_string($field) && count(explode('.', $field)) === 1) {
+ $field = 'main_table.' . $field;
+ }
+
+ return parent::addFieldToFilter($field, $condition);
+ }
+
+ /**
+ * Add fulltext filter
+ *
+ * @param string $value
+ * @return $this
+ */
+ public function addFullTextFilter(string $value)
+ {
+ $fields = self::FIELDS_TO_FULLTEXT_SEARCH;
+ $whereCondition = '';
+ foreach ($fields as $key => $field) {
+ $field = $field === 'region'
+ ? $this->getRegionNameExpresion()
+ : 'main_table.' . $field;
+ $condition = $this->_getConditionSql(
+ $this->getConnection()->quoteIdentifier($field),
+ ['like' => "%$value%"]
+ );
+ $whereCondition .= ($key === 0 ? '' : ' OR ') . $condition;
+ }
+ if ($whereCondition) {
+ $this->getSelect()->where($whereCondition);
+ }
+
+ return $this;
+ }
+
+ /**
+ * Join region name table by current locale
+ *
+ * @return $this
+ */
+ private function joinRegionNameTable()
+ {
+ $locale = $this->localeResolver->getLocale();
+ $connection = $this->getConnection();
+ $regionIdField = $connection->quoteIdentifier('main_table.region_id');
+ $localeCondition = $connection->quoteInto("rnt.locale=?", $locale);
+
+ $this->getSelect()
+ ->joinLeft(
+ ['rct' => $this->getTable('directory_country_region')],
+ "rct.region_id={$regionIdField}",
+ []
+ )->joinLeft(
+ ['rnt' => $this->getTable('directory_country_region_name')],
+ "rnt.region_id={$regionIdField} AND {$localeCondition}",
+ ['region' => $this->getRegionNameExpresion()]
+ );
+
+ return $this;
+ }
+
+ /**
+ * Get SQL Expresion to define Region Name field by locale
+ *
+ * @return \Zend_Db_Expr
+ */
+ private function getRegionNameExpresion(): \Zend_Db_Expr
+ {
+ $connection = $this->getConnection();
+ $defaultNameExpr = $connection->getIfNullSql(
+ $connection->quoteIdentifier('rct.default_name'),
+ $connection->quoteIdentifier('main_table.region')
+ );
+
+ return $connection->getIfNullSql(
+ $connection->quoteIdentifier('rnt.name'),
+ $defaultNameExpr
+ );
+ }
}
diff --git a/app/code/Magento/Customer/Model/ResourceModel/Grid/Collection.php b/app/code/Magento/Customer/Model/ResourceModel/Grid/Collection.php
index 15678bd3dfd3f..bf8ef767063bd 100644
--- a/app/code/Magento/Customer/Model/ResourceModel/Grid/Collection.php
+++ b/app/code/Magento/Customer/Model/ResourceModel/Grid/Collection.php
@@ -3,17 +3,27 @@
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-
namespace Magento\Customer\Model\ResourceModel\Grid;
+use Magento\Customer\Model\ResourceModel\Customer;
use Magento\Customer\Ui\Component\DataProvider\Document;
use Magento\Framework\Data\Collection\Db\FetchStrategyInterface as FetchStrategy;
use Magento\Framework\Data\Collection\EntityFactoryInterface as EntityFactory;
use Magento\Framework\Event\ManagerInterface as EventManager;
+use Magento\Framework\Locale\ResolverInterface;
+use Magento\Framework\View\Element\UiComponent\DataProvider\SearchResult;
use Psr\Log\LoggerInterface as Logger;
-class Collection extends \Magento\Framework\View\Element\UiComponent\DataProvider\SearchResult
+/**
+ * Collection to present grid of customers on admin area
+ */
+class Collection extends SearchResult
{
+ /**
+ * @var ResolverInterface
+ */
+ private $localeResolver;
+
/**
* @inheritdoc
*/
@@ -25,12 +35,11 @@ class Collection extends \Magento\Framework\View\Element\UiComponent\DataProvide
protected $_map = ['fields' => ['entity_id' => 'main_table.entity_id']];
/**
- * Initialize dependencies.
- *
* @param EntityFactory $entityFactory
* @param Logger $logger
* @param FetchStrategy $fetchStrategy
* @param EventManager $eventManager
+ * @param ResolverInterface $localeResolver
* @param string $mainTable
* @param string $resourceModel
*/
@@ -39,9 +48,132 @@ public function __construct(
Logger $logger,
FetchStrategy $fetchStrategy,
EventManager $eventManager,
+ ResolverInterface $localeResolver,
$mainTable = 'customer_grid_flat',
- $resourceModel = \Magento\Customer\Model\ResourceModel\Customer::class
+ $resourceModel = Customer::class
) {
+ $this->localeResolver = $localeResolver;
parent::__construct($entityFactory, $logger, $fetchStrategy, $eventManager, $mainTable, $resourceModel);
}
+
+ /**
+ * @inheritdoc
+ */
+ protected function _initSelect()
+ {
+ parent::_initSelect();
+ $this->joinRegionNameTable();
+
+ return $this;
+ }
+
+ /**
+ * @inheritdoc
+ */
+ public function addFieldToFilter($field, $condition = null)
+ {
+ if ($field === 'billing_region') {
+ $conditionSql = $this->_getConditionSql(
+ $this->getRegionNameExpresion(),
+ $condition
+ );
+ $this->getSelect()->where($conditionSql);
+ return $this;
+ }
+
+ if (is_string($field) && count(explode('.', $field)) === 1) {
+ $field = 'main_table.' . $field;
+ }
+
+ return parent::addFieldToFilter($field, $condition);
+ }
+
+ /**
+ * Add fulltext filter
+ *
+ * @param string $value
+ * @return $this
+ */
+ public function addFullTextFilter(string $value)
+ {
+ $fields = $this->getFulltextIndexColumns();
+ $whereCondition = '';
+ foreach ($fields as $key => $field) {
+ $field = $field === 'billing_region'
+ ? $this->getRegionNameExpresion()
+ : 'main_table.' . $field;
+ $condition = $this->_getConditionSql(
+ $this->getConnection()->quoteIdentifier($field),
+ ['like' => "%$value%"]
+ );
+ $whereCondition .= ($key === 0 ? '' : ' OR ') . $condition;
+ }
+
+ if ($whereCondition) {
+ $this->getSelect()->where($whereCondition);
+ }
+
+ return $this;
+ }
+
+ /**
+ * Returns list of columns from fulltext index
+ *
+ * @return array
+ */
+ private function getFulltextIndexColumns(): array
+ {
+ $indexes = $this->getConnection()->getIndexList($this->getMainTable());
+ foreach ($indexes as $index) {
+ if (strtoupper($index['INDEX_TYPE']) == 'FULLTEXT') {
+ return $index['COLUMNS_LIST'];
+ }
+ }
+ return [];
+ }
+
+ /**
+ * Join region name table by current locale
+ *
+ * @return $this
+ */
+ private function joinRegionNameTable()
+ {
+ $locale = $this->localeResolver->getLocale();
+ $connection = $this->getConnection();
+ $regionIdField = $connection->quoteIdentifier('main_table.billing_region_id');
+ $localeCondition = $connection->quoteInto("rnt.locale=?", $locale);
+
+ $this->getSelect()
+ ->joinLeft(
+ ['rct' => $this->getTable('directory_country_region')],
+ "rct.region_id={$regionIdField}",
+ []
+ )->joinLeft(
+ ['rnt' => $this->getTable('directory_country_region_name')],
+ "rnt.region_id={$regionIdField} AND {$localeCondition}",
+ ['billing_region' => $this->getRegionNameExpresion()]
+ );
+
+ return $this;
+ }
+
+ /**
+ * Get SQL Expresion to define Region Name field by locale
+ *
+ * @return \Zend_Db_Expr
+ */
+ private function getRegionNameExpresion(): \Zend_Db_Expr
+ {
+ $connection = $this->getConnection();
+ $defaultNameExpr = $connection->getIfNullSql(
+ $connection->quoteIdentifier('rct.default_name'),
+ $connection->quoteIdentifier('main_table.billing_region')
+ );
+
+ return $connection->getIfNullSql(
+ $connection->quoteIdentifier('rnt.name'),
+ $defaultNameExpr
+ );
+ }
}
diff --git a/app/code/Magento/Customer/Test/Mftf/Data/NewCustomerData.xml b/app/code/Magento/Customer/Test/Mftf/Data/NewCustomerData.xml
index 347a04251f9cd..0a357c86ed9f8 100644
--- a/app/code/Magento/Customer/Test/Mftf/Data/NewCustomerData.xml
+++ b/app/code/Magento/Customer/Test/Mftf/Data/NewCustomerData.xml
@@ -8,18 +8,6 @@
-
- Abgar
- Abgaryan
- m@m.com
- Abgar
- Abgaryan
- Street
- Yerevan
- 9999
- 9999
- Armenia
-
John
Doe
diff --git a/app/code/Magento/Customer/Test/Mftf/Test/StorefrontLoginWithIncorrectCredentialsTest.xml b/app/code/Magento/Customer/Test/Mftf/Test/StorefrontLoginWithIncorrectCredentialsTest.xml
index 104b5d56314ba..a7dc3c7fde7f4 100644
--- a/app/code/Magento/Customer/Test/Mftf/Test/StorefrontLoginWithIncorrectCredentialsTest.xml
+++ b/app/code/Magento/Customer/Test/Mftf/Test/StorefrontLoginWithIncorrectCredentialsTest.xml
@@ -26,10 +26,14 @@
-
-
-
-
-
+
+
+
+
+
+
+
+
+
diff --git a/app/code/Magento/Customer/Test/Unit/Model/Customer/DataProviderWithDefaultAddressesTest.php b/app/code/Magento/Customer/Test/Unit/Model/Customer/DataProviderWithDefaultAddressesTest.php
index 0cb135ee66a12..fbeefb26efedb 100644
--- a/app/code/Magento/Customer/Test/Unit/Model/Customer/DataProviderWithDefaultAddressesTest.php
+++ b/app/code/Magento/Customer/Test/Unit/Model/Customer/DataProviderWithDefaultAddressesTest.php
@@ -1,5 +1,4 @@
eavConfigMock = $this->getMockBuilder(Config::class)
- ->disableOriginalConstructor()
- ->getMock();
+ $this->eavConfigMock = $this->getMockBuilder(Config::class)->disableOriginalConstructor()->getMock();
$this->customerCollectionFactoryMock = $this->createPartialMock(CustomerCollectionFactory::class, ['create']);
$this->sessionMock = $this->getMockBuilder(SessionManagerInterface::class)
->setMethods(['getCustomerFormData', 'unsCustomerFormData'])
@@ -161,20 +164,21 @@ protected function setUp(): void
],
]
);
+
$helper = new ObjectManager($this);
$this->dataProvider = $helper->getObject(
DataProviderWithDefaultAddresses::class,
[
- 'name' => 'test-name',
- 'primaryFieldName' => 'primary-field-name',
- 'requestFieldName' => 'request-field-name',
+ 'name' => 'test-name',
+ 'primaryFieldName' => 'primary-field-name',
+ 'requestFieldName' => 'request-field-name',
'customerCollectionFactory' => $this->customerCollectionFactoryMock,
- 'eavConfig' => $this->eavConfigMock,
- 'countryFactory' => $this->countryFactoryMock,
- 'session' => $this->sessionMock,
- 'fileUploaderDataResolver' => $this->fileUploaderDataResolver,
+ 'eavConfig' => $this->eavConfigMock,
+ 'countryFactory' => $this->countryFactoryMock,
+ 'session' => $this->sessionMock,
+ 'fileUploaderDataResolver' => $this->fileUploaderDataResolver,
'attributeMetadataResolver' => $this->attributeMetadataResolver,
- true
+ 'allowToShowHiddenAttributes' => true,
]
);
}
@@ -343,6 +347,7 @@ protected function getAttributeMock($options = []): array
*/
public function testGetData(): void
{
+ $customerId = 1;
$customerData = [
'email' => 'test@test.ua',
'default_billing' => 2,
@@ -350,18 +355,35 @@ public function testGetData(): void
'password_hash' => 'password_hash',
'rp_token' => 'rp_token',
];
+ $addressData = [
+ 'country_id' => 'code',
+ 'entity_id' => 2,
+ 'parent_id' => $customerId,
+ 'street' => "line 1\nline 2",
+ 'region' => 'Region Name',
+ ];
+ $localeRegionName = 'Locale Region Name';
- $address = $this->getMockBuilder(Address::class)
- ->disableOriginalConstructor()
- ->getMock();
- $this->customerCollectionMock->expects($this->once())->method('getItems')->willReturn([$this->customerMock]);
- $this->customerMock->expects($this->once())->method('getData')->willReturn($customerData);
- $this->customerMock->expects($this->atLeastOnce())->method('getId')->willReturn(1);
+ $address = $this->createMock(Address::class);
+ $address->method('getData')->willReturn($addressData);
+ $address->method('getRegion')->willReturn($localeRegionName);
+
+ $this->customerCollectionMock->method('getItems')->willReturn([$this->customerMock]);
+ $this->customerMock->method('getDefaultBillingAddress')->willReturn($address);
+ $this->customerMock->method('getDefaultShippingAddress')->willReturn(false);
+ $this->customerMock->method('getData')->willReturn($customerData);
+ $this->customerMock->method('getId')->willReturn($customerId);
- $this->customerMock->expects($this->once())->method('getDefaultBillingAddress')->willReturn($address);
- $this->countryFactoryMock->expects($this->once())->method('create')->willReturnSelf();
- $this->countryFactoryMock->expects($this->once())->method('loadByCode')->willReturnSelf();
- $this->countryFactoryMock->expects($this->once())->method('getName')->willReturn('Ukraine');
+ $this->countryFactoryMock->expects($this->once())
+ ->method('create')
+ ->willReturnSelf();
+ $this->countryFactoryMock->expects($this->once())
+ ->method('loadByCode')
+ ->with('code')
+ ->willReturnSelf();
+ $this->countryFactoryMock->expects($this->once())
+ ->method('getName')
+ ->willReturn('Ukraine');
$this->sessionMock->expects($this->once())
->method('getCustomerFormData')
@@ -369,7 +391,7 @@ public function testGetData(): void
$this->assertEquals(
[
- 1 => [
+ $customerId => [
'customer' => [
'email' => 'test@test.ua',
'default_billing' => 2,
@@ -377,9 +399,14 @@ public function testGetData(): void
],
'default_billing_address' => [
'country' => 'Ukraine',
+ 'country_id' => 'code',
+ 'entity_id' => 2,
+ 'parent_id' => $customerId,
+ 'street' => ['line 1', 'line 2'],
+ 'region' => $localeRegionName,
],
'default_shipping_address' => [],
- 'customer_id' => 1
+ 'customer_id' => $customerId
]
],
$this->dataProvider->getData()
diff --git a/app/code/Magento/Customer/Test/Unit/Model/CustomerExtractorTest.php b/app/code/Magento/Customer/Test/Unit/Model/CustomerExtractorTest.php
index 0bc45ab97e6e0..3613298ab85f2 100644
--- a/app/code/Magento/Customer/Test/Unit/Model/CustomerExtractorTest.php
+++ b/app/code/Magento/Customer/Test/Unit/Model/CustomerExtractorTest.php
@@ -121,14 +121,27 @@ protected function setUp(): void
);
}
- public function testExtract()
+ /**
+ * @param int $storeId
+ * @param int $websiteId
+ * @param array $customerData
+ * @dataProvider getDataProvider
+ * @return void
+ */
+ public function testExtract(int $storeId, int $websiteId, array $customerData)
{
- $customerData = [
- 'firstname' => 'firstname',
- 'lastname' => 'firstname',
- 'email' => 'email.example.com',
- ];
+ $this->initializeExpectation($storeId, $websiteId, $customerData);
+ $this->assertSame($this->customerData, $this->customerExtractor->extract('form-code', $this->request));
+ }
+
+ /**
+ * @param int $storeId
+ * @param int $websiteId
+ * @param array $customerData
+ */
+ private function initializeExpectation(int $storeId, int $websiteId, array $customerData): void
+ {
$this->formFactory->expects($this->once())
->method('create')
->with('customer', 'form-code')
@@ -156,17 +169,54 @@ public function testExtract()
->willReturn($this->store);
$this->store->expects($this->once())
->method('getId')
- ->willReturn(1);
+ ->willReturn($storeId);
$this->store->expects($this->once())
->method('getWebsiteId')
- ->willReturn(1);
+ ->willReturn($websiteId);
$this->customerData->expects($this->once())
->method('setWebsiteId')
- ->with(1);
+ ->with($websiteId);
$this->customerData->expects($this->once())
->method('setStoreId')
- ->with(1);
+ ->with($storeId);
+ }
- $this->assertSame($this->customerData, $this->customerExtractor->extract('form-code', $this->request));
+ /**
+ * @return array
+ */
+ public function getDataProvider()
+ {
+ return [
+ 'extract data when group id is null' => [
+ 1,
+ 1,
+ [
+ 'firstname' => 'firstname-1',
+ 'lastname' => 'firstname-1',
+ 'email' => 'email-1.example.com',
+ 'group_id' => null
+ ]
+ ],
+ 'extract data when group id is not null and default' => [
+ 1,
+ 2,
+ [
+ 'firstname' => 'firstname-2',
+ 'lastname' => 'firstname-3',
+ 'email' => 'email-2.example.com',
+ 'group_id' => 1
+ ]
+ ],
+ 'extract data when group id is different from default' => [
+ 1,
+ 1,
+ [
+ 'firstname' => 'firstname-3',
+ 'lastname' => 'firstname-3',
+ 'email' => 'email-3.example.com',
+ 'group_id' => 2
+ ]
+ ],
+ ];
}
}
diff --git a/app/code/Magento/Customer/Ui/Component/Listing/Address/DataProvider.php b/app/code/Magento/Customer/Ui/Component/Listing/Address/DataProvider.php
index c70e25ee99ec3..e26a32ec15c62 100644
--- a/app/code/Magento/Customer/Ui/Component/Listing/Address/DataProvider.php
+++ b/app/code/Magento/Customer/Ui/Component/Listing/Address/DataProvider.php
@@ -5,17 +5,20 @@
*/
namespace Magento\Customer\Ui\Component\Listing\Address;
+use Magento\Customer\Model\ResourceModel\Address\Grid\Collection as GridCollection;
use Magento\Customer\Model\ResourceModel\Address\Grid\CollectionFactory;
use Magento\Directory\Model\CountryFactory;
use Magento\Framework\Api\Filter;
+use Magento\Framework\App\RequestInterface;
+use Magento\Ui\DataProvider\AbstractDataProvider;
/**
* Custom DataProvider for customer addresses listing
*/
-class DataProvider extends \Magento\Ui\DataProvider\AbstractDataProvider
+class DataProvider extends AbstractDataProvider
{
/**
- * @var \Magento\Framework\App\RequestInterface $request,
+ * @var RequestInterface $request,
*/
private $request;
@@ -29,7 +32,7 @@ class DataProvider extends \Magento\Ui\DataProvider\AbstractDataProvider
* @param string $primaryFieldName
* @param string $requestFieldName
* @param CollectionFactory $collectionFactory
- * @param \Magento\Framework\App\RequestInterface $request
+ * @param RequestInterface $request
* @param CountryFactory $countryFactory
* @param array $meta
* @param array $data
@@ -39,7 +42,7 @@ public function __construct(
$primaryFieldName,
$requestFieldName,
CollectionFactory $collectionFactory,
- \Magento\Framework\App\RequestInterface $request,
+ RequestInterface $request,
CountryFactory $countryFactory,
array $meta = [],
array $data = []
@@ -57,6 +60,7 @@ public function __construct(
*/
public function getData(): array
{
+ /** @var GridCollection $collection */
$collection = $this->getCollection();
$data['items'] = [];
if ($this->request->getParam('parent_id')) {
@@ -80,34 +84,15 @@ public function getData(): array
*/
public function addFilter(Filter $filter): void
{
- if ($filter->getField() !== 'fulltext') {
- $this->collection->addFieldToFilter(
+ /** @var GridCollection $collection */
+ $collection = $this->getCollection();
+ if ($filter->getField() === 'fulltext') {
+ $collection->addFullTextFilter(trim($filter->getValue()));
+ } else {
+ $collection->addFieldToFilter(
$filter->getField(),
[$filter->getConditionType() => $filter->getValue()]
);
- } else {
- $value = trim($filter->getValue());
- $this->collection->addFieldToFilter(
- [
- ['attribute' => 'firstname'],
- ['attribute' => 'lastname'],
- ['attribute' => 'street'],
- ['attribute' => 'city'],
- ['attribute' => 'region'],
- ['attribute' => 'postcode'],
- ['attribute' => 'telephone']
- ],
- [
- ['like' => "%{$value}%"],
- ['like' => "%{$value}%"],
- ['like' => "%{$value}%"],
- ['like' => "%{$value}%"],
- ['like' => "%{$value}%"],
- ['like' => "%{$value}%"],
- ['like' => "%{$value}%"],
- ['like' => "%{$value}%"],
- ]
- );
}
}
}
diff --git a/app/code/Magento/Customer/Ui/Component/Listing/FulltextFilter.php b/app/code/Magento/Customer/Ui/Component/Listing/FulltextFilter.php
new file mode 100644
index 0000000000000..b6821e002f645
--- /dev/null
+++ b/app/code/Magento/Customer/Ui/Component/Listing/FulltextFilter.php
@@ -0,0 +1,34 @@
+addFullTextFilter(trim($filter->getValue()));
+ }
+}
diff --git a/app/code/Magento/Customer/etc/adminhtml/di.xml b/app/code/Magento/Customer/etc/adminhtml/di.xml
index 575fd639fa539..9f207ea8bebd1 100644
--- a/app/code/Magento/Customer/etc/adminhtml/di.xml
+++ b/app/code/Magento/Customer/etc/adminhtml/di.xml
@@ -23,4 +23,22 @@
+
+
+
+ - Magento\Framework\View\Element\UiComponent\DataProvider\RegularFilter
+ - Magento\Customer\Ui\Component\Listing\FulltextFilter
+
+
+
+
+
+ CustomerGirdFilterPool
+
+
+
+
+ CustomerGridCollectionReporting
+
+
diff --git a/app/code/Magento/Customer/etc/db_schema.xml b/app/code/Magento/Customer/etc/db_schema.xml
index 9f6d75f8ff64f..63ac8d9c1e46b 100644
--- a/app/code/Magento/Customer/etc/db_schema.xml
+++ b/app/code/Magento/Customer/etc/db_schema.xml
@@ -8,23 +8,23 @@
-
-
-
-
-
-
@@ -37,15 +37,15 @@
-
-
-
-
-
-
-
@@ -97,19 +97,19 @@
-
-
-
@@ -123,11 +123,11 @@
-
-
-
@@ -154,11 +154,11 @@
-
-
-
@@ -185,13 +185,13 @@
-
-
-
-
@@ -217,11 +217,11 @@
-
-
-
@@ -243,11 +243,11 @@
-
-
-
@@ -273,11 +273,11 @@
-
-
-
@@ -303,11 +303,11 @@
-
-
-
@@ -334,13 +334,13 @@
-
-
-
-
@@ -365,11 +365,11 @@
-
-
-
@@ -390,11 +390,11 @@
-
-
-
@@ -420,36 +420,36 @@
-
-
-
-
-
-
-
-
-
@@ -463,7 +463,7 @@
-
-
-
-
-
@@ -504,9 +504,9 @@
-
-
+
diff --git a/app/code/Magento/Customer/view/frontend/layout/customer_account_index.xml b/app/code/Magento/Customer/view/frontend/layout/customer_account_index.xml
index 4494a5dd67103..67b2c2ed02b53 100644
--- a/app/code/Magento/Customer/view/frontend/layout/customer_account_index.xml
+++ b/app/code/Magento/Customer/view/frontend/layout/customer_account_index.xml
@@ -14,7 +14,9 @@
-
+
+
+