Currently, the use of Drupal\address\Repository\CountryRepository is hardcoded in the constructor of the CreateStoreCommand class.
This way, it's impossible to replace the CountryRepository with an own version of the service.

I replaced the CountryRepository with a my own version so it sorts sorts the countries in the list according to their usage on the site.
Works perfectly for the most part, but when I run drupal console, it crashes with:

TypeError: Argument 3 passed to Drupal\commerce_store\Command\CreateStoreCommand::__construct() must be an instance of Drupal\address\Repository\CountryRepository, instance of Drupal\mymodule\Repository\SortedCountryRepository given in modules/contrib/commerce/modules/store/src/Command/CreateStoreCommand.php on line 85

It should be sufficient to use
CommerceGuys\Addressing\Country\CountryRepositoryInterface
instead.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Kate Heinlein created an issue. See original summary.

agoradesign’s picture

It's also implementing CommerceGuys\Intl\Country\CountryRepositoryInterface, which overlaps with the only function of the CommerceGuys\Addressing\Country\CountryRepositoryInterface, but has some additional functions, which are also used by the command... I guess that this was the reason, why the class was used. The author may have thought, that in doubt better to use the class, or so...

alianov’s picture

Assigned: Unassigned » alianov
alianov’s picture

Status: Active » Needs review
FileSize
2.47 KB
bojanz’s picture

Status: Needs review » Needs work

I see what agoradesign means now :(
Our plan is to move the intl Country code into addressing, but since that hasn't happened yet, we'll need to use the intl interface, not the addressing one.

alianov’s picture

Status: Needs work » Needs review
FileSize
2.46 KB
bojanz’s picture

Status: Needs review » Needs work
-use Drupal\address\Repository\CountryRepository;
+use CommerceGuys\Addressing\Country\CountryRepositoryInterface;

This is still the Addressing, not the intl one interface.

+   * @param \CommerceGuys\Intl\Country\CountryRepositoryInterface $address_country
+   *   The country repository interface.

Should be $country_repository, not $address_country.

alianov’s picture

Status: Needs work » Needs review
FileSize
2.46 KB
bojanz’s picture

Status: Needs review » Fixed
+   * @param \CommerceGuys\Intl\Country\CountryRepositoryInterface $country_repository
+   *   The country repository interface.

This is the country repository, the previous description was correct. We don't inject interfaces, we just use them for typehints.

Fixed on commit. Thanks!

  • bojanz committed 05042bc on 8.x-2.x authored by alianov
    Issue #2949406 by alianov, bojanz, Kate Heinlein: Make CountryRepository...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

aestigarribia’s picture

Updated version of address module (8.x-1.4) cause this issue again on commerce (8.x-2.6) when you run Drupal Console.

jungle’s picture

Category: Task » Bug report
Updated version of address module (8.x-1.4) cause this issue again on commerce (8.x-2.6) when you run Drupal Console.

Same here.

bojanz’s picture

Status: Closed (fixed) » Needs work
bojanz’s picture

Status: Needs work » Fixed
mrhappymac’s picture

Drupal console version 1.8.0 not working following basic install "composer create-project drupalcommerce/project-base mystore --stability dev"

John.nie’s picture

I have saw the patch code on floor #8, my commerce version is 8.x-2.7, but it still reported this error when I do this code:

./vendor/bin/drupal gm
TypeError: Argument 3 passed to Drupal\commerce_store\Command\CreateStoreCommand::__construct() must be an instance of CommerceGuys\Intl\Country\CountryRepositoryInterface, instance of Drupal\address\Repository\CountryRepository given in /var/www/drupal/modules/contrib/commerce/modules/store/src/Command/CreateStoreCommand.php on line 85 #0 [internal function]: Drupal\commerce_store\Command\CreateStoreCommand->__construct(Object(Drupal\commerce_price\CurrencyImporter), Object(Drupal\Core\Entity\EntityTypeManager), Object(Drupal\address\Repository\CountryRepository), Object(Drupal\Core\Render\MetadataBubblingUrlGenerator), Object(Egulias\EmailValidator\EmailValidator))
#1 /var/www/drupal/vendor/symfony/dependency-injection/ContainerBuilder.php(1159): ReflectionClass->newInstanceArgs(Array)
#2 /var/www/drupal/vendor/symfony/dependency-injection/ContainerBuilder.php(623): Symfony\Component\DependencyInjection\ContainerBuilder->createService(Object(Symfony\Component\DependencyInjection\Definition), Array, 'commerce_store....')
#3 /var/www/drupal/vendor/symfony/dependency-injection/ContainerBuilder.php(588): Symfony\Component\DependencyInjection\ContainerBuilder->doGet('commerce_store....', 1)
#4 /var/www/drupal/vendor/drupal/console-core/src/Application.php(441): Symfony\Component\DependencyInjection\ContainerBuilder->get('commerce_store....')
#5 /var/www/drupal/vendor/drupal/console-core/src/Application.php(211): Drupal\Console\Core\Application->registerCommands()
#6 /var/www/drupal/vendor/drupal/console-core/src/Application.php(116): Drupal\Console\Core\Application->loadCommands()
#7 /var/www/drupal/vendor/drupal/console/src/Application.php(64): Drupal\Console\Core\Application->doRun(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#8 /var/www/drupal/vendor/symfony/console/Application.php(148): Drupal\Console\Application->doRun(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#9 /var/www/drupal/vendor/drupal/console/bin/drupal.php(89): Symfony\Component\Console\Application->run()
#10 /var/www/drupal/vendor/drupal/console/bin/drupal(4): require('/var/www/drupal...')
#11 {main}
TypeError: Argument 3 passed to Drupal\commerce_store\Command\CreateStoreCommand::__construct() must be an instance of CommerceGuys\Intl\Country\CountryRepositoryInterface, instance of Drupal\address\Repository\CountryRepository given in Drupal\commerce_store\Command\CreateStoreCommand->__construct() (line 85 of /var/www/drupal/modules/contrib/commerce/modules/store/src/Command/CreateStoreCommand.php).


John.nie’s picture

Status: Fixed » Active
John.nie’s picture

services:
  commerce_store.commerce_create_store:
    class: Drupal\commerce_store\Command\CreateStoreCommand
    arguments: ['@commerce_price.currency_importer', '@entity_type.manager', '@address.country_repository', '@url_generator', '@email.validator']
    tags:
      - { name: drupal.command }

I found it's error from this,
should not be @address.country_repository service name.
but none CommerceGuys\Intl\Country\CountryRepositoryInterface service, what can I do this?

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.