Clear Compare list (added from jmquickview) always shows error

Dear support,

I found an error in your template which is happening only if the products are added to compare list from jmquickview.
If you add one or more product to compare , and then you press "clear all" , it will produce an error.
Attachment 32557

How to solve this ?

2 answers

Profile photo of Sherlock 0.00 $tone January 3, 2014
Public

Hi Asavano,

It seems to be a bug, please try the workaround below:
1. Back up the files (below) you are going to change first
2. Replace the file skin\frontend\default\jm_crafts\joomlart\jmquickvi ew\js\jmquickview.js file withattached herewith (please unzip it first)
3. Open the file app\code\local\Wavethemes\Jmquickview\controllers\ IndexController.php, then add following snippets:

PHP Code:

                        /**
     * Remove item from compare list
     */
    
public function removeAction()
    {
        
$response = array();
        if (
$productId = (int) $this->getRequest()->getParam('product')) {
            
$product Mage::getModel('catalog/product')
                ->
setStoreId(Mage::app()->getStore()->getId())
                ->
load($productId);

            if($product->getId()) {
                
/**  item Mage_Catalog_Model_Product_Compare_Item */
                
$item Mage::getModel('catalog/product_compare_item');
                if(
Mage::getSingleton('customer/session')->isLoggedIn()) {
                    
$item->addCustomerData(Mage::getSingleton('customer/session')->getCustomer());
                } elseif (
$this->_customerId) {
                    
$item->addCustomerData(
                        
Mage::getModel('customer/customer')->load($this->_customerId)
                    );
                } else {
                    
$item->addVisitorId(Mage::getSingleton('log/visitor')->getId());
                }

                $item->loadByProduct($product);

                if($item->getId()) {
                    
$item->delete();
                    
$response['status'] = 'SUCCESS';
                    
$response['message'] = $this->__('The product %s has been removed from comparison list.'$product->getName());
                    
Mage::dispatchEvent('catalog_product_compare_remove_product', array('product'=>$item));
                    
Mage::helper('catalog/product_compare')->calculate();
                     
$this->loadLayout();
                    
$sidebar_block $this->getLayout()->getBlock('catalog.compare.sidebar');
                    
$sidebar_block->setTemplate('jmquickview/compare/sidebar.phtml');
                    
$sidebar $sidebar_block->toHtml();
                    
$response['sidebar'] = $sidebar;
                }
            }
        }
        
$this->getResponse()->setBody(Mage::helper('core')->jsonEncode($response));

    }

     /**
     * Remove all items from comparison list
     */
    
public function clearAction()
    {
        
$response = array();
        
$items Mage::getResourceModel('catalog/product_compare_item_collection');

        if (Mage::getSingleton('customer/session')->isLoggedIn()) {
            
$items->setCustomerId(Mage::getSingleton('customer/session')->getCustomerId());
        } elseif (
$this->_customerId) {
            
$items->setCustomerId($this->_customerId);
        } else {
            
$items->setVisitorId(Mage::getSingleton('log/visitor')->getId());
        }

        /**  session Mage_Catalog_Model_Session */
        
$session Mage::getSingleton('catalog/session');

        try {
            $items->clear();
            
$session->addSuccess($this->__('The comparison list was cleared.'));
            
Mage::helper('catalog/product_compare')->calculate();
            
$response['status'] = 'SUCCESS';
            
$response['message'] = $this->__('The comparison list was cleared.');
            
$this->loadLayout();
            
$sidebar_block $this->getLayout()->getBlock('catalog.compare.sidebar');
            
$sidebar_block->setTemplate('jmquickview/compare/sidebar.phtml');
            
$sidebar $sidebar_block->toHtml();
            
$response['sidebar'] = $sidebar;
        } catch (
Mage_Core_Exception $e) {
            
$session->addError($e->getMessage());
        } catch (
Exception $e) {
            
$session->addException($e$this->__('An error occurred while clearing comparison list.'));
        }
        
$this->getResponse()->setBody(Mage::helper('core')->jsonEncode($response));
        
    } 




Let me know how it goes.

#1

This question is now closed

Written By

Comments