{"id":19622186,"url":"https://github.com/commercetools/commercetools-php-symfony","last_synced_at":"2025-04-28T03:32:31.271Z","repository":{"id":36295255,"uuid":"40599797","full_name":"commercetools/commercetools-php-symfony","owner":"commercetools","description":null,"archived":false,"fork":false,"pushed_at":"2019-11-28T15:27:04.000Z","size":4686,"stargazers_count":10,"open_issues_count":5,"forks_count":6,"subscribers_count":46,"default_branch":"develop","last_synced_at":"2025-04-20T15:17:55.480Z","etag":null,"topics":["audit-sdk"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/commercetools.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-08-12T12:38:27.000Z","updated_at":"2022-10-01T11:40:28.000Z","dependencies_parsed_at":"2022-09-04T19:51:15.008Z","dependency_job_id":null,"html_url":"https://github.com/commercetools/commercetools-php-symfony","commit_stats":null,"previous_names":[],"tags_count":14,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/commercetools%2Fcommercetools-php-symfony","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/commercetools%2Fcommercetools-php-symfony/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/commercetools%2Fcommercetools-php-symfony/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/commercetools%2Fcommercetools-php-symfony/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/commercetools","download_url":"https://codeload.github.com/commercetools/commercetools-php-symfony/tar.gz/refs/heads/develop","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251246391,"owners_count":21558762,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["audit-sdk"],"created_at":"2024-11-11T11:26:28.853Z","updated_at":"2025-04-28T03:32:26.258Z","avatar_url":"https://github.com/commercetools.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# commercetools Symfony bundle Beta\n\nThe commercetools Symfony Bundle is a collection of Symfony bundles that ease the use of the\n[commercetools PHP-SDK](https://github.com/commercetools/commercetools-php-sdk) when implementing\na Symfony project.\n\n##### Table of contents\n\n  * [Pre-requisites](#pre-requisites)\n  * [Installation](#installation)\n    + [Verify configuration](#verify-configuration)\n  * [Usage](#usage)\n    + [Available services](#available-services)\n      - [Services list](#services-list)\n    + [Console Commands](#console-commands)\n      - [Available console commands](#available-console-commands)\n    + [Using SDK Models in twig templates](#using-sdk-models-in-twig-templates)\n  * [Quick-start](#quick-start)\n  * [Disclaimer for ExampleBundle (dev)](#disclaimer-for-examplebundle--dev-)\n  * [Testing](#testing)\n  * [Issues](#issues)\n  * [Contribute](#contribute)\n  * [License](#license)\n\n\n## Pre-requisites\nComposer :\nTo install the composer go to https://getcomposer.org/doc/00-intro.md\n\n## Installation\nYou can either create a new Symfony project or use an existing Symfony project (ver. 3.4 and above)\n\nCreate a new Symfony project using the following command: \n\n```sh\ncomposer create-project symfony/skeleton \u003cproject-name\u003e\n```\n\nNext, navigate to the project's directory and run the following command: \n\n```sh\ncomposer config extra.symfony.allow-contrib true\n```\n\nThis automates most of the configuration using the `recipes-contrib` bundle from Symfony Flex.\n\nNext, install the commercetools Symfony bundle. To do this, run the following from the command line\n```sh\ncomposer require commercetools/symfony-bundle\n```\n\nAlternatively, open the **composer.json** file, add `\"commercetools/symfony-bundle\"` to the `require` attribute, and run\n```sh\ncomposer install\n```\n\nNext, open the`.env` file or create a `.env.local` file on root directory and edit the following \nlines to add your credentials. You can retrieve your API client credentials from the Merchant Center under\n`Commercetools Merchant Center \u003e Settings \u003e Developer Settings`, when you create a new \nAPI Client. Note that for security reasons you cannot retrieve the `CTP_CLIENT_SECRET` \nfor clients created in the past.\n\n```dotenv\nCTP_CLIENT_ID=\u003cyour client id\u003e\nCTP_CLIENT_SECRET=\u003cyour client secret\u003e\nCTP_PROJECT_KEY=\u003cyour project id\u003e\nCTP_AUTH_URL=https://auth.commercetools.com\nCTP_API_URL=https://api.commercetools.com\nCTP_SCOPES=\u003cyour desired scopes\u003e\n```\n\nor for US region change URLs to\n\n```dotenv\nCTP_AUTH_URL=https://auth.commercetools.co\nCTP_API_URL=https://api.commercetools.co\n```\n\nFor more information about using `.env` and `.env.local`, see\n[here](https://symfony.com/doc/current/configuration/dot-env-changes.html) and\n[here](https://symfony.com/blog/new-in-symfony-4-2-define-env-vars-per-environment)\n\n### Verify configuration\n\nTo verify that your configuration works, after adding your client credentials on the `.env` file\nrun the following on the command line:\n```sh\nbin/console commercetools:project-info\n```\nIf everything is set up correctly, this should return\nthe details of your project. For example:\n\n```\nProject's key: super-cool-project-4\nProject's name: my eshop at commercetools\nCountries: DE, US\nCurrencies: EUR\nLanguages: en\nCreated at: 2019-02-04T11:28:49+00:00\nMessages: disabled\n```\n\n\n## Usage\n\nThe commercetools Symfony bundle consists of 8 smaller bundles (The dependencies mentioned are\nonly the additional ones, required for bundle-specific functionalities)\n\n- CartBundle\n- CatalogBundle\n- CtpBundle\n- CustomerBundle\n    - Dependency: `symfony/security-bundle`\n- ReviewBundle\n- SetupBundle\n    - Dependency: `symfony/console`\n- ShoppingListBundle\n- StateBundle\n    - Dependency: `symfony/console`, `symfony/workflow`, `twig/extensions`\n    \n\nBy default, `CtpBundle` \u0026 `CustomerBundle` are enabled for all environments.\n`SetupBundle` \u0026 `StateBundle` are only enabled for for development environments. To\nsee which bundles are enabled and optionally enable or disable them, edit\nthe `config/bundles.php` file.\n\n\n### Available services\n\nThe main idea is that in each Bundle there are some reusable services that you\nmay inject directly in your app. As a generic pattern there are a \ncouple of `*Manager` services, that provide related actions. So, for example in `CartManager`\nyou will find helpers like `getCart`, `createCartForUser` and `update`. The `update` service\nreturns a  `CartUpdateBuilder` where you can dynamically build update actions. To autowire\na service, for example `CatalogManager`, in a controller action, do the following: \n\n```php\n\u003c?php\nnamespace App\\Controller;\n\nuse Commercetools\\Symfony\\CatalogBundle\\Manager\\CatalogManager;\nuse Symfony\\Component\\HttpFoundation\\Response;\n\nclass MyController\n{\n    public function index(CatalogManager $manager)\n    {\n        /** @var CategoryCollection $categories */\n        $categories = $manager-\u003egetCategories('en');\n\n        return new Response(\n            '\u003chtml\u003e\u003cbody\u003ecategories: '\n            // handle CategoryCollection $categories\n            .'\u003c/body\u003e\u003c/html\u003e'\n        );\n    }\n}\n```\n\n#### Services list\n\n- CartBundle: Provides helpers for carts, orders, payments and shipping-methods\n    - CartManager\n    - OrderManager\n    - PaymentManager\n    - ShippingMethodManager\n- CatalogBundle: Provides helpers for products, product-types, product-projections,\n      categories, product search and facets\n    - CatalogManager\n    - Search\n- CtpBundle: Provides the core helpers required by the rest bundles. Includes the HTTP client\n      factory, the custom-type-provider for handling custom-types, the locale converter,\n      the mapper factory and the context factory\n    - ClientFactory\n    - ContextFactory\n    - MapperFactory\n    - LocaleConverter\n    - CustomTypeProvider\n- CustomerBundle: Provides user and customer related features including an integrated\n      authentication provider\n    - CustomerManager\n    - AuthenticationProvider\n    - UserProvider\n- ReviewBundle: Provides helpers for reviews\n    - ReviewManager\n- ShoppingListBundle: Provides helpers for shopping-lists\n    - ShoppingListManager\n- StateBundle: Provides helpers for handling the state of LineItems, Orders, Payments, Products\n      and Reviews. It can be configured as a `workflow` or as a `state_machine` and takes care of the\n      transition between the states.\n    - CtpMarkingStoreLineItemState\n    - CtpMarkingStoreOrderState\n    - CtpMarkingStorePaymentState\n    - CtpMarkingStoreProductState\n    - CtpMarkingStoreReviewState\n    \n### Console Commands\n\n`SetupBundle` and `StateBundle` come together with a few handy console commands. These commands\nautomate tasks during development and allow a 2-way sync between an online project and a local configuration.\nTo use a console command navigate to your project's directory and run\n\n```sh\nbin/console commercetools:\u003ccommand-name\u003e\n```\n\n#### Available console commands\n\n- SetupBundle\n    - `bin/console commercetools:project-info`: Fetches and displays information from commercetools platform\n    about the selected project\n    - `bin/console commercetools:project-apply-configuration`: Save the local project configuration that resides under\n    `commercetools` key, on the online commercetools platform\n    - `bin/console commercetools:create-custom-type`: Interactive CLI to create CustomTypes on your project\n    - `bin/console commercetools:sync-custom-types-from-server`: Saves locally the CustomTypes currently present on the online project,\n    in the `\u003cPROJECT_DIR\u003e/config/packages/\u003cENV\u003e/custom_types.yaml` file\n    - `bin/console commercetools:sync-custom-types-from-local`: Saves or updates the CustomTypes present locally in \n    the `\u003cPROJECT_DIR\u003e/config/packages/\u003cENV\u003e/custom_types.yaml` file, on your online commercetools project\n    \n- StateBundle\n    - `bin/console commercetools:set-state-machine-config`: Fetches States from commercetools platform and creates a \n    Symfony `state_machine` type configuration file at \n    `\u003cPROJECT_DIR\u003e/config/packages/\u003cENV\u003e/workflow.yaml`\n    - `bin/console commercetools:set-workflow-config`: Fetches States from commercetools platform and creates a Symfony\n    `workflow` type configuration file at `\u003cPROJECT_DIR\u003e/config/packages/\u003cENV\u003e/workflow.yaml`\n    \n      More info on working with Symfony Workflows can be found in Symfony's [documentation](https://symfony.com/doc/current/workflow/usage.html):\n\n### Using SDK Models in twig templates\n\nIf you are using Twig for your templating engine you can print the value of a nested attribute of any \n[SDK Model](https://commercetools.github.io/commercetools-php-sdk/docs/master/namespace-Commercetools.Core.Model.html)\njust by referring the attribute's path and name. For example the following two are valid representations:\n```\n{{ product.masterVariant.attributes.test.value }}\n{{ attribute(product.masterVariant.attributes, 'custom-attribute').value }}\n```\n\n## Quick-start\n\nFor a more detailed quick start guide you can continue [here](quickstart.md)\n\n## Disclaimer for ExampleBundle (dev)\n\nThere is an ExampleBundle provided in the repository which tries to demonstrate a sample\neshop implementation making use of the other Bundles provided. This ExampleBundle is currently \nunder development. It may includes outdated code, is not properly tested and right now\nis not encouraged to be used in any production environment. For now, we don't guarantee any\nnon breaking changes. We intend to fix the problems, improve it and create a more helpful \ngeneric example.\n\n## Testing\n\nClone the project and navigate on the project's directory. On the command line, run\n```sh\ncomposer install --dev\n./vendor/bin/phpunit\n```\n\n## Issues\n\nCheck current [issues](https://github.com/commercetools/commercetools-php-symfony/issues/) \nor [open](https://github.com/commercetools/commercetools-php-symfony/issues/new)\na new one\n\n## Contribute\n\n[Contribute](CONTRIBUTING.md)\n\n## License\nThis bundle is under the MIT license. See the complete license in the bundle:\n[MIT License](LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcommercetools%2Fcommercetools-php-symfony","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcommercetools%2Fcommercetools-php-symfony","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcommercetools%2Fcommercetools-php-symfony/lists"}