"Fatal error: commerceguys\addressing" - inability to purchase the course due to unknown issue

Created on 10 June 2023, over 1 year ago
Updated 11 June 2023, over 1 year ago

Problem/Motivation

I am working on website where the users will be able to purchase courses. After enabling the module Opigno Commerce which is succesfully installed, the shop is created automatically and everything seems to be working properly. However, after configuration of payment gateway and conducting payment-related tests, the following error appears:

"Fatal error: Declaration of Drupal\address\Repository\CountryRepository::loadDefinitions(string $locale): array must be compatible with CommerceGuys\Addressing\Country\CountryRepository::loadDefinitions($locale) in /var/www/html/lmsaadrupal/web/modules/contrib/address/src/Repository/CountryRepository.php on line 43"

Everything has been deleted and installed again adding a manual payment gateway. The purchase process works well but the above error appears while attempting to edit the store: /admin/commerce/config/stores
Any advice would be useful as I am not able to resolve this issue by myself.

Steps to reproduce

I use the version
PHP 8.1.
mysql Ver 8.0.33-0ubuntu0.22.04.2 for Linux on x86_64 ((Ubuntu))
Ubuntu 22.04.1 LTS

Drupal core 9.5.9
Commerce 8.x-2.36
Opigno 3.1.0
Address 8.x-1.12
commerceguys\addressing 1.4.2

πŸ› Bug report
Status

Fixed

Version

1.12

Component

Code

Created by

πŸ‡΅πŸ‡±Poland jacek061192

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @jacek061192
  • πŸ‡·πŸ‡ΈSerbia bojanz

    Errors like this happen when the version of the module is not in sync with the version of the library.

    Don't know how, but your site is definitely not running commerceguys/addressing v.1.4.2 as it has the right typehints:
    https://github.com/commerceguys/addressing/blob/v1.4.2/src/Country/Count...

  • πŸ‡ΊπŸ‡ΈUnited States TolstoyDotCom L.A.

    The error message indicates that the definitions of loadDefinitions are different, yet they seem the same. Are you sure about the versions?

    What do the lines around line 43 of web/modules/contrib/address/src/Repository/CountryRepository.php look like?

    If you search (probably in your vendor directory) for CountryRepository.php, what do the lines around the line with loadDefinitions look like?

  • πŸ‡΅πŸ‡±Poland jacek061192

    Hi guys, thanks for quick response. Below you can find the whole code from the file. Indeed, it is different than the one in the repository https://github.com/commerceguys/addressing/blob/v1.4.2/src/Country/Count...

    Below you can see the photo from Ludwig module.

    Do you have any ideas how it can be fixed?

    <?php
    
    namespace Drupal\address\Repository;
    
    use CommerceGuys\Addressing\Country\CountryRepository as ExternalCountryRepository;
    use Drupal\Core\Cache\CacheBackendInterface;
    use Drupal\Core\Language\LanguageManagerInterface;
    
    /**
     * Defines the country repository.
     *
     * Countries are stored on disk in JSON and cached inside Drupal.
     */
    class CountryRepository extends ExternalCountryRepository {
    
      /**
       * The cache backend.
       *
       * @var \Drupal\Core\Cache\CacheBackendInterface
       */
      protected $cache;
    
      /**
       * Creates a CountryRepository instance.
       *
       * @param \Drupal\Core\Cache\CacheBackendInterface $cache
       *   The cache backend.
       * @param \Drupal\Core\Language\LanguageManagerInterface $language_manager
       *   The language manager.
       */
      public function __construct(CacheBackendInterface $cache, LanguageManagerInterface $language_manager) {
        parent::__construct();
    
        $this->cache = $cache;
        // The getCurrentLanguage() fallback is a workaround for core bug #2684873.
        $language = $language_manager->getConfigOverrideLanguage() ?: $language_manager->getCurrentLanguage();
        $this->defaultLocale = $language->getId();
      }
    
      /**
       * {@inheritdoc}
       */
      protected function loadDefinitions(string $locale): array {
        if (isset($this->definitions[$locale])) {
          return $this->definitions[$locale];
        }
    
        $cache_key = 'address.countries.' . $locale;
        if ($cached = $this->cache->get($cache_key)) {
          $this->definitions[$locale] = $cached->data;
        }
        else {
          $filename = $this->definitionPath . $locale . '.json';
          $this->definitions[$locale] = json_decode(file_get_contents($filename), TRUE);
          $this->cache->set($cache_key, $this->definitions[$locale], CacheBackendInterface::CACHE_PERMANENT, ['countries']);
        }
    
        return $this->definitions[$locale];
      }
    
    }
    
  • πŸ‡·πŸ‡ΈSerbia bojanz

    You will have to use Ludwig (admin/reports/packages) to update/reinstall the library.

    Docs:
    https://www.drupal.org/docs/contributed-modules/ludwig/maintenance-of-lu... β†’

  • πŸ‡΅πŸ‡±Poland jacek061192

    I deleted from Address module the library, v1.4.2. I used the command drush cr to rebuild cache. The library appeared again in the catalogue with new date, screenshot below. Unfortunately, it did not change anything. Is it possible that this library might be in another place? Because while installing Address module I didn't use Ludwig module. Everything was installed through composer.

  • πŸ‡΅πŸ‡±Poland jacek061192

    I have already found the solution. It turned out the library was automatically added to Vendor each time the composer update was enabled. The only thing that needed to be done was deleting the library front Vendor. Everything is nΓ³w working properly. Thanks for your advice.

  • Status changed to Fixed over 1 year ago
  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.71.5 2024