Esempio n. 1
0
 public function testAddNameToSelect()
 {
     $this->_collection->addNameToSelect();
     $joinParts = $this->_collection->getSelect()->getPart(\Zend_Db_Select::FROM);
     $this->assertArrayHasKey('e', $joinParts);
     $this->assertCount(1, $joinParts);
 }
 public function testAddNameToSelect()
 {
     $this->_collection->addNameToSelect();
     $joinParts = $this->_collection->getSelect()->getPart(\Zend_Db_Select::FROM);
     $this->assertArrayHasKey('at_prefix', $joinParts);
     $this->assertArrayHasKey('at_firstname', $joinParts);
     $this->assertArrayHasKey('at_middlename', $joinParts);
     $this->assertArrayHasKey('at_lastname', $joinParts);
     $this->assertArrayHasKey('at_suffix', $joinParts);
 }
Esempio n. 3
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\Resource $resource
  * @param \Magento\Eav\Model\EntityFactory $eavEntityFactory
  * @param \Magento\Eav\Model\Resource\Helper $resourceHelper
  * @param \Magento\Framework\Validator\UniversalFactory $universalFactory
  * @param \Magento\Framework\Object\Copy\Config $fieldsetConfig
  * @param \Magento\Quote\Model\QuoteRepository $quoteRepository
  * @param \Magento\Quote\Model\Resource\Quote\Item\CollectionFactory $quoteItemFactory
  * @param \Magento\Sales\Model\Resource\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\Resource $resource, \Magento\Eav\Model\EntityFactory $eavEntityFactory, \Magento\Eav\Model\Resource\Helper $resourceHelper, \Magento\Framework\Validator\UniversalFactory $universalFactory, \Magento\Framework\Object\Copy\Config $fieldsetConfig, \Magento\Quote\Model\QuoteRepository $quoteRepository, \Magento\Quote\Model\Resource\Quote\Item\CollectionFactory $quoteItemFactory, \Magento\Sales\Model\Resource\Order\Collection $orderResource, $connection = null, $modelName = self::CUSTOMER_MODEL_NAME)
 {
     parent::__construct($entityFactory, $logger, $fetchStrategy, $eventManager, $eavConfig, $resource, $eavEntityFactory, $resourceHelper, $universalFactory, $fieldsetConfig, $connection, $modelName);
     $this->orderResource = $orderResource;
     $this->quoteRepository = $quoteRepository;
     $this->_quoteItemFactory = $quoteItemFactory;
 }
Esempio n. 4
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;
 }
Esempio n. 5
0
 /**
  * Retrieve count of loaded items
  *
  * @return int
  */
 public function count()
 {
     return $this->collection->count();
 }
 /**
  * Helper function that adds a FilterGroup to the collection.
  *
  * @param FilterGroup $filterGroup
  * @param Collection $collection
  * @return void
  * @throws \Magento\Framework\Exception\InputException
  */
 protected function addFilterGroupToCollection(FilterGroup $filterGroup, Collection $collection)
 {
     $fields = [];
     $conditions = [];
     foreach ($filterGroup->getFilters() as $filter) {
         $condition = $filter->getConditionType() ? $filter->getConditionType() : 'eq';
         $fields[] = array('attribute' => $filter->getField(), $condition => $filter->getValue());
     }
     if ($fields) {
         $collection->addFieldToFilter($fields, $conditions);
     }
 }
 /**
  * Helper function that adds a FilterGroup to the collection.
  *
  * @param \Magento\Framework\Api\Search\FilterGroup $filterGroup
  * @param \Magento\Customer\Model\Resource\Customer\Collection $collection
  * @return void
  * @throws \Magento\Framework\Exception\InputException
  */
 protected function addFilterGroupToCollection(\Magento\Framework\Api\Search\FilterGroup $filterGroup, \Magento\Customer\Model\Resource\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);
     }
 }
Esempio n. 8
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');
     return $this;
 }
Esempio n. 9
0
 /**
  * Retrieve count of loaded items
  *
  * @return int
  */
 public function count()
 {
     $this->filterPool->applyFilters($this->collection);
     return $this->collection->count();
 }
 /**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $this->_state->setAreaCode('crontab');
     $indexersData = $this->indexerCollection->getItems();
     if (!is_null($input->getOption(self::INPUT_KEY_MAX_PRODUCTS))) {
         $productsNum = $input->getOption(self::INPUT_KEY_MAX_PRODUCTS);
     } else {
         $productsNum = $this->productCollection->getSize();
     }
     if (!is_null($input->getOption(self::INPUT_KEY_MAX_CATEGORIES))) {
         $categoriesNum = $input->getOption(self::INPUT_KEY_MAX_CATEGORIES);
     } else {
         $categoriesNum = $this->categoryCollection->getSize();
     }
     if (!is_null($input->getOption(self::INPUT_KEY_MAX_CUSTOMERS))) {
         $customersNum = $input->getOption(self::INPUT_KEY_MAX_CUSTOMERS);
     } else {
         $customersNum = $this->customerCollection->getSize();
     }
     if (!is_null($input->getOption(self::INPUT_KEY_MAX_RULES))) {
         $rulesNum = $input->getOption(self::INPUT_KEY_MAX_RULES);
     } else {
         $rulesNum = $this->ruleCollection->getSize();
     }
     //These indexers are not ready to run in single-row mode
     $excludeIndexers = ['catalogrule_rule', 'catalogsearch_fulltext'];
     $productIndexers = ['catalog_product_flat', 'catalog_product_price', 'catalog_product_attribute', 'cataloginventory_stock', 'catalogrule_product', 'targetrule_product_rule', 'catalogpermissions_product', 'catalogrule_rule', 'catalogsearch_fulltext'];
     $categoryIndexers = ['catalog_category_flat', 'catalog_category_product', 'catalog_product_category', 'catalogpermissions_category'];
     $ruleIndexers = ['targetrule_rule_product'];
     $customerIndexres = ['customer_grid'];
     $requestedIndexer = $input->getOption('indexer');
     if ($requestedIndexer == 'all') {
         $runThese = [];
     } else {
         $runThese = explode(',', $input->getOption('indexer'));
     }
     foreach ($indexersData as $indexer) {
         if (in_array($indexer->getIndexerId(), $excludeIndexers)) {
             continue;
         }
         if (count($runThese) > 0 && !in_array($indexer->getIndexerId(), $runThese)) {
             continue;
         }
         $max = 0;
         $entity = '';
         if (in_array($indexer->getIndexerId(), $productIndexers)) {
             $max = $productsNum;
             $entity = 'Product';
         } else {
             if (in_array($indexer->getIndexerId(), $categoryIndexers)) {
                 $max = $categoriesNum;
                 $entity = 'Category';
             } else {
                 if (in_array($indexer->getIndexerId(), $customerIndexres)) {
                     $max = $customersNum;
                     $entity = 'Customer';
                 } else {
                     if (in_array($indexer->getIndexerId(), $ruleIndexers)) {
                         $max = $rulesNum;
                         $entity = 'Rule';
                     }
                 }
             }
         }
         if (!is_null($input->getOption(self::INPUT_KEY_REINDEX_ID))) {
             $id = $input->getOption(self::INPUT_KEY_REINDEX_ID);
         } else {
             $id = mt_rand(1, $max);
         }
         $output->writeln('<info>' . $entity . '# id ' . $id . ' (out of ' . $max . ') for ' . $indexer->getIndexerId() . ' </info>');
         $this->indexRegistry->get($indexer->getIndexerId())->reindexRow($id);
         $output->writeln('<info>' . $indexer->getDescription() . ' completed.</info>');
     }
 }