Skip to content

Commit ef1c3ad

Browse files
authored
Merge pull request #1719 from algolia/fix/MAGE-1222-scoped-currency-codes
MAGE-1222 scoped currency codes
2 parents 0ddd8ea + 117a25d commit ef1c3ad

File tree

5 files changed

+30
-19
lines changed

5 files changed

+30
-19
lines changed

Helper/ConfigHelper.php

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1190,17 +1190,32 @@ public function setSorting(array $sorting, string $scope = Magento\Framework\App
11901190
}
11911191

11921192
/**
1193-
* @param $storeId
1194-
* @return string
11951193
* @throws Magento\Framework\Exception\NoSuchEntityException
11961194
*/
1197-
public function getCurrencyCode($storeId = null)
1195+
public function getCurrencyCode(int $storeId = null): string
11981196
{
11991197
/** @var Magento\Store\Model\Store $store */
12001198
$store = $this->storeManager->getStore($storeId);
12011199
return $store->getCurrentCurrencyCode();
12021200
}
12031201

1202+
/**
1203+
* Obtain the store scoped currency configuration or fall back to all allowed currencies
1204+
* @return array
1205+
*/
1206+
public function getAllowedCurrencies(?int $storeId = null): array
1207+
{
1208+
$configured = explode(
1209+
',',
1210+
$this->configInterface->getValue(
1211+
DirCurrency::XML_PATH_CURRENCY_ALLOW,
1212+
ScopeInterface::SCOPE_STORE,
1213+
$storeId
1214+
) ?? ''
1215+
);
1216+
return $configured ?: $this->dirCurrency->getConfigAllowCurrencies();
1217+
}
1218+
12041219
/**
12051220
* @param $storeId
12061221
* @return bool
@@ -1483,6 +1498,8 @@ public function showSuggestionsOnNoResultsPage($storeId = null)
14831498
}
14841499

14851500
/**
1501+
* NOTE: This method is currently only used in integration tests and was removed from the general implementation
1502+
* TODO: Evaluate use cases with product permissions where we may need to restore this functionality
14861503
* @param $groupId
14871504
* @return array
14881505
*/

Service/Product/FacetBuilder.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
use Algolia\AlgoliaSearch\Helper\ConfigHelper;
66
use Magento\Customer\Api\GroupExcludedWebsiteRepositoryInterface;
77
use Magento\Customer\Model\ResourceModel\Group\Collection as GroupCollection;
8-
use Magento\Directory\Model\Currency as CurrencyHelper;
98
use Magento\Framework\Exception\LocalizedException;
109
use Magento\Framework\Exception\NoSuchEntityException;
1110
use Magento\Store\Model\StoreManagerInterface;
@@ -29,7 +28,6 @@ class FacetBuilder
2928
public function __construct(
3029
protected ConfigHelper $configHelper,
3130
protected StoreManagerInterface $storeManager,
32-
protected CurrencyHelper $currencyManager,
3331
protected GroupCollection $groupCollection,
3432
protected GroupExcludedWebsiteRepositoryInterface $groupExcludedWebsiteRepository,
3533
)
@@ -196,7 +194,7 @@ protected function addCategoryFacets(int $storeId, array $facets): array
196194
protected function getPricingAttributes(int $storeId): array
197195
{
198196
$pricingAttributes = [];
199-
$currencies = $this->currencyManager->getConfigAllowCurrencies();
197+
$currencies = $this->configHelper->getAllowedCurrencies($storeId);
200198
foreach ($currencies as $currencyCode) {
201199
$pricingAttributes[] = self::FACET_ATTRIBUTE_PRICE . '.' . $currencyCode . '.default';
202200
$pricingAttributes = array_merge($pricingAttributes, $this->getGroupPricingAttributes($storeId, $currencyCode));

Test/Unit/Service/Product/FacetBuilderTest.php

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,33 +9,29 @@
99
use Algolia\AlgoliaSearch\Service\Product\FacetBuilder;
1010
use Magento\Customer\Api\GroupExcludedWebsiteRepositoryInterface;
1111
use Magento\Customer\Model\ResourceModel\Group\Collection as GroupCollection;
12-
use Magento\Directory\Model\Currency as CurrencyHelper;
1312
use Magento\Framework\Exception\LocalizedException;
1413
use Magento\Framework\Exception\NoSuchEntityException;
1514
use Magento\Store\Model\StoreManagerInterface;
1615
use PHPUnit\Framework\TestCase;
1716

1817
class FacetBuilderTest extends TestCase
1918
{
20-
protected FacetBuilder $facetBuilder;
21-
protected ConfigHelper $configHelper;
22-
protected StoreManagerInterface $storeManager;
23-
protected CurrencyHelper $currencyManager;
24-
protected GroupCollection $groupCollection;
25-
protected GroupExcludedWebsiteRepositoryInterface $groupExcludedWebsiteRepository;
19+
protected ?FacetBuilder $facetBuilder;
20+
protected ?ConfigHelper $configHelper;
21+
protected ?StoreManagerInterface $storeManager;
22+
protected ?GroupCollection $groupCollection;
23+
protected ?GroupExcludedWebsiteRepositoryInterface $groupExcludedWebsiteRepository;
2624

2725
protected function setUp(): void
2826
{
2927
$this->configHelper = $this->createMock(ConfigHelper::class);
3028
$this->storeManager = $this->createMock(StoreManagerInterface::class);
31-
$this->currencyManager = $this->createMock(CurrencyHelper::class);
3229
$this->groupCollection = $this->createMock(GroupCollection::class);
3330
$this->groupExcludedWebsiteRepository = $this->createMock(GroupExcludedWebsiteRepositoryInterface::class);
3431

3532
$this->facetBuilder = new FacetBuilderTestable(
3633
$this->configHelper,
3734
$this->storeManager,
38-
$this->currencyManager,
3935
$this->groupCollection,
4036
$this->groupExcludedWebsiteRepository
4137
);
@@ -54,8 +50,8 @@ protected function mockFacets(): void
5450

5551
protected function mockStoreConfig($storeId, $websiteId): void
5652
{
57-
$this->currencyManager
58-
->method('getConfigAllowCurrencies')
53+
$this->configHelper
54+
->method('getAllowedCurrencies')
5955
->willReturn(['EUR', 'USD']);
6056

6157
$storeMock = $this->createMock(\Magento\Store\Api\Data\StoreInterface::class);

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"description": "Algolia Search & Discovery extension for Magento 2",
44
"type": "magento2-module",
55
"license": ["MIT"],
6-
"version": "3.15.0",
6+
"version": "3.16.0-dev",
77
"require": {
88
"php": "~8.1|~8.2|~8.3",
99
"magento/framework": "~103.0",

etc/module.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0"?>
22
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
3-
<module name="Algolia_AlgoliaSearch" setup_version="3.15.0">
3+
<module name="Algolia_AlgoliaSearch" setup_version="3.16.0-dev">
44
<sequence>
55
<module name="Magento_Theme"/>
66
<module name="Magento_Backend"/>

0 commit comments

Comments
 (0)