本文整理汇总了PHP中Magento\Catalog\Model\Resource\Product\Collection::getSize方法的典型用法代码示例。如果您正苦于以下问题:PHP Collection::getSize方法的具体用法?PHP Collection::getSize怎么用?PHP Collection::getSize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Magento\Catalog\Model\Resource\Product\Collection
的用法示例。
在下文中一共展示了Collection::getSize方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: execute
/**
* {@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>');
}
}