diff --git a/app/code/Magento/Customer/Model/Address.php b/app/code/Magento/Customer/Model/Address.php index 9ea44f30fe1d6..cea536df75921 100644 --- a/app/code/Magento/Customer/Model/Address.php +++ b/app/code/Magento/Customer/Model/Address.php @@ -9,6 +9,7 @@ use Magento\Customer\Api\Data\AddressInterfaceFactory; use Magento\Customer\Api\Data\AddressInterface; use Magento\Customer\Api\Data\RegionInterfaceFactory; +use Magento\Framework\Indexer\StateInterface; /** * Customer address model @@ -317,7 +318,10 @@ public function getEntityTypeId() */ public function afterSave() { - $this->_getResource()->addCommitCallback([$this, 'reindex']); + $indexer = $this->indexerRegistry->get(Customer::CUSTOMER_GRID_INDEXER_ID); + if ($indexer->getState()->getStatus() !== StateInterface::STATUS_INVALID) { + $this->_getResource()->addCommitCallback([$this, 'reindex']); + } return parent::afterSave(); } diff --git a/app/code/Magento/Customer/Model/Customer.php b/app/code/Magento/Customer/Model/Customer.php index 1d21b5ff8e0d3..04c6e568ee14c 100644 --- a/app/code/Magento/Customer/Model/Customer.php +++ b/app/code/Magento/Customer/Model/Customer.php @@ -16,6 +16,7 @@ use Magento\Framework\Exception\EmailNotConfirmedException; use Magento\Framework\Exception\InvalidEmailOrPasswordException; use Magento\Framework\Exception\AuthenticationException; +use Magento\Framework\Indexer\StateInterface; /** * Customer model @@ -210,22 +211,23 @@ class Customer extends \Magento\Framework\Model\AbstractModel * @param \Magento\Framework\Registry $registry * @param \Magento\Store\Model\StoreManagerInterface $storeManager * @param \Magento\Eav\Model\Config $config - * @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig + * @param ScopeConfigInterface $scopeConfig * @param ResourceCustomer $resource * @param Share $configShare * @param AddressFactory $addressFactory * @param CollectionFactory $addressesFactory * @param \Magento\Framework\Mail\Template\TransportBuilder $transportBuilder * @param GroupRepositoryInterface $groupRepository - * @param AttributeFactory $attributeFactory * @param \Magento\Framework\Encryption\EncryptorInterface $encryptor * @param \Magento\Framework\Stdlib\DateTime $dateTime * @param CustomerInterfaceFactory $customerDataFactory * @param DataObjectProcessor $dataObjectProcessor * @param \Magento\Framework\Api\DataObjectHelper $dataObjectHelper * @param CustomerMetadataInterface $metadataService - * @param \Magento\Framework\Data\Collection\AbstractDb $resourceCollection + * @param \Magento\Framework\Indexer\IndexerRegistry $indexerRegistry + * @param \Magento\Framework\Data\Collection\AbstractDb|null $resourceCollection * @param array $data + * * @SuppressWarnings(PHPMD.ExcessiveParameterList) */ public function __construct( @@ -1085,7 +1087,10 @@ public function beforeDelete() */ public function afterSave() { - $this->_getResource()->addCommitCallback([$this, 'reindex']); + $indexer = $this->indexerRegistry->get(self::CUSTOMER_GRID_INDEXER_ID); + if ($indexer->getState()->getStatus() !== StateInterface::STATUS_INVALID) { + $this->_getResource()->addCommitCallback([$this, 'reindex']); + } return parent::afterSave(); } diff --git a/app/code/Magento/Customer/Model/Resource/Customer/Grid/ServiceCollection.php b/app/code/Magento/Customer/Model/Resource/Customer/Grid/ServiceCollection.php deleted file mode 100644 index de8f7aa1bf338..0000000000000 --- a/app/code/Magento/Customer/Model/Resource/Customer/Grid/ServiceCollection.php +++ /dev/null @@ -1,104 +0,0 @@ -customerRepository = $customerRepository; - } - - /** - * {@inheritdoc} - */ - public function loadData($printQuery = false, $logQuery = false) - { - if (!$this->isLoaded()) { - $searchCriteria = $this->getSearchCriteria(); - $searchResults = $this->customerRepository->getList($searchCriteria); - $this->_totalRecords = $searchResults->getTotalCount(); - /** @var CustomerInterface[] $customers */ - $customers = $searchResults->getItems(); - foreach ($customers as $customer) { - $this->_addItem($this->createCustomerItem($customer)); - } - $this->_setIsLoaded(); - } - return $this; - } - - /** - * Creates a collection item that represents a customer for the customer Grid. - * - * @param CustomerInterface $customer Input data for creating the item. - * @return \Magento\Framework\DataObject Collection item that represents a customer - */ - protected function createCustomerItem(CustomerInterface $customer) - { - $customerNameParts = [ - $customer->getPrefix(), - $customer->getFirstname(), - $customer->getMiddlename(), - $customer->getLastname(), - $customer->getSuffix(), - ]; - $customerItem = new \Magento\Framework\DataObject(); - $customerItem->setId($customer->getId()); - $customerItem->setEntityId($customer->getId()); - // All parts of the customer name must be displayed in the name column of the grid - $customerItem->setName(implode(' ', array_filter($customerNameParts))); - $customerItem->setEmail($customer->getEmail()); - $customerItem->setWebsiteId($customer->getWebsiteId()); - $customerItem->setCreatedAt($customer->getCreatedAt()); - $customerItem->setGroupId($customer->getGroupId()); - - $billingAddress = null; - foreach ($customer->getAddresses() as $address) { - if ($address->isDefaultBilling()) { - $billingAddress = $address; - break; - } - } - if ($billingAddress !== null) { - $customerItem->setBillingTelephone($billingAddress->getTelephone()); - $customerItem->setBillingPostcode($billingAddress->getPostcode()); - $customerItem->setBillingCountryId($billingAddress->getCountryId()); - $region = $billingAddress->getRegion() === null ? '' : $billingAddress->getRegion()->getRegion(); - $customerItem->setBillingRegion($region); - } - return $customerItem; - } -} diff --git a/app/code/Magento/Customer/Model/Visitor.php b/app/code/Magento/Customer/Model/Visitor.php index 681713b895c65..c3e9dced54a5b 100644 --- a/app/code/Magento/Customer/Model/Visitor.php +++ b/app/code/Magento/Customer/Model/Visitor.php @@ -6,6 +6,8 @@ namespace Magento\Customer\Model; +use Magento\Framework\Indexer\StateInterface; + /** * Class Visitor * @package Magento\Customer\Model @@ -55,15 +57,21 @@ class Visitor extends \Magento\Framework\Model\AbstractModel */ protected $dateTime; + /** + * @var \Magento\Framework\Indexer\IndexerRegistry + */ + protected $indexerRegistry; + /** * @param \Magento\Framework\Model\Context $context * @param \Magento\Framework\Registry $registry * @param \Magento\Framework\Session\SessionManagerInterface $session * @param \Magento\Framework\HTTP\Header $httpHeader - * @param \Magento\Framework\Model\Resource\AbstractResource $resource - * @param \Magento\Framework\Data\Collection\AbstractDb $resourceCollection * @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig * @param \Magento\Framework\Stdlib\DateTime $dateTime + * @param \Magento\Framework\Indexer\IndexerRegistry $indexerRegistry + * @param \Magento\Framework\Model\Resource\AbstractResource|null $resource + * @param \Magento\Framework\Data\Collection\AbstractDb|null $resourceCollection * @param array $ignoredUserAgents * @param array $ignores * @param array $data @@ -77,6 +85,7 @@ public function __construct( \Magento\Framework\HTTP\Header $httpHeader, \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig, \Magento\Framework\Stdlib\DateTime $dateTime, + \Magento\Framework\Indexer\IndexerRegistry $indexerRegistry, \Magento\Framework\Model\Resource\AbstractResource $resource = null, \Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null, array $ignoredUserAgents = [], @@ -90,6 +99,7 @@ public function __construct( $this->ignores = $ignores; $this->scopeConfig = $scopeConfig; $this->dateTime = $dateTime; + $this->indexerRegistry = $indexerRegistry; } /** @@ -149,6 +159,34 @@ public function initByRequest($observer) return $this; } + /** + * Processing object after save data + * + * @return $this + */ + public function afterSave() + { + $indexer = $this->indexerRegistry->get(Customer::CUSTOMER_GRID_INDEXER_ID); + if ($indexer->getState()->getStatus() !== StateInterface::STATUS_INVALID) { + $this->_getResource()->addCommitCallback([$this, 'reindex']); + } + return parent::afterSave(); + } + + /** + * Init indexing process after visitor save + * + * @return void + */ + public function reindex() + { + if ($this->getCustomerId()) { + /** @var \Magento\Framework\Indexer\IndexerInterface $indexer */ + $indexer = $this->indexerRegistry->get(Customer::CUSTOMER_GRID_INDEXER_ID); + $indexer->reindexRow($this->getCustomerId()); + } + } + /** * Save visitor by request * diff --git a/app/code/Magento/Customer/Ui/Component/FilterFactory.php b/app/code/Magento/Customer/Ui/Component/FilterFactory.php index b33a07f757efb..c9bc2b3cd6bfe 100644 --- a/app/code/Magento/Customer/Ui/Component/FilterFactory.php +++ b/app/code/Magento/Customer/Ui/Component/FilterFactory.php @@ -44,7 +44,7 @@ public function create($attribute, $context) 'label' => __($attribute->getFrontendLabel()), ]; if ($attribute->getOptions()) { - $config['options'] = $attribute->getOptions(); + $config['options'] = $this->getOptionsArray($attribute); $config['caption'] = __('Select...'); } $arguments = [ @@ -57,6 +57,25 @@ public function create($attribute, $context) return $this->componentFactory->create($columnName, $this->getFilterType($attribute), $arguments); } + /** + * @param \Magento\Customer\Api\Data\AttributeMetadataInterface $attribute + * @return array + */ + protected function getOptionsArray($attribute) + { + $options = []; + foreach ($attribute->getOptions() as $option) { + array_push( + $options, + [ + 'value' => $option->getValue(), + 'label' => $option->getLabel() + ] + ); + } + return $options; + } + /** * @param \Magento\Customer\Api\Data\AttributeMetadataInterface $attribute * @return string diff --git a/app/code/Magento/Customer/Ui/Component/Listing/AttributeRepository.php b/app/code/Magento/Customer/Ui/Component/Listing/AttributeRepository.php index b63319a7f582a..2a7cd21971cbb 100644 --- a/app/code/Magento/Customer/Ui/Component/Listing/AttributeRepository.php +++ b/app/code/Magento/Customer/Ui/Component/Listing/AttributeRepository.php @@ -34,7 +34,7 @@ class AttributeRepository protected $customerMetadata; /** - * @var \Magento\Customer\Api\AddressMetadataInterface + * @var \Magento\Customer\Model\Metadata\AddressMetadata */ protected $addressMetadata; @@ -42,13 +42,13 @@ class AttributeRepository * @param \Magento\Customer\Model\Resource\Attribute\Collection $attributeCollection * @param \Magento\Customer\Model\Resource\Address\Attribute\Collection $addressAttributeCollection * @param \Magento\Customer\Model\Metadata\CustomerMetadata $customerMetadata - * @param AddressMetadataInterface $addressMetadata + * @param \Magento\Customer\Model\Metadata\AddressMetadata $addressMetadata */ public function __construct( \Magento\Customer\Model\Resource\Attribute\Collection $attributeCollection, \Magento\Customer\Model\Resource\Address\Attribute\Collection $addressAttributeCollection, \Magento\Customer\Model\Metadata\CustomerMetadata $customerMetadata, - \Magento\Customer\Api\AddressMetadataInterface $addressMetadata + \Magento\Customer\Model\Metadata\AddressMetadata $addressMetadata ) { $this->attributeCollection = $attributeCollection; $this->addressAttributeCollection = $addressAttributeCollection; diff --git a/app/code/Magento/Customer/Ui/Component/Listing/Columns.php b/app/code/Magento/Customer/Ui/Component/Listing/Columns.php index f820211469530..4d53645505ba4 100644 --- a/app/code/Magento/Customer/Ui/Component/Listing/Columns.php +++ b/app/code/Magento/Customer/Ui/Component/Listing/Columns.php @@ -96,6 +96,7 @@ public function addColumn(AttributeMetadataInterface $attribute) { $config['sortOrder'] = ++$this->columnSortOrder; $column = $this->columnFactory->create($attribute, $this->getContext(), $config); + $column->prepare(); $this->addComponent($attribute->getAttributeCode(), $column); } diff --git a/app/code/Magento/Indexer/etc/di.xml b/app/code/Magento/Indexer/etc/di.xml index c2706d5eba041..b3b3275dbed8c 100644 --- a/app/code/Magento/Indexer/etc/di.xml +++ b/app/code/Magento/Indexer/etc/di.xml @@ -10,7 +10,7 @@ - + diff --git a/app/code/Magento/Indexer/Test/Unit/Model/Indexer/Table/StrategyTest.php b/lib/internal/Magento/Framework/Indexer/Test/Unit/StrategyTest.php similarity index 97% rename from app/code/Magento/Indexer/Test/Unit/Model/Indexer/Table/StrategyTest.php rename to lib/internal/Magento/Framework/Indexer/Test/Unit/StrategyTest.php index 6481197921768..5fcf1a03d3109 100644 --- a/app/code/Magento/Indexer/Test/Unit/Model/Indexer/Table/StrategyTest.php +++ b/lib/internal/Magento/Framework/Indexer/Test/Unit/StrategyTest.php @@ -3,7 +3,7 @@ * Copyright © 2015 Magento. All rights reserved. * See COPYING.txt for license details. */ -namespace Magento\Indexer\Test\Unit\Model\Indexer\Table; +namespace Magento\Framework\Indexer\Test\Unit\Table; /** * Class StrategyTest diff --git a/lib/internal/Magento/Framework/View/Element/UiComponentFactory.php b/lib/internal/Magento/Framework/View/Element/UiComponentFactory.php index 4dfc2ea09e6a3..f7267a3cb002a 100644 --- a/lib/internal/Magento/Framework/View/Element/UiComponentFactory.php +++ b/lib/internal/Magento/Framework/View/Element/UiComponentFactory.php @@ -144,7 +144,7 @@ public function create($identifier, $name = null, array $arguments = []) $identifier, $bundleComponents[$identifier] ); - $componentArguments = array_merge($componentArguments, $arguments); + $componentArguments = array_replace_recursive($componentArguments, $arguments); if (!isset($componentArguments['context'])) { $componentArguments['context'] = $this->contextFactory->create([ 'namespace' => $identifier @@ -164,7 +164,10 @@ public function create($identifier, $name = null, array $arguments = []) $componentArguments['components'] = $components; /** @var \Magento\Framework\View\Element\UiComponentInterface $component */ - $component = $this->objectManager->create($className, array_merge($componentArguments, $arguments)); + $component = $this->objectManager->create( + $className, + array_replace_recursive($componentArguments, $arguments) + ); return $component; } else { @@ -173,7 +176,7 @@ public function create($identifier, $name = null, array $arguments = []) /** @var \Magento\Framework\View\Element\UiComponentInterface $component */ $component = $this->objectManager->create( $className, - array_merge($componentArguments, $arguments) + array_replace_recursive($componentArguments, $arguments) ); return $component;