Skip to content

Commit 32b2f78

Browse files
authored
Merge pull request #1877 from algolia/feat/MAGE-1474-backport-url-model-3.16
MAGE-1474: backport url model changes (3.16.x)
2 parents 40bf78f + ecb4d0a commit 32b2f78

File tree

9 files changed

+101
-155
lines changed

9 files changed

+101
-155
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
## 3.16.2
44

5+
### Updates
6+
- Removed `Magento\Catalog\Model\Product\Url` preference
7+
- Moved `algolia_algoliasearch_plugin_category_url` plugin to global area so it can be used in the new indexers
8+
59
### Bug fixes
610
- Fixed issue where missing pricing keys were not handled gracefully in the Autocomplete product template
711
- Fixed issue where category was not properly checked in the configuration block - thank you @benjamin-volle

Model/Product/Url.php

Lines changed: 0 additions & 150 deletions
This file was deleted.

Test/Integration/Indexing/Category/MultiStoreCategoriesTest.php

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,10 @@
1111
use Magento\Catalog\Model\ResourceModel\Category\CollectionFactory;
1212
use Magento\Framework\Exception\CouldNotSaveException;
1313
use Magento\Framework\Exception\NoSuchEntityException;
14+
use Magento\Store\Api\Data\StoreInterface;
1415

1516
/**
16-
* @magentoDataFixture Magento/Store/_files/second_website_with_two_stores.php
17+
* @magentoDataFixture Algolia_AlgoliaSearch::Test/Integration/_files/second_website_with_two_stores_and_products.php
1718
* @magentoDbIsolation disabled
1819
* @magentoAppIsolation enabled
1920
*/
@@ -64,6 +65,20 @@ public function testMultiStoreCategoryIndices()
6465
$defaultStore = $this->storeRepository->get('default');
6566
$fixtureSecondStore = $this->storeRepository->get('fixture_second_store');
6667

68+
// Check the base url of the categories
69+
$this->validateEntityUrl(
70+
'categories',
71+
self::BAGS_CATEGORY_ID,
72+
$defaultStore,
73+
"http://default.test/"
74+
);
75+
$this->validateEntityUrl(
76+
'categories',
77+
self::BAGS_CATEGORY_ID,
78+
$fixtureSecondStore,
79+
"http://fixture_second_store.test/"
80+
);
81+
6782
$bagsCategory = $this->loadCategory(self::BAGS_CATEGORY_ID, $defaultStore->getId());
6883

6984
$this->assertEquals(self::BAGS_CATEGORY_NAME, $bagsCategory->getName());

Test/Integration/Indexing/MultiStoreTestCase.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,23 @@ protected function setupStore(StoreInterface $store, bool $enableInstantSearch =
123123
$this->indicesConfigurator->saveConfigurationToAlgolia($store->getId());
124124
}
125125

126+
/**
127+
* Fetch a category from an index and check its base url
128+
*
129+
* @param StoreInterface $store
130+
* @param string $baseUrl
131+
* @return void
132+
* @throws NoSuchEntityException
133+
* @throws AlgoliaException
134+
*/
135+
protected function validateEntityUrl(string $entity, string $entityId, StoreInterface $store, string $baseUrl): void
136+
{
137+
$indexOptions = $this->getIndexOptions($entity, $store->getId());
138+
$results = $this->algoliaConnector->getObjects($indexOptions, [$entityId]);
139+
$hit = reset($results['results']);
140+
$this->assertStringContainsString($baseUrl, $hit['url']);
141+
}
142+
126143
/**
127144
* @throws ExceededRetriesException
128145
* @throws AlgoliaException

Test/Integration/Indexing/Product/MultiStoreProductsTest.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Algolia\AlgoliaSearch\Test\Integration\Indexing\Product;
44

5+
use Algolia\AlgoliaSearch\Exceptions\AlgoliaException;
56
use Algolia\AlgoliaSearch\Service\Product\BatchQueueProcessor as ProductBatchQueueProcessor;
67
use Algolia\AlgoliaSearch\Test\Integration\Indexing\MultiStoreTestCase;
78
use Magento\Catalog\Api\Data\ProductInterface;
@@ -10,6 +11,7 @@
1011
use Magento\Framework\Exception\CouldNotSaveException;
1112
use Magento\Framework\Exception\NoSuchEntityException;
1213
use Magento\Framework\Indexer\IndexerRegistry;
14+
use Magento\Store\Api\Data\StoreInterface;
1315
use Magento\Store\Api\WebsiteRepositoryInterface;
1416

1517
/**
@@ -117,6 +119,29 @@ public function testMultiStoreProductIndices()
117119
$fixtureSecondStore->getId()
118120
);
119121

122+
// Check the base url of the products
123+
$this->validateEntityUrl(
124+
'products',
125+
self::VOYAGE_YOGA_BAG_ID,
126+
$defaultStore,
127+
"http://default.test/"
128+
);
129+
130+
$this->validateEntityUrl(
131+
'products',
132+
self::VOYAGE_YOGA_BAG_ID,
133+
$fixtureSecondStore,
134+
"http://fixture_second_store.test/"
135+
);
136+
137+
$this->validateEntityUrl(
138+
'products',
139+
self::VOYAGE_YOGA_BAG_ID,
140+
$fixtureThirdStore,
141+
"http://fixture_third_store.test/"
142+
);
143+
144+
120145
// Unassign product from a single website (removed from test website (second and third store))
121146
$baseWebsite = $this->websiteRepository->get('base');
122147

Test/Integration/TestCase.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Algolia\AlgoliaSearch\Test\Integration;
44

5+
use Algolia\AlgoliaSearch\Api\Data\IndexOptionsInterface;
56
use Algolia\AlgoliaSearch\Exceptions\AlgoliaException;
67
use Algolia\AlgoliaSearch\Exceptions\ExceededRetriesException;
78
use Algolia\AlgoliaSearch\Helper\ConfigHelper;
@@ -21,6 +22,8 @@
2122

2223
abstract class TestCase extends \PHPUnit\Framework\TestCase
2324
{
25+
const DEFAULT_STORE_ID = 1;
26+
2427
/**
2528
* @var ObjectManagerInterface
2629
*/
@@ -291,4 +294,20 @@ function runOnce(callable $callback, ?string $key = null): mixed
291294

