My product comparison link doesn't work. This is in Magento 1.9.
My issues are almost identical to this post, with the exception that clearing the index did not work. Is there anything else I can try?
Here are the issues:
When I click "Add to Compare" on a product, a message stating that "such-and-such product successfully added to compare list" appears.
However the compare products sidebar shows "You have no items to compare."
I can tell the table catalog_compare_item
is being populated with the correct visitor ID and product ID, but if I do a print_r($this->helper('catalog/product_compare')->getItemCount())
in template/catalog/product/compare/sidebar.phtml, "0" is returned.
Why won't the sidebar show the products to compare?
From the comments, it looks like your Magento DB does not have report_compared_product_index table.
Import the following SQL to create this table structure in your DB.
CREATE TABLE IF NOT EXISTS `report_compared_product_index` (
`index_id` bigint(20) unsigned NOT NULL COMMENT 'Index Id',
`visitor_id` int(10) unsigned DEFAULT NULL COMMENT 'Visitor Id',
`customer_id` int(10) unsigned DEFAULT NULL COMMENT 'Customer Id',
`product_id` int(10) unsigned NOT NULL COMMENT 'Product Id',
`store_id` smallint(5) unsigned DEFAULT NULL COMMENT 'Store Id',
`added_at` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00' COMMENT 'Added At'
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Reports Compared Product Index Table' AUTO_INCREMENT=1 ;
ALTER TABLE `report_compared_product_index`
ADD PRIMARY KEY (`index_id`), ADD UNIQUE KEY `UNQ_REPORT_COMPARED_PRODUCT_INDEX_VISITOR_ID_PRODUCT_ID` (`visitor_id`,`product_id`), ADD UNIQUE KEY `UNQ_REPORT_COMPARED_PRODUCT_INDEX_CUSTOMER_ID_PRODUCT_ID` (`customer_id`,`product_id`), ADD KEY `IDX_REPORT_COMPARED_PRODUCT_INDEX_STORE_ID` (`store_id`), ADD KEY `IDX_REPORT_COMPARED_PRODUCT_INDEX_ADDED_AT` (`added_at`), ADD KEY `IDX_REPORT_COMPARED_PRODUCT_INDEX_PRODUCT_ID` (`product_id`);
Let me know if this helps.
Step 1 : Make sure you have "report_compared_product_index" table in your database.
Step 2 : clearing cache and perform indexing
step 3 : go to the following url
app\code\core\Mage\Catalog\Helper\Product\Compare.php
Find the following function
public function calculate($logout = false)
and commenting the code as bellow
// first visit
// if (!$this->_catalogSession->hasCatalogCompareItemsCount() && !$this->_customerId) {
// $count = 0;
// } else {
/** @var $collection Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Compare_Item_Collection */
$collection = Mage::getResourceModel('catalog/product_compare_item_collection')
->useProductItem(true);
if (!$logout && $this->_customerSession->isLoggedIn()) {
$collection->setCustomerId($this->_customerSession->getCustomerId());
} elseif ($this->_customerId) {
$collection->setCustomerId($this->_customerId);
} else {
$collection->setVisitorId($this->_logVisitor->getId());
}
/* Price data is added to consider item stock status using price index */
$collection->addPriceData();
$this->_productVisibility->addVisibleInSiteFilterToCollection($collection);
$count = $collection->getSize();
// }
$this->_catalogSession->setCatalogCompareItemsCount($count);
return $this;
Let me know if you have still any query
Thanks
Sagar
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With