Skip to content

Commit

Permalink
MAGETWO-40731: Merge Attribute configuration with UI listing
Browse files Browse the repository at this point in the history
  • Loading branch information
okarpenko committed Aug 5, 2015
1 parent 6187271 commit 3fd06fa
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 7 deletions.
6 changes: 5 additions & 1 deletion app/code/Magento/Customer/Model/Address.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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();
}

Expand Down
13 changes: 9 additions & 4 deletions app/code/Magento/Customer/Model/Customer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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();
}

Expand Down
42 changes: 40 additions & 2 deletions app/code/Magento/Customer/Model/Visitor.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

namespace Magento\Customer\Model;

use Magento\Framework\Indexer\StateInterface;

/**
* Class Visitor
* @package Magento\Customer\Model
Expand Down Expand Up @@ -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
Expand All @@ -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 = [],
Expand All @@ -90,6 +99,7 @@ public function __construct(
$this->ignores = $ignores;
$this->scopeConfig = $scopeConfig;
$this->dateTime = $dateTime;
$this->indexerRegistry = $indexerRegistry;
}

/**
Expand Down Expand Up @@ -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
*
Expand Down

0 comments on commit 3fd06fa

Please sign in to comment.