Skip to content

Commit

Permalink
fix country resolution after it'been invalidated
Browse files Browse the repository at this point in the history
  • Loading branch information
thomas-kl1 committed Sep 8, 2021
1 parent da1ad52 commit e875be9
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
10 changes: 8 additions & 2 deletions CustomerData/CountryStoreData.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,16 @@
use Opengento\CountryStore\Api\CountryRegistryInterface;
use Opengento\CountryStore\Api\CountryStoreResolverInterface;
use Opengento\CountryStore\Api\Data\CountryInterface;
use Opengento\CountryStore\Model\Resolver\DefaultCountryStore;
use Opengento\CountryStore\Model\Resolver\ResolverFactory;
use Psr\Log\LoggerInterface;

final class CountryStoreData implements SectionSourceInterface
{
private CountryRegistryInterface $countryRegistry;

private ResolverFactory $countryResolverFactory;

private CountryStoreResolverInterface $countryStoreResolver;

private StoreManagerInterface $storeManager;
Expand All @@ -30,12 +34,14 @@ final class CountryStoreData implements SectionSourceInterface

public function __construct(
CountryRegistryInterface $countryRegistry,
ResolverFactory $countryResolverFactory,
CountryStoreResolverInterface $countryStoreResolver,
StoreManagerInterface $storeManager,
ExtensibleDataObjectConverter $dataObjectConverter,
LoggerInterface $logger
) {
$this->countryRegistry = $countryRegistry;
$this->countryResolverFactory = $countryResolverFactory;
$this->countryStoreResolver = $countryStoreResolver;
$this->storeManager = $storeManager;
$this->dataObjectConverter = $dataObjectConverter;
Expand All @@ -47,8 +53,8 @@ public function getSectionData(): array
$country = $this->countryRegistry->get();

if ($this->isInvalidated($country)) {
$this->countryRegistry->clear();
$country = $this->countryRegistry->get();
$country = $this->countryResolverFactory->get(DefaultCountryStore::RESOLVER_CODE)->getCountry();
$this->countryRegistry->set($country->getCode());
}

return $this->dataObjectConverter->toFlatArray($country);
Expand Down
2 changes: 1 addition & 1 deletion view/frontend/web/js/view/country-store-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ define([
return Component.extend({
initialize() {
this._super();
var _self = this;
const _self = this;

customerData.getInitCustomerData().done(function () { _self.initCountryStoreData(); });
},
Expand Down

0 comments on commit e875be9

Please sign in to comment.