Score:0

How do I fix this error about a missing class?

pk flag

I'm using the Commerce Canada Post module.

The code in the src/Plugin/Commerce/ShippingMethod/CanadaPost.php file uses a CanadaPost\Rating class which isn't defined that namespace and it causes an error.

The src/Api/RatingService.php file contains the following code.

/**
 * Returns an initialized Canada Post Rating service.
 *
 * @param array $api_settings
 *   The Canada Post API settings.
 *
 * @return \CanadaPost\Rating
 *   The rating service class.
 */
protected function getRequest(array $api_settings) {
  $config = $this->getRequestConfig($api_settings);

  return new Rating($config);
}

How do I fix this error?

Score:2
in flag

The CanadaPost\Rating class is not part of the Commerce Canada Post module, rather it's part of a dependency, the PHP Canada Post API, that should be installed into your vendor directory by composer in the thejacer87/php-canadapost-api subdirectory.

If it's not there, then my best guess is that you tried to install Commerce Canada Post without using composer. Install it, the Commerce Canada Post module, with composer and the dependency will be installed and it'll resolve your error.

See Download contributed modules, themes and their dependencies using Composer on drupal.org for how to install a module with composer.

composer require drupal/commerce_canadapost
pk flag
Thanks @sonfd for clear explanation after install thejacer87/php-canadapost-api through composer now its working. you save my day.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.