Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
coruble opened this issue Jun 13, 2016 · 5 comments
Open

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

coruble opened this issue Jun 13, 2016 · 5 comments

Comments

@coruble
Copy link

coruble commented Jun 13, 2016

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
Copy link

diego3g commented Jul 13, 2016

Did you solve it?

@coruble
Copy link
Author

coruble commented Jul 13, 2016

@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
Copy link

diego3g commented Jul 13, 2016

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

@diego3g
Copy link

diego3g commented Jul 14, 2016

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
Copy link
Author

coruble commented Jul 14, 2016

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants