jreinke / magento-autocomplete

Super fast autocomplete for Magento
52 stars 28 forks source link

Autocomplete loads base (high-res) images, not thumbnails #18

Open coruble opened 8 years ago

coruble commented 8 years ago

Hey,

it's probably a problem coming from my custom theme or something because demo.bubbleshop.net doesn't show this behavior, but I can't get the extension to load thumbnails instead of 1MB+ base images.

I looked around in the source code but can't find any $this->helper('catalog/image')->init($_product, 'image') I could customise.

Any idea ? For now it makes my autocomplete kind of broken because of the multiple megabytes downloaded when suggestions are shown.

Thanks a lot, Camille

PS : great extension BTW

diego3g commented 8 years ago

Did you solve it?

coruble commented 8 years ago

@diego3g Nope :-( I still have it in my todo-list somewhere. I'll update the issue when I solve it, if I solve it

diego3g commented 8 years ago

I'll try too. If i solve it i tell you.

diego3g commented 8 years ago

Hey @hack47, i've found a solution, i don't know if it's the best or the fastest but it works!

In your /app/code/community/Bubble/Autocomplete/controllers/ProductController.php change jsonAction to:

$cacheId = 'bubble_autocomplete_' . Mage::app()->getStore()->getId();
if (false === ($data = Mage::app()->loadCache($cacheId))) {
    $collection = Mage::getModel('catalog/product')->getCollection();

    Mage::dispatchEvent('bubble_autocomplete_product_collection_init', array('collection' => $collection));

    foreach ($collection->getData() as $product) {
        $p     = Mage::getModel('catalog/product')->load($product['entity_id']);
        $image = Mage::helper('catalog/image')->init($p, 'image')->resize(90, 90);
        $product['small_image'] = (string) $image;

        $newData[] = $product;
    }

    $data = json_encode($newData);
    $lifetime = Mage::helper('bubble_autocomplete')->getCacheLifetime();
    Mage::app()->saveCache($data, $cacheId, array('block_html'), $lifetime);
}

$this->getResponse()
    ->setHeader('Content-Type', 'application/json')
    ->setBody($data);

At the resize function, set the size of your thumbnail in the search box, i'm currently using 90x90px.

Clear the cache and your localStorage and refresh the page.

Hope it helps you.

coruble commented 8 years ago

@diego3g Thanks a lot for sharing your code. I tried it and still can't solve the bug, it's crazy. I remember trying approximately the same thing as you with no success... Obviously I cleared all caches, including the client-side Local Storage. So strange... There has to be something elsewhere in my Magento code.