public function rebuildStoreProductIndexPage($storeId, $collectionDefault, $page, $pageSize, $emulationInfo = null, $productIds = null, $useTmpIndex = false) { if ($this->config->isEnabledBackend($storeId) === false) { $this->logger->log('INDEXING IS DISABLED FOR ' . $this->logger->getStoreName($storeId)); return; } $this->logger->start('rebuildStoreProductIndexPage ' . $this->logger->getStoreName($storeId) . ' page ' . $page . ' pageSize ' . $pageSize); $emulationInfoPage = null; if ($emulationInfo === null) { $emulationInfoPage = $this->startEmulation($storeId); } $index_prefix = Mage::getConfig()->getTablePrefix(); $additionalAttributes = $this->config->getProductAdditionalAttributes($storeId); /** @var Mage_Catalog_Model_Resource_Product_Collection $collection */ $collection = clone $collectionDefault; $collection->setCurPage($page)->setPageSize($pageSize); $collection->addCategoryIds(); $collection->addUrlRewrite(); if ($this->product_helper->isAttributeEnabled($additionalAttributes, 'stock_qty')) { $collection->joinField('stock_qty', $index_prefix . 'cataloginventory_stock_item', 'qty', 'product_id=entity_id', '{{table}}.stock_id=1', 'left'); } if ($this->product_helper->isAttributeEnabled($additionalAttributes, 'ordered_qty')) { $collection->getSelect()->columns('(SELECT SUM(qty_ordered) FROM ' . $index_prefix . 'sales_flat_order_item WHERE ' . $index_prefix . 'sales_flat_order_item.product_id = e.entity_id) as ordered_qty'); } if ($this->product_helper->isAttributeEnabled($additionalAttributes, 'total_ordered')) { $collection->getSelect()->columns('(SELECT SUM(row_total) FROM ' . $index_prefix . 'sales_flat_order_item WHERE ' . $index_prefix . 'sales_flat_order_item.product_id = e.entity_id) as total_ordered'); } if ($this->product_helper->isAttributeEnabled($additionalAttributes, 'rating_summary')) { $collection->joinField('rating_summary', $index_prefix . 'review_entity_summary', 'rating_summary', 'entity_pk_value=entity_id', '{{table}}.store_id=' . $storeId, 'left'); } $this->logger->start('LOADING ' . $this->logger->getStoreName($storeId) . ' collection page ' . $page . ', pageSize ' . $pageSize); $collection->load(); $this->logger->log('Loaded ' . count($collection) . ' products'); $this->logger->stop('LOADING ' . $this->logger->getStoreName($storeId) . ' collection page ' . $page . ', pageSize ' . $pageSize); $index_name = $this->product_helper->getIndexName($storeId, $useTmpIndex); $indexData = $this->getProductsRecords($storeId, $collection, $productIds); if (!empty($indexData['toIndex'])) { $this->logger->start('ADD/UPDATE TO ALGOLIA'); $this->algolia_helper->addObjects($indexData['toIndex'], $index_name); $this->logger->log('Product IDs: ' . implode(', ', array_keys($indexData['toIndex']))); $this->logger->stop('ADD/UPDATE TO ALGOLIA'); } if (!empty($indexData['toRemove'])) { $this->logger->start('REMOVE FROM ALGOLIA'); $this->algolia_helper->deleteObjects($indexData['toRemove'], $index_name); $this->logger->log('Product IDs: ' . implode(', ', $indexData['toRemove'])); $this->logger->stop('REMOVE FROM ALGOLIA'); } unset($indexData); $collection->walk('clearInstance'); $collection->clear(); unset($collection); if ($emulationInfo === null) { $this->stopEmulation($emulationInfoPage); } $this->logger->stop('rebuildStoreProductIndexPage ' . $this->logger->getStoreName($storeId) . ' page ' . $page . ' pageSize ' . $pageSize); }
protected function _rebuildProductIndex($storeId, $productIds = null, $useTmpIndex = false) { if ($productIds == null || count($productIds) == 0) { $collection = $this->product_helper->getProductCollectionQuery($storeId, $productIds, $useTmpIndex); $size = $collection->getSize(); if (!empty($productIds)) { $size = max(count($productIds), $size); } $by_page = $this->config->getNumberOfElementByPage(); $nb_page = ceil($size / $by_page); for ($i = 1; $i <= $nb_page; $i++) { $data = array('store_id' => $storeId, 'product_ids' => $productIds, 'page_size' => $by_page, 'page' => $i, 'use_tmp_index' => $useTmpIndex); $this->addToQueue('algoliasearch/observer', 'rebuildProductIndex', $data, $by_page); } } else { $this->addToQueue('algoliasearch/observer', 'rebuildProductIndex', array('store_id' => $storeId, 'product_ids' => $productIds), count($productIds)); } return $this; }
public function getAllAttributes($add_empty_row = false) { if (is_null(self::$_productAttributes)) { self::$_productAttributes = array(); /** @var $config Mage_Eav_Model_Config */ $config = Mage::getSingleton('eav/config'); $allAttributes = $config->getEntityAttributeCodes('catalog_product'); $productAttributes = array_merge(array('name', 'path', 'categories', 'categories.level0', 'categories.level1', 'categories.level2', 'categories.level3', 'categories.level4', 'categories_without_path', 'main_categories', 'main_categories.level0', 'main_categories.level1', 'main_categories.level2', 'main_categories.level3', 'main_categories.level4', 'description', 'ordered_qty', 'total_ordered', 'stock_qty', 'rating_summary', 'media_gallery', 'in_stock'), $allAttributes); $excludedAttributes = $this->getExcludedAttributes(); $productAttributes = array_diff($productAttributes, $excludedAttributes); foreach ($productAttributes as $attributeCode) { self::$_productAttributes[$attributeCode] = $config->getAttribute('catalog_product', $attributeCode)->getFrontendLabel(); } } $attributes = self::$_productAttributes; if ($add_empty_row === true) { $attributes[''] = ''; } uksort($attributes, function ($a, $b) { return strcmp($a, $b); }); return $attributes; }
public function getAllAttributes($add_empty_row = false) { if (is_null(self::$_productAttributes)) { self::$_productAttributes = array(); /** @var $config Mage_Eav_Model_Config */ $config = Mage::getSingleton('eav/config'); $allAttributes = $config->getEntityAttributeCodes('catalog_product'); $productAttributes = array_merge(array('name', 'path', 'categories', 'categories_without_path', 'description', 'ordered_qty', 'stock_qty', 'price_with_tax', 'rating_summary'), $allAttributes); $excludedAttributes = array('all_children', 'available_sort_by', 'children', 'children_count', 'custom_apply_to_products', 'custom_design', 'custom_design_from', 'custom_design_to', 'custom_layout_update', 'custom_use_parent_settings', 'default_sort_by', 'display_mode', 'filter_price_range', 'global_position', 'image', 'include_in_menu', 'is_active', 'is_always_include_in_menu', 'is_anchor', 'landing_page', 'level', 'lower_cms_block', 'page_layout', 'path_in_store', 'position', 'small_image', 'thumbnail', 'url_key', 'url_path', 'visible_in_menu'); $productAttributes = array_diff($productAttributes, $excludedAttributes); foreach ($productAttributes as $attributeCode) { self::$_productAttributes[$attributeCode] = $config->getAttribute('catalog_category', $attributeCode)->getFrontendLabel(); } } $attributes = self::$_productAttributes; if ($add_empty_row === true) { $attributes[''] = ''; } uksort($attributes, function ($a, $b) { return strcmp($a, $b); }); return $attributes; }
public function rebuildProductIndex(Varien_Object $event) { $storeId = $event->getStoreId(); $productIds = $event->getProductIds(); $page = $event->getPage(); $pageSize = $event->getPageSize(); $useTmpIndex = (bool) $event->getUseTmpIndex(); if (is_null($storeId) && !empty($productIds)) { foreach (Mage::app()->getStores() as $storeId => $store) { if (!$store->getIsActive()) { continue; } $this->helper->rebuildStoreProductIndex($storeId, $productIds); } } else { if (!empty($page) && !empty($pageSize)) { $collection = $this->product_helper->getProductCollectionQuery($storeId, $productIds, $useTmpIndex); $this->helper->rebuildStoreProductIndexPage($storeId, $collection, $page, $pageSize, null, $productIds, $useTmpIndex); } else { $this->helper->rebuildStoreProductIndex($storeId, $productIds); } } return $this; }