Skip to content

Commit 3fd06fa

Browse files
author
okarpenko
committed
MAGETWO-40731: Merge Attribute configuration with UI listing
1 parent 6187271 commit 3fd06fa

File tree

3 files changed

+54
-7
lines changed

3 files changed

+54
-7
lines changed

app/code/Magento/Customer/Model/Address.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use Magento\Customer\Api\Data\AddressInterfaceFactory;
1010
use Magento\Customer\Api\Data\AddressInterface;
1111
use Magento\Customer\Api\Data\RegionInterfaceFactory;
12+
use Magento\Framework\Indexer\StateInterface;
1213

1314
/**
1415
* Customer address model
@@ -317,7 +318,10 @@ public function getEntityTypeId()
317318
*/
318319
public function afterSave()
319320
{
320-
$this->_getResource()->addCommitCallback([$this, 'reindex']);
321+
$indexer = $this->indexerRegistry->get(Customer::CUSTOMER_GRID_INDEXER_ID);
322+
if ($indexer->getState()->getStatus() !== StateInterface::STATUS_INVALID) {
323+
$this->_getResource()->addCommitCallback([$this, 'reindex']);
324+
}
321325
return parent::afterSave();
322326
}
323327

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

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use Magento\Framework\Exception\EmailNotConfirmedException;
1717
use Magento\Framework\Exception\InvalidEmailOrPasswordException;
1818
use Magento\Framework\Exception\AuthenticationException;
19+
use Magento\Framework\Indexer\StateInterface;
1920

2021
/**
2122
* Customer model
@@ -210,22 +211,23 @@ class Customer extends \Magento\Framework\Model\AbstractModel
210211
* @param \Magento\Framework\Registry $registry
211212
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
212213
* @param \Magento\Eav\Model\Config $config
213-
* @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
214+
* @param ScopeConfigInterface $scopeConfig
214215
* @param ResourceCustomer $resource
215216
* @param Share $configShare
216217
* @param AddressFactory $addressFactory
217218
* @param CollectionFactory $addressesFactory
218219
* @param \Magento\Framework\Mail\Template\TransportBuilder $transportBuilder
219220
* @param GroupRepositoryInterface $groupRepository
220-
* @param AttributeFactory $attributeFactory
221221
* @param \Magento\Framework\Encryption\EncryptorInterface $encryptor
222222
* @param \Magento\Framework\Stdlib\DateTime $dateTime
223223
* @param CustomerInterfaceFactory $customerDataFactory
224224
* @param DataObjectProcessor $dataObjectProcessor
225225
* @param \Magento\Framework\Api\DataObjectHelper $dataObjectHelper
226226
* @param CustomerMetadataInterface $metadataService
227-
* @param \Magento\Framework\Data\Collection\AbstractDb $resourceCollection
227+
* @param \Magento\Framework\Indexer\IndexerRegistry $indexerRegistry
228+
* @param \Magento\Framework\Data\Collection\AbstractDb|null $resourceCollection
228229
* @param array $data
230+
*
229231
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
230232
*/
231233
public function __construct(
@@ -1085,7 +1087,10 @@ public function beforeDelete()
10851087
*/
10861088
public function afterSave()
10871089
{
1088-
$this->_getResource()->addCommitCallback([$this, 'reindex']);
1090+
$indexer = $this->indexerRegistry->get(self::CUSTOMER_GRID_INDEXER_ID);
1091+
if ($indexer->getState()->getStatus() !== StateInterface::STATUS_INVALID) {
1092+
$this->_getResource()->addCommitCallback([$this, 'reindex']);
1093+
}
10891094
return parent::afterSave();
10901095
}
10911096

app/code/Magento/Customer/Model/Visitor.php

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
namespace Magento\Customer\Model;
88

9+
use Magento\Framework\Indexer\StateInterface;
10+
911
/**
1012
* Class Visitor
1113
* @package Magento\Customer\Model
@@ -55,15 +57,21 @@ class Visitor extends \Magento\Framework\Model\AbstractModel
5557
*/
5658
protected $dateTime;
5759

60+
/**
61+
* @var \Magento\Framework\Indexer\IndexerRegistry
62+
*/
63+
protected $indexerRegistry;
64+
5865
/**
5966
* @param \Magento\Framework\Model\Context $context
6067
* @param \Magento\Framework\Registry $registry
6168
* @param \Magento\Framework\Session\SessionManagerInterface $session
6269
* @param \Magento\Framework\HTTP\Header $httpHeader
63-
* @param \Magento\Framework\Model\Resource\AbstractResource $resource
64-
* @param \Magento\Framework\Data\Collection\AbstractDb $resourceCollection
6570
* @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
6671
* @param \Magento\Framework\Stdlib\DateTime $dateTime
72+
* @param \Magento\Framework\Indexer\IndexerRegistry $indexerRegistry
73+
* @param \Magento\Framework\Model\Resource\AbstractResource|null $resource
74+
* @param \Magento\Framework\Data\Collection\AbstractDb|null $resourceCollection
6775
* @param array $ignoredUserAgents
6876
* @param array $ignores
6977
* @param array $data
@@ -77,6 +85,7 @@ public function __construct(
7785
\Magento\Framework\HTTP\Header $httpHeader,
7886
\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig,
7987
\Magento\Framework\Stdlib\DateTime $dateTime,
88+
\Magento\Framework\Indexer\IndexerRegistry $indexerRegistry,
8089
\Magento\Framework\Model\Resource\AbstractResource $resource = null,
8190
\Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null,
8291
array $ignoredUserAgents = [],
@@ -90,6 +99,7 @@ public function __construct(
9099
$this->ignores = $ignores;
91100
$this->scopeConfig = $scopeConfig;
92101
$this->dateTime = $dateTime;
102+
$this->indexerRegistry = $indexerRegistry;
93103
}
94104

95105
/**
@@ -149,6 +159,34 @@ public function initByRequest($observer)
149159
return $this;
150160
}
151161

162+
/**
163+
* Processing object after save data
164+
*
165+
* @return $this
166+
*/
167+
public function afterSave()
168+
{
169+
$indexer = $this->indexerRegistry->get(Customer::CUSTOMER_GRID_INDEXER_ID);
170+
if ($indexer->getState()->getStatus() !== StateInterface::STATUS_INVALID) {
171+
$this->_getResource()->addCommitCallback([$this, 'reindex']);
172+
}
173+
return parent::afterSave();
174+
}
175+
176+
/**
177+
* Init indexing process after visitor save
178+
*
179+
* @return void
180+
*/
181+
public function reindex()
182+
{
183+
if ($this->getCustomerId()) {
184+
/** @var \Magento\Framework\Indexer\IndexerInterface $indexer */
185+
$indexer = $this->indexerRegistry->get(Customer::CUSTOMER_GRID_INDEXER_ID);
186+
$indexer->reindexRow($this->getCustomerId());
187+
}
188+
}
189+
152190
/**
153191
* Save visitor by request
154192
*

0 commit comments

Comments
 (0)