commercetools / commercetools-php-symfony

MIT License
10 stars 6 forks source link

Flex recipes failing for Symfony 4.2.5 #69

Closed rkmourya closed 5 years ago

rkmourya commented 5 years ago

I am trying to use this bundle with Symfony 4.2.5. I followed the steps mentioned in the readme.

composer config extra.symfony.allow-contrib true
composer require commercetools/symfony-bundle

But no bundle got added to config/bundles.php Also it seems yml files are no updated for required config

If I am manually adding below entries in config/bundles.php

    Commercetools\Symfony\CtpBundle\CtpBundle::class => ['all' => true],
    Commercetools\Symfony\CartBundle\CartBundle::class => ['all' => true],

I am getting below error. In CommercetoolsExtension.php line 32: Notice: Undefined offset: 0

I tried making below entries in config/config.yml, but nothing helping

commercetools:
  credentials:
    client_id: "%commercetools.client_id%"
    client_secret: "%commercetools.client_secret%"
    project: "%commercetools.project%"
    scope: "%commercetools.scope%"
    api_url: "%commercetools.api_url%"
    oauth_url: "%commercetools.oauth_url%"
nikossvnk commented 5 years ago

There is still an issue with the recipe and is not yet officialy published, which explains why you didn't get the initial configuration. For now, you can do it manually by edititng:

file config/packages/commercetools.yaml

commercetools:
    api:
        default_client: 'default'
        clients:
            default:
                client_id: '%env(CTP_CLIENT_ID)%'
                client_secret: '%env(CTP_CLIENT_SECRET)%'
                project: '%env(CTP_PROJECT_KEY)%'
                scope: '%env(CTP_SCOPES)%'
                oauth_url: '%env(CTP_AUTH_URL)%'
                api_url: '%env(CTP_API_URL)%'

file config/bundles.php for minimun enabled bundles:

    Commercetools\Symfony\CtpBundle\CtpBundle::class => ['all' => true],
    Commercetools\Symfony\SetupBundle\SetupBundle::class => ['all' => true],

or you may enable all bundles:

    Commercetools\Symfony\CtpBundle\CtpBundle::class => ['all' => true],
    Commercetools\Symfony\CartBundle\CartBundle::class => ['all' => true],
    Commercetools\Symfony\CustomerBundle\CustomerBundle::class => ['all' => true],
    Commercetools\Symfony\ReviewBundle\ReviewBundle::class => ['all' => true],
    Commercetools\Symfony\CatalogBundle\CatalogBundle::class => ['all' => true],
    Commercetools\Symfony\ShoppingListBundle\ShoppingListBundle::class => ['all' => true],
    Commercetools\Symfony\SetupBundle\SetupBundle::class => ['all' => true],
    Commercetools\Symfony\StateBundle\StateBundle::class => ['all' => true],

file .env (you need to replace your credentials ofcource)

CTP_CLIENT_ID=<your client id>
CTP_CLIENT_SECRET=<your client secret>
CTP_PROJECT_KEY=<your project id>
CTP_AUTH_URL=https://auth.commercetools.com or https://auth.commercetools.co
CTP_API_URL=https://api.commercetools.com or https://api.commercetools.co
CTP_SCOPES=<your desired scopes>

Optionally, in case you want to use commercetools for the user login system you can edit file config/packages/security.yaml as:

security:
    providers:
        ctp:
            id: Commercetools\Symfony\CustomerBundle\Security\User\UserProvider
    access_control:
        - { path: /user/, roles: ROLE_USER }
    encoders:
        Symfony\Component\Security\Core\User\User: plaintext
        Commercetools\Symfony\CustomerBundle\Security\User\User: plaintext
    firewalls:
        main:
            anonymous: ~
            commercetools-login:
                login_path: login
                check_path: login_check
            logout:
                path: logout
        dev:
            pattern: ^/(_(profiler|wdt)|css|images|js)/
            security: false
        default:
            anonymous: ~

Apologies for the inconvinience

rkmourya commented 5 years ago

Thanks for the configuration.

Other than that there seems to be issue with dependencies of the project. I got below error now.

In CheckExceptionOnInvalidReferenceBehaviorPass.php line 86: The service "commercetools.profiler_controller" has a dependency on a non-existent service "templating".

I resolved this by manually including templating

composer require symfony/templating

and adding below to config/packages/framework.yaml

framework:
    templating:
        engines:
            - twig

Now running below command

php bin/console commercetools:project-info

throws below error.

console.ERROR: Error thrown while running command "commercetools:project-info". Message: "Error completing request" {"exception":"[object] (Commercetools\\Core\\Error\\ApiException(code: 0): Error completing request at C:\\projects\\commercetools-gateway\\vendor\\commercetools\\php-sdk\\src\\Core\\Error\\ApiException.php:50)","command":"commercetools:project-info","message":"Error completing request"} []
console.DEBUG: Command "commercetools:project-info" exited with code "1" {"command":"commercetools:project-info","code":1} []

There is no proper error code to trace this error.

rkmourya commented 5 years ago

I was able to resolve the error. All working now.

However note that symfony/templating dependency as mentioned in earlier tag needs to be fixed. Also it would be better to throw exceptions instead of error getting shown if configurations are not in place or dependency is missing

nikossvnk commented 5 years ago

Could you please describe what was the error and what was the solution? For a possible future reference.

Also, regarding symfony/templating it is included in the composer.json, so it should be there. I will also try to provide a solution so that no longer need to manually include the templating system in framework.yaml (as you mentioned above) . Thanks for the feedback

rkmourya commented 5 years ago

Problem was with development environment. Seems some extension required by the php-sdk was missing. Commercetools\Core\Error\ApiException(code: 0) exception should give a proper message about missing dependency. I switched to environment where most of the extension is enabled and it worked.