292295
return null;
293296
}
297+
298+
/**
299+
* @param string $indexSuffix
300+
* @param int|null $storeId
301+
* @param bool|null $isTmp
302+
* @return IndexOptionsInterface
303+
* @throws NoSuchEntityException
304+
*/
305+
protected function getIndexOptions(
306+
string $indexSuffix,
307+
?int $storeId = self::DEFAULT_STORE_ID,
308+
?bool $isTmp = null
309+
): IndexOptionsInterface
310+
{
311+
return $this->indexOptionsBuilder->buildWithComputedIndex('_' . $indexSuffix, $storeId, $isTmp);
312+
}
294313
}

Test/Integration/_files/second_website_with_two_stores_and_products.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,22 @@
8787
$configManager->setValue('algoliasearch_indexing_manager/algolia_indexing/enable_indexing', 1, 'store', 'fixture_second_store');
8888
$configManager->setValue('algoliasearch_indexing_manager/algolia_indexing/enable_indexing', 1, 'store', 'fixture_third_store');
8989

90+
// Set base urls
91+
$configManager->setValue('web/secure/base_url', 'http://default.test/', 'store', 'default');
92+
$configManager->setValue('web/unsecure/base_url', 'http://default.test/', 'store', 'default');
93+
$configManager->setValue('web/secure/base_link_url', 'http://default.test/', 'store', 'default');
94+
$configManager->setValue('web/unsecure/base_link_url', 'http://default.test/', 'store', 'default');
95+
96+
$configManager->setValue('web/secure/base_url', 'http://fixture_second_store.test/', 'store', 'fixture_second_store');
97+
$configManager->setValue('web/unsecure/base_url', 'http://fixture_second_store.test/', 'store', 'fixture_second_store');
98+
$configManager->setValue('web/secure/base_link_url', 'http://fixture_second_store.test/', 'store', 'fixture_second_store');
99+
$configManager->setValue('web/unsecure/base_link_url', 'http://fixture_second_store.test/', 'store', 'fixture_second_store');
100+
101+
$configManager->setValue('web/secure/base_url', 'http://fixture_third_store.test/', 'store', 'fixture_third_store');
102+
$configManager->setValue('web/unsecure/base_url','http://fixture_third_store.test/', 'store', 'fixture_third_store');
103+
$configManager->setValue('web/secure/base_link_url', 'http://fixture_third_store.test/', 'store', 'fixture_third_store');
104+
$configManager->setValue('web/unsecure/base_link_url','http://fixture_third_store.test/', 'store', 'fixture_third_store');
105+
90106
/* Refresh CatalogSearch index */
91107
/** @var IndexerRegistry $indexerRegistry */
92108
$indexerRegistry = Bootstrap::getObjectManager()

etc/adminhtml/di.xml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
<?xml version="1.0"?>
22
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
3-
<preference for="Magento\Catalog\Model\Product\Url" type="Algolia\AlgoliaSearch\Model\Product\Url" />
43
<preference for="Magento\Config\Controller\Adminhtml\System\Config\Save" type="Algolia\AlgoliaSearch\Controller\Adminhtml\System\Config\Save" />
5-
<type name="Magento\Catalog\Model\Category">
6-
<plugin name="algolia_algoliasearch_plugin_category_url" type="Algolia\AlgoliaSearch\Plugin\CategoryUrlPlugin"/>
7-
</type>
84
<type name="Magento\Catalog\Controller\Adminhtml\Category\Edit">
95
<plugin name="algolia_algoliasearch_plugin_set_admin_current_category" type="Algolia\AlgoliaSearch\Plugin\SetAdminCurrentCategory"/>
106
</type>

etc/di.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@
1414
<plugin name="algoliaCategories" type="Algolia\AlgoliaSearch\Model\Indexer\CategoryObserver"/>
1515
</type>
1616

17+
<type name="Magento\Catalog\Model\Category">
18+
<plugin name="algolia_algoliasearch_plugin_category_url" type="Algolia\AlgoliaSearch\Plugin\CategoryUrlPlugin"/>
19+
</type>
20+
1721
<type name="Magento\Cms\Model\ResourceModel\Page">
1822
<plugin name="algoliaPages" type="Algolia\AlgoliaSearch\Model\Indexer\PageObserver"/>
1923
</type>

0 commit comments

Comments
 (0)