1.Open file /app/code/community/Klevu/Search/Model/Product/Sync.php 2.Find for function syncData and replace as below:- public function syncData($store){ if ($this->rescheduleIfOutOfMemory()) { return; } $config = Mage::helper('klevu_search/config'); $session = Mage::getSingleton('klevu_search/session'); $firstSync = $session->getFirstSync(); try { $rating_upgrade_flag = $config->getRatingUpgradeFlag(); if(!empty($firstSync) || $rating_upgrade_flag==0) { $this->updateProductsRating($store); } } catch(Exception $e) { Mage::helper('klevu_search')->log(Zend_Log::WARN, sprintf("Unable to update rating attribute %s", $store->getName())); } //set current store so will get proper bundle price Mage::app()->setCurrentStore($store->getId()); $this->log(Zend_Log::INFO, sprintf("Starting sync for %s (%s).", $store->getWebsite()->getName(), $store->getName())); $actions = array( 'delete' => $this->getConnection() ->select() ->union(array( $this->getConnection() ->select() /* * Select synced products in the current store/mode that are no longer enabled * (don't exist in the products table, or have status disabled for the current * store, or have status disabled for the default store) or are not visible * (in the case of configurable products, check the parent visibility instead). */ ->from( array('k' => $this->getTableName("klevu_search/product_sync")), array('product_id' => "k.product_id", 'parent_id' => "k.parent_id") ) ->joinLeft( array('v' => $this->getTableName("catalog/category_product_index")), "v.product_id = k.product_id AND v.store_id = :store_id", "" ) ->joinLeft( array('p' => $this->getTableName("catalog/product")), "p.entity_id = k.product_id", "" ) ->joinLeft( array('si' => $this->getTableName("cataloginventory/stock_item")), "si.product_id = p.entity_id AND si.stock_id=1", "" ) ->joinLeft( array('ss' => $this->getProductStatusAttribute()->getBackendTable()), "ss.attribute_id = :status_attribute_id AND ss.entity_id = k.product_id AND ss.store_id = :store_id", "" )->joinLeft( array('sd' => $this->getProductStatusAttribute()->getBackendTable()), "sd.attribute_id = :status_attribute_id AND sd.entity_id = k.product_id AND sd.store_id = :default_store_id", "" ) ->where("(k.store_id = :store_id) AND (k.type = :type) AND (k.test_mode = :test_mode) AND ((p.entity_id IS NULL) OR (si.use_config_manage_stock = 0 AND si.manage_stock = 1 AND si.is_in_stock = 0) OR (CASE WHEN ss.value_id > 0 THEN ss.value ELSE sd.value END != :status_enabled) OR (CASE WHEN k.parent_id = 0 THEN k.product_id ELSE k.parent_id END NOT IN (?)) )", $this->getConnection() ->select() ->from( array('i' => $this->getTableName("catalog/category_product_index")), array('id' => "i.product_id") ) ->where("(i.store_id = :store_id) AND (i.visibility IN (:visible_both, :visible_search))") ), $this->getConnection() ->select() /* * Select products which are not associated with parent * but still parent exits in klevu product sync table with parent id * */ ->from( array('ks' => $this->getTableName("klevu_search/product_sync")), array('product_id' => "ks.product_id","parent_id" => 'ks.parent_id') ) ->where("(ks.parent_id !=0 AND ks.product_id NOT IN (?) AND ks.store_id = :store_id)", $this->getConnection() ->select() /* * Select products from catalog super link table */ ->from( array('s' => $this->getTableName("catalog/product_super_link")), array('product_id' => "s.product_id") ) ) ) ) ->group(array('k.product_id', 'k.parent_id')) ->bind(array( 'type' => "products", 'store_id' => $store->getId(), 'default_store_id' => Mage_Catalog_Model_Abstract::DEFAULT_STORE_ID, 'test_mode' => $this->isTestModeEnabled(), 'status_attribute_id' => $this->getProductStatusAttribute()->getId(), 'status_enabled' => Mage_Catalog_Model_Product_Status::STATUS_ENABLED, 'visible_both' => Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH, 'visible_search' => Mage_Catalog_Model_Product_Visibility::VISIBILITY_IN_SEARCH )), 'update' => $this->getConnection() ->select() ->union(array( // Select products without parents that need to be updated $this->getConnection() ->select() /* * Select synced non-configurable products for the current store/mode * that are visible (using the category product index) and have been * updated since last sync. */ ->from( array('k' => $this->getTableName("klevu_search/product_sync")), array('product_id' => "k.product_id", 'parent_id' => "k.parent_id") ) ->join( array('p' => $this->getTableName("catalog/product")), "p.entity_id = k.product_id", "" ) ->join( array('i' => $this->getTableName("catalog/category_product_index")), "i.product_id = k.product_id AND k.store_id = i.store_id AND i.visibility IN (:visible_both, :visible_search)", "" ) ->where("(k.store_id = :store_id) AND (k.type = :type) AND (k.test_mode = :test_mode) AND (p.type_id != :configurable) AND (p.updated_at > k.last_synced_at)"), // Select products with parents (configurable) that need to be updated $this->getConnection() ->select() /* * Select synced products for the current store/mode that are configurable * children (have entries in the super link table), are enabled for the current * store (or the default store), have visible parents (using the category product * index) and, either the product or the parent, have been updated since last sync. */ ->from( array('k' => $this->getTableName("klevu_search/product_sync")), array('product_id' => "k.product_id", 'parent_id' => "k.parent_id") ) ->join( array('s' => $this->getTableName("catalog/product_super_link")), "k.parent_id = s.parent_id AND k.product_id = s.product_id", "" ) ->join( array('i' => $this->getTableName("catalog/category_product_index")), "k.parent_id = i.product_id AND k.store_id = i.store_id AND i.visibility IN (:visible_both, :visible_search)", "" ) ->join( array('p1' => $this->getTableName("catalog/product")), "k.product_id = p1.entity_id", "" ) ->join( array('p2' => $this->getTableName("catalog/product")), "k.parent_id = p2.entity_id", "" ) ->joinLeft( array('ss' => $this->getProductStatusAttribute()->getBackendTable()), "ss.attribute_id = :status_attribute_id AND ss.entity_id = k.product_id AND ss.store_id = :store_id", "" ) ->joinLeft( array('sd' => $this->getProductStatusAttribute()->getBackendTable()), "sd.attribute_id = :status_attribute_id AND sd.entity_id = k.product_id AND sd.store_id = :default_store_id", "" ) ->where("(k.store_id = :store_id) AND (k.type = :type) AND (k.test_mode = :test_mode) AND (CASE WHEN ss.value_id > 0 THEN ss.value ELSE sd.value END = :status_enabled) AND ((p1.updated_at > k.last_synced_at) OR (p2.updated_at > k.last_synced_at))") )) ->group(array('k.product_id', 'k.parent_id')) ->bind(array( 'type' => "products", 'store_id' => $store->getId(), 'default_store_id' => Mage_Catalog_Model_Abstract::DEFAULT_STORE_ID, 'test_mode' => $this->isTestModeEnabled(), 'configurable' => Mage_Catalog_Model_Product_Type_Configurable::TYPE_CODE, 'visible_both' => Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH, 'visible_search' => Mage_Catalog_Model_Product_Visibility::VISIBILITY_IN_SEARCH, 'status_attribute_id' => $this->getProductStatusAttribute()->getId(), 'status_enabled' => Mage_Catalog_Model_Product_Status::STATUS_ENABLED, )), 'add' => $this->getConnection() ->select() ->union(array( // Select non-configurable products that need to be added $this->getConnection() ->select() /* * Select non-configurable products that are visible in the current * store (using the category product index), but have not been synced * for this store yet. */ ->from( array('p' => $this->getTableName("catalog/product")), array('product_id' => "p.entity_id", 'parent_id' => new Zend_Db_Expr("0")) ) ->join( array('i' => $this->getTableName("catalog/category_product_index")), "p.entity_id = i.product_id AND i.store_id = :store_id AND i.visibility IN (:visible_both, :visible_search)", "" ) ->join( array('si' => $this->getTableName("cataloginventory/stock_item")), "si.product_id = i.product_id", "" ) ->joinLeft( array('k' => $this->getTableName("klevu_search/product_sync")), "p.entity_id = k.product_id AND k.parent_id = 0 AND i.store_id = k.store_id AND k.test_mode = :test_mode AND k.type = :type", "" ) ->where("(p.type_id != :configurable) AND si.stock_id=1 AND ((si.use_config_manage_stock = 1) OR (si.use_config_manage_stock = 0 AND si.manage_stock = 1 AND si.is_in_stock = 1) OR (si.use_config_manage_stock = 0 AND si.manage_stock = 0)) AND (k.product_id IS NULL)"), // Select configurable parent & product pairs that need to be added $this->getConnection() ->select() /* * Select configurable product children that are enabled (for the current * store or for the default store), have visible parents (using the category * product index) and have not been synced yet for the current store with * the current parent. */ ->from( array('s' => $this->getTableName("catalog/product_super_link")), array('product_id' => "s.product_id", 'parent_id' => "s.parent_id") ) ->join( array('si' => $this->getTableName("cataloginventory/stock_item")), "si.product_id = s.product_id AND si.stock_id=1 AND ((si.use_config_manage_stock = 1) OR (si.use_config_manage_stock = 0 AND si.manage_stock = 1 AND si.is_in_stock = 1) OR (si.use_config_manage_stock = 0 AND si.manage_stock = 0))", "" ) ->join( array('i' => $this->getTableName("catalog/category_product_index")), "s.parent_id = i.product_id AND i.store_id = :store_id AND i.visibility IN (:visible_both, :visible_search)", "" ) ->joinLeft( array('ss' => $this->getProductStatusAttribute()->getBackendTable()), "ss.attribute_id = :status_attribute_id AND ss.entity_id = s.product_id AND ss.store_id = :store_id", "" ) ->joinLeft( array('sd' => $this->getProductStatusAttribute()->getBackendTable()), "sd.attribute_id = :status_attribute_id AND sd.entity_id = s.product_id AND sd.store_id = :default_store_id", "" ) ->joinLeft( array('k' => $this->getTableName("klevu_search/product_sync")), "s.parent_id = k.parent_id AND s.product_id = k.product_id AND k.store_id = :store_id AND k.test_mode = :test_mode AND k.type = :type", "" ) ->where("(CASE WHEN ss.value_id > 0 THEN ss.value ELSE sd.value END = :status_enabled) AND ((si.use_config_manage_stock = 1) OR (si.use_config_manage_stock = 0 AND si.manage_stock = 1 AND si.is_in_stock = 1) OR (si.use_config_manage_stock = 0 AND si.manage_stock = 0)) AND (k.product_id IS NULL)") )) ->group(array('k.product_id', 'k.parent_id')) ->bind(array( 'type' => "products", 'store_id' => $store->getId(), 'default_store_id' => Mage_Catalog_Model_Abstract::DEFAULT_STORE_ID, 'test_mode' => $this->isTestModeEnabled(), 'configurable' => Mage_Catalog_Model_Product_Type_Configurable::TYPE_CODE, 'visible_both' => Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH, 'visible_search' => Mage_Catalog_Model_Product_Visibility::VISIBILITY_IN_SEARCH, 'status_attribute_id' => $this->getProductStatusAttribute()->getId(), 'status_enabled' => Mage_Catalog_Model_Product_Status::STATUS_ENABLED )) ); $errors = 0; foreach ($actions as $action => $statement) { if ($this->rescheduleIfOutOfMemory()) { return; } $method = $action . "Products"; $products = $this->getConnection()->fetchAll($statement, $statement->getBind()); $total = count($products); $this->log(Zend_Log::INFO, sprintf("Found %d products to %s.", $total, $action)); $pages = ceil($total / static::RECORDS_PER_PAGE); for ($page = 1; $page <= $pages; $page++) { if ($this->rescheduleIfOutOfMemory()) { return; } $offset = ($page - 1) * static::RECORDS_PER_PAGE; $result = $this->$method(array_slice($products, $offset, static::RECORDS_PER_PAGE)); if ($result !== true) { $errors++; $this->log(Zend_Log::ERR, sprintf("Errors occurred while attempting to %s products %d - %d: %s", $action, $offset + 1, ($offset + static::RECORDS_PER_PAGE <= $total) ? $offset + static::RECORDS_PER_PAGE : $total, $result )); /*$this->notify( Mage::helper('klevu_search')->__("Product Sync for %s (%s) failed to %s some products. Please consult the logs for more details.", $store->getWebsite()->getName(), $store->getName(), $action ), $store );*/ } } } $this->log(Zend_Log::INFO, sprintf("Finished sync for %s (%s).", $store->getWebsite()->getName(), $store->getName())); /* Sync category content */ $this->runCategory($store); if (!$config->isExtensionEnabled($store) && !$config->hasProductSyncRun($store)) { // Enable Klevu Search after the first sync if(!empty($firstSync)) { $config->setExtensionEnabledFlag(true, $store); $this->log(Zend_Log::INFO, sprintf("Automatically enabled Klevu Search on Frontend for %s (%s).", $store->getWebsite()->getName(), $store->getName() )); } } $config->setLastProductSyncRun("now", $store); if ($errors == 0) { // If Product Sync finished without any errors, notifications are not relevant anymore $this->deleteNotifications($store); } } 3.Perform full Catalog sync by selecting "All Data" option as given in the below guide: https://support.klevu.com/knowledgebase/synchronize-data-with-klevu-search-2/