Algolia Multistore Links Issue

magento2

#1

Hello,

I have setup Algolia for my Multistore with each store having seperate indicies but when searching for a product the URL is incorrect, it uses a different stores URL for a product for example I am on the url example.com/store1/ when I search products are showing links to example.com/store2/

Does anyone know about this issue and can anyone support me to get this resolved?


#2

Hi @gareth.jones,

Could you please look into two settings:

  • System > Configuration > General > Web > Search Engine Optimization and set the field Use Web Server Rewrites to Yes .

  • System > Configuration > General > Web > Unsecure or Secure:

After each, a full reindex is required for the changes to take effect.

I hope this helps!


#3

Hi Ajay,

We are using Magento 2 and we have already setup the settings you mentioned in Magento 2 format, very confused to why this issue occurs


#4

Hi @gareth.jones,

Just wanted to follow up here and see if it has been resolved. If it hasn’t, would it be possible to see a live example? It would help us with investigating your issue.

Let us know,

Betty


#5

Hello @betty.suravech

The issue is still continuning to happen, we have developed a URL fix for now which looks like this

<?php
require_once 'vendor/algolia/algoliasearch-client-php/algoliasearch.php';
$client = new \AlgoliaSearch\Client('********', '************************');
$indexes = $client->listIndexes();
$indexes = array_shift($indexes);

$wrongBaseUrl = 'paladone.com/usa/';
$partOfWrongBaseUrl = 'paladone.com/usa';

foreach ($indexes as $index) {
$indice = $client->initIndex($index['name']);
foreach ($indice->browse('') as $hit) {
if (stripos($hit['url'], $partOfWrongBaseUrl) !== false) {
	
    if($index['name'] == 'ustradesite_usa_products') {
        $baseUrl = 'paladone.com/usa/';
    } elseif($index['name'] == 'uktradestore_ukb2b_products') {
        $baseUrl = 'paladone.com/ukb2b/';
    } elseif($index['name'] == 'ukb2cstore_ukb2c_products') {
        $baseUrl = 'paladone.com/ukb2c/';
    } else {
        continue;
    }
    $hit['url'] = str_replace($wrongBaseUrl, $baseUrl, $hit['url']);
    echo 'Saving ' .$hit['objectID'] . PHP_EOL;
			echo "<br>";
    $indice->saveObject($hit);
}
}
}

We do have issues though because it seems everyday the wrongBaseUrl is changing to another store view as the main one, we have tried contacting the Algolia support multiple times but they won’t provide support about this issue. I have also posted this issue in the github issues for the Algolia module.

If it’s possible to get this fixed asap that would be great because I’ve noticed we are not the only ones encountering this issue!


#6

Hi @gareth.jones,

Thanks for following up and sharing your script with us. After inspecting your script and noticing the index names you have, can you describe your Magento store set up? Are you using different Magento instances for each store or have you set up your stores by store view? Can you also confirm the index name prefix set in Stores > Configuration (possibly for all 3 stores)?

It would be helpful to lend us access to your data as well. You can do that here. You can revoke this access anytime.

Let us know! Thanks!


#7

Hi @betty.suravech,

No problem, in our store we have 3 store views (multistore) with unique products and categories in each store view (though some have the same name)

Index Prefix Names
UKB2C - ukb2cstore_
UKB2B - uktradestore_
USA - ustradesite_

I have also provided access for support as requested.


#8

/public_html/vendor/algolia/algoliasearch-magento-2/Helper/Entity/ProductHelper.php

Line 456 add
$newURL = $product->getUrlModel()->getUrl($product, $urlParams);

Directly below find ‘url’ and replace with, replace the storeurl/code with yours

'url' => str_replace(array('https://STOREURL1/STORECODE1/', 'https://STOREURL2/STORECODE2/', 'https://STOREURL3/STORECODE3/'), array('', '', ''), $newURL),

/public_html/vendor/algolia/algoliasearch-magento-2/view/frontend/templates/instant/hit.phtml

Line 15

Add

<?php echo $block->getBaseUrl(); ?>

Before

{{url}}

Do the same in

/public_html/vendor/algolia/algoliasearch-magento-2/view/frontend/templates/autocomplete/

For the following files

page.phtml
product.phtml
suggestion.phtml