Пример #1
0
 public function testAddNameToSelect()
 {
     $this->_collection->addNameToSelect();
     $joinParts = $this->_collection->getSelect()->getPart(\Magento\Framework\DB\Select::FROM);
     $this->assertArrayHasKey('e', $joinParts);
     $this->assertCount(1, $joinParts);
 }
Пример #2
0
 /**
  * @param \Magento\Customer\Model\ResourceModel\Customer\Collection $subject
  * @param \Closure $proceed
  * @return \Magento\Customer\Model\ResourceModel\Customer\Collection
  */
 public function aroundAddNameToSelect(Collection $subject, \Closure $proceed)
 {
     $fields = [];
     $customerAccount = $this->fieldsetConfig->getFieldset('customer_account');
     foreach ($customerAccount as $code => $field) {
         if (isset($field['name'])) {
             $fields[$code] = $code;
         }
     }
     $connection = $subject->getConnection();
     $concatenate = [];
     if (isset($fields['prefix'])) {
         $concatenate[] = $connection->getCheckSql('{{prefix}} IS NOT NULL AND {{prefix}} != \'\'', $connection->getConcatSql(['LTRIM(RTRIM({{prefix}}))', '\' \'']), '\'\'');
     }
     if ($this->localeResolver->getLocale() != 'ja_JP') {
         $concatenate[] = 'LTRIM(RTRIM({{firstname}}))';
     } else {
         $concatenate[] = 'LTRIM(RTRIM({{lastname}}))';
     }
     $concatenate[] = '\' \'';
     if (isset($fields['middlename'])) {
         $concatenate[] = $connection->getCheckSql('{{middlename}} IS NOT NULL AND {{middlename}} != \'\'', $connection->getConcatSql(['LTRIM(RTRIM({{middlename}}))', '\' \'']), '\'\'');
     }
     if ($this->localeResolver->getLocale() != 'ja_JP') {
         $concatenate[] = 'LTRIM(RTRIM({{lastname}}))';
     } else {
         $concatenate[] = 'LTRIM(RTRIM({{firstname}}))';
     }
     if (isset($fields['suffix'])) {
         $concatenate[] = $connection->getCheckSql('{{suffix}} IS NOT NULL AND {{suffix}} != \'\'', $connection->getConcatSql(['\' \'', 'LTRIM(RTRIM({{suffix}}))']), '\'\'');
     }
     $nameExpr = $connection->getConcatSql($concatenate);
     $subject->addExpressionAttributeToSelect('name', $nameExpr, $fields);
     return $subject;
 }
Пример #3
0
 /**
  * Get data
  *
  * @return array
  */
 public function getData()
 {
     if (isset($this->loadedData)) {
         return $this->loadedData;
     }
     $items = $this->collection->getItems();
     /** @var Customer $customer */
     foreach ($items as $customer) {
         $result['customer'] = $customer->getData();
         unset($result['address']);
         /** @var Address $address */
         foreach ($customer->getAddresses() as $address) {
             $addressId = $address->getId();
             $address->load($addressId);
             $result['address'][$addressId] = $address->getData();
             $this->prepareAddressData($addressId, $result['address'], $result['customer']);
         }
         $this->loadedData[$customer->getId()] = $result;
     }
     $data = $this->getSession()->getCustomerFormData();
     if (!empty($data)) {
         $customerId = isset($data['customer']['entity_id']) ? $data['customer']['entity_id'] : null;
         $this->loadedData[$customerId] = $data;
         $this->getSession()->unsCustomerFormData();
     }
     return $this->loadedData;
 }
 public function testExecuteWithException()
 {
     $customersIds = [10, 11, 12];
     $this->customerCollectionMock->expects($this->any())->method('getAllIds')->willReturn($customersIds);
     $this->customerRepositoryMock->expects($this->any())->method('getById')->willThrowException(new \Exception('Some message.'));
     $this->messageManagerMock->expects($this->once())->method('addError')->with('Some message.');
     $this->massAction->execute();
 }
 /**
  * @inheritdoc
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $this->collection->addAttributeToSelect('*');
     $customerCollection = $this->collection->getItems();
     /** @var $customer Customer */
     foreach ($customerCollection as $customer) {
         $customer->load($customer->getId());
         if (!$this->encryptor->validateHashVersion($customer->getPasswordHash())) {
             list($hash, $salt, $version) = explode(Encryptor::DELIMITER, $customer->getPasswordHash(), 3);
             $version .= Encryptor::DELIMITER . Encryptor::HASH_VERSION_LATEST;
             $customer->setPasswordHash($this->encryptor->getHash($hash, $salt, $version));
             $customer->save();
             $output->write(".");
         }
     }
     $output->writeln(".");
     $output->writeln("<info>Finished</info>");
 }
Пример #6
0
 /**
  * Initialize existent customers data
  *
  * @return $this
  */
 protected function _initCustomers()
 {
     if (empty($this->_customers)) {
         // add customer default addresses column name to customer attribute mapping array
         $this->_customerCollection->addAttributeToSelect(self::$_defaultAddressAttributeMapping);
         // filter customer collection
         $this->_customerCollection = $this->_customerEntity->filterEntityCollection($this->_customerCollection);
         $customers = [];
         $addCustomer = function (\Magento\Customer\Model\Customer $customer) use(&$customers) {
             $customers[$customer->getId()] = $customer->getData();
         };
         $this->_byPagesIterator->iterate($this->_customerCollection, $this->_pageSize, [$addCustomer]);
         $this->_customers = $customers;
     }
     return $this;
 }
Пример #7
0
 /**
  * Get data
  *
  * @return array
  */
 public function getData()
 {
     if (isset($this->loadedData)) {
         return $this->loadedData;
     }
     $items = $this->collection->getItems();
     /** @var Customer $customer */
     foreach ($items as $customer) {
         $result['customer'] = $customer->getData();
         unset($result['address']);
         /** @var Address $address */
         foreach ($customer->getAddresses() as $address) {
             $addressId = $address->getId();
             $address->load($addressId);
             $result['address'][$addressId] = $address->getData();
             $this->prepareAddressData($addressId, $result['address'], $result['customer']);
         }
         $this->loadedData[$customer->getId()] = $result;
     }
     return $this->loadedData;
 }
 /**
  * Helper function that adds a FilterGroup to the collection.
  *
  * @param \Magento\Framework\Api\Search\FilterGroup $filterGroup
  * @param \Magento\Customer\Model\ResourceModel\Customer\Collection $collection
  * @return void
  * @throws \Magento\Framework\Exception\InputException
  */
 protected function addFilterGroupToCollection(\Magento\Framework\Api\Search\FilterGroup $filterGroup, \Magento\Customer\Model\ResourceModel\Customer\Collection $collection)
 {
     $fields = [];
     $conditions = [];
     foreach ($filterGroup->getFilters() as $filter) {
         $condition = $filter->getConditionType() ? $filter->getConditionType() : 'eq';
         $fields[] = ['attribute' => $filter->getField(), $condition => $filter->getValue()];
     }
     if ($fields) {
         $collection->addFieldToFilter($fields, $conditions);
     }
 }
Пример #9
0
 /**
  * @param \Magento\Framework\Data\Collection\EntityFactory $entityFactory
  * @param \Psr\Log\LoggerInterface $logger
  * @param \Magento\Framework\Data\Collection\Db\FetchStrategyInterface $fetchStrategy
  * @param \Magento\Framework\Event\ManagerInterface $eventManager
  * @param \Magento\Eav\Model\Config $eavConfig
  * @param \Magento\Framework\App\ResourceConnection $resource
  * @param \Magento\Eav\Model\EntityFactory $eavEntityFactory
  * @param \Magento\Eav\Model\ResourceModel\Helper $resourceHelper
  * @param \Magento\Framework\Validator\UniversalFactory $universalFactory
  * @param \Magento\Framework\Model\ResourceModel\Db\VersionControl\Snapshot $entitySnapshot
  * @param \Magento\Framework\DataObject\Copy\Config $fieldsetConfig
  * @param \Magento\Quote\Model\QuoteRepository $quoteRepository
  * @param \Magento\Quote\Model\ResourceModel\Quote\Item\CollectionFactory $quoteItemFactory
  * @param \Magento\Sales\Model\ResourceModel\Order\Collection $orderResource
  * @param mixed $connection
  * @param string $modelName
  *
  * @SuppressWarnings(PHPMD.ExcessiveParameterList)
  */
 public function __construct(\Magento\Framework\Data\Collection\EntityFactory $entityFactory, \Psr\Log\LoggerInterface $logger, \Magento\Framework\Data\Collection\Db\FetchStrategyInterface $fetchStrategy, \Magento\Framework\Event\ManagerInterface $eventManager, \Magento\Eav\Model\Config $eavConfig, \Magento\Framework\App\ResourceConnection $resource, \Magento\Eav\Model\EntityFactory $eavEntityFactory, \Magento\Eav\Model\ResourceModel\Helper $resourceHelper, \Magento\Framework\Validator\UniversalFactory $universalFactory, \Magento\Framework\Model\ResourceModel\Db\VersionControl\Snapshot $entitySnapshot, \Magento\Framework\DataObject\Copy\Config $fieldsetConfig, \Magento\Quote\Model\QuoteRepository $quoteRepository, \Magento\Quote\Model\ResourceModel\Quote\Item\CollectionFactory $quoteItemFactory, \Magento\Sales\Model\ResourceModel\Order\Collection $orderResource, \Magento\Framework\DB\Adapter\AdapterInterface $connection = null, $modelName = self::CUSTOMER_MODEL_NAME)
 {
     parent::__construct($entityFactory, $logger, $fetchStrategy, $eventManager, $eavConfig, $resource, $eavEntityFactory, $resourceHelper, $universalFactory, $entitySnapshot, $fieldsetConfig, $connection, $modelName);
     $this->orderResource = $orderResource;
     $this->quoteRepository = $quoteRepository;
     $this->_quoteItemFactory = $quoteItemFactory;
 }
Пример #10
0
 /**
  * @return $this
  */
 protected function _initSelect()
 {
     parent::_initSelect();
     $this->addNameToSelect()->addAttributeToSelect('email')->addAttributeToSelect('created_at')->joinAttribute('billing_postcode', 'customer_address/postcode', 'default_billing', null, 'left')->joinAttribute('billing_city', 'customer_address/city', 'default_billing', null, 'left')->joinAttribute('billing_telephone', 'customer_address/telephone', 'default_billing', null, 'left')->joinAttribute('billing_regione', 'customer_address/region', 'default_billing', null, 'left')->joinAttribute('billing_country_id', 'customer_address/country_id', 'default_billing', null, 'left')->joinField('store_name', 'store', 'name', 'store_id=store_id', null, 'left')->joinField('website_name', 'store_website', 'name', 'website_id=website_id', null, 'left');
     return $this;
 }