Skip to content

Commit

Permalink
Me endpoints (#75)
Browse files Browse the repository at this point in the history
Me endpoints
  • Loading branch information
Jens Schulze committed Oct 1, 2019
2 parents 7ba9af3 + 73eca4d commit 71ca1b8
Show file tree
Hide file tree
Showing 483 changed files with 21,278 additions and 2,445 deletions.
4 changes: 3 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,14 @@
},
"require": {
"php": ">=7.0",
"ext-json": "*",
"symfony/framework-bundle": "^3.4 | ^4.0",
"symfony/form": "^3.4 | ^4.0",
"symfony/security-bundle": "^3.4 | ^4.0",
"symfony/validator": "^3.4 | ^4.0",
"symfony/serializer": "^3.4 | ^4.0",
"symfony/cache": "^3.4 | ^4.0",
"commercetools/php-sdk": "^2.6",
"commercetools/php-sdk": "dev-develop",
"symfony/var-dumper": "^3.4 | ^4.0",
"symfony/dotenv": "^3.4 | ^4.0",
"symfony/stopwatch": "^3.4 | ^4.0",
Expand All @@ -28,6 +29,7 @@
"require-dev": {
"phpunit/phpunit": "^7.0 | ^6.0 | ^5.0",
"symfony/phpunit-bridge": "^3.4 | ^4.0",
"phpspec/prophecy": "~1.0",
"commercetools/commercetools-api-reference": "dev-master",
"matthiasnoback/symfony-dependency-injection-test": "^3.0",
"symfony/test-pack": "^1.0",
Expand Down
85 changes: 83 additions & 2 deletions quickstart.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Quick-start

* [Pre-requisites](#pre-requisites)
* [Create a basic page](#create-a-basic-page)
* [Install ExampleBundle](#examplebundle)
* [Import sample data](#sample-data)
* [Preview in browser](#preview-in-browser)

### Pre-requisites

* You have successfully completed the Installation step and verified that everything works fine.
Expand Down Expand Up @@ -74,6 +80,83 @@ class DefaultController extends AbstractController
{% endblock %}
```

## ExampleBundle

You may enable ExampleBundle to have a running instance of the Sunrise sample e-shop. It
resembles an e-shop demonstrating sample data, templates and functionalities.

* run `composer require symfony/asset symfony/translation`
* enable all commercetools bundles in `config/bundles.php`
```php
return [
...
Commercetools\Symfony\CtpBundle\CtpBundle::class => ['all' => true],
Commercetools\Symfony\ShoppingListBundle\ShoppingListBundle::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\ExampleBundle\ExampleBundle::class => ['all' => true],
Commercetools\Symfony\SetupBundle\SetupBundle::class => ['all' => true],
Commercetools\Symfony\StateBundle\StateBundle::class => ['all' => true],
...
];
```
* import the ExampleBundle routes in `config/routes.yaml`
```yaml
_example:
resource: "@ExampleBundle/Resources/config/routing.yml"
```

* enable user/customer management and authentication to be managed by commercetools
by editing `congig/packages/security.yaml` as:
```yaml
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
default_target_path: _ctp_example_index
logout:
path: logout
target: _ctp_example_index
dev:
pattern: ^/(_(profiler|wdt)|css|images|js)/
security: false
default:
anonymous: ~
```
* note: to disable errors on undefined twig variables change in `config/packages/twig.yaml`. This is
because right now there are undefined variables in the Sunrise templates. This setting should and it is
recommended to be back to it's original value for any real world scenario.
```yaml
twig:
strict_variables: false
```

* recreate the translation messages by running:
`bin/console translation:update --dump-messages --force en ExampleBundle`

## Sample Data

* At this point no data is inserted in the shop which will result to your sample e-shop be
more or less empty and no sample products/categories/etc
will be demonstrated. To import the sample Sunrise data please follow the procedure
[here](https://github.com/commercetools/commercetools-sunrise-data/). You may run this importer
in a repository other than the one you currently work at, since you will not need any of it
after running it once on your project.



## Preview in browser

Expand All @@ -86,5 +169,3 @@ created your project in commercetools, you will have to manually add some produc
the list will be empty. If you, manually added some products and your locale was not `en`,
you should change the parameter `en` used in the `DefaultController` above, to match the
locale that you used in your products.


2 changes: 1 addition & 1 deletion src/CartBundle/Event/CartCreateEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

namespace Commercetools\Symfony\CartBundle\Event;

use Symfony\Component\EventDispatcher\Event;
use Symfony\Contracts\EventDispatcher\Event;

class CartCreateEvent extends Event
{
Expand Down
2 changes: 1 addition & 1 deletion src/CartBundle/Event/CartGetEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
namespace Commercetools\Symfony\CartBundle\Event;

use Commercetools\Core\Model\Cart\Cart;
use Symfony\Component\EventDispatcher\Event;
use Symfony\Contracts\EventDispatcher\Event;

class CartGetEvent extends Event
{
Expand Down
2 changes: 1 addition & 1 deletion src/CartBundle/Event/CartNotFoundEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

namespace Commercetools\Symfony\CartBundle\Event;

use Symfony\Component\EventDispatcher\Event;
use Symfony\Contracts\EventDispatcher\Event;

class CartNotFoundEvent extends Event
{
Expand Down
2 changes: 1 addition & 1 deletion src/CartBundle/Event/CartPostCreateEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
namespace Commercetools\Symfony\CartBundle\Event;

use Commercetools\Core\Model\Cart\Cart;
use Symfony\Component\EventDispatcher\Event;
use Symfony\Contracts\EventDispatcher\Event;

class CartPostCreateEvent extends Event
{
Expand Down
2 changes: 1 addition & 1 deletion src/CartBundle/Event/CartPostUpdateEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

use Commercetools\Core\Model\Cart\Cart;
use Commercetools\Core\Request\AbstractAction;
use Symfony\Component\EventDispatcher\Event;
use Symfony\Contracts\EventDispatcher\Event;

class CartPostUpdateEvent extends Event
{
Expand Down
2 changes: 1 addition & 1 deletion src/CartBundle/Event/CartUpdateEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

use Commercetools\Core\Model\Cart\Cart;
use Commercetools\Core\Request\AbstractAction;
use Symfony\Component\EventDispatcher\Event;
use Symfony\Contracts\EventDispatcher\Event;

class CartUpdateEvent extends Event
{
Expand Down
2 changes: 1 addition & 1 deletion src/CartBundle/Event/OrderCreateEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

namespace Commercetools\Symfony\CartBundle\Event;

use Symfony\Component\EventDispatcher\Event;
use Symfony\Contracts\EventDispatcher\Event;

class OrderCreateEvent extends Event
{
Expand Down
2 changes: 1 addition & 1 deletion src/CartBundle/Event/OrderPostCreateEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

namespace Commercetools\Symfony\CartBundle\Event;

use Symfony\Component\EventDispatcher\Event;
use Symfony\Contracts\EventDispatcher\Event;

class OrderPostCreateEvent extends Event
{
Expand Down
2 changes: 1 addition & 1 deletion src/CartBundle/Event/OrderPostUpdateEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

use Commercetools\Core\Model\Order\Order;
use Commercetools\Core\Request\AbstractAction;
use Symfony\Component\EventDispatcher\Event;
use Symfony\Contracts\EventDispatcher\Event;

class OrderPostUpdateEvent extends Event
{
Expand Down
2 changes: 1 addition & 1 deletion src/CartBundle/Event/OrderUpdateEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

use Commercetools\Core\Model\Order\Order;
use Commercetools\Core\Request\AbstractAction;
use Symfony\Component\EventDispatcher\Event;
use Symfony\Contracts\EventDispatcher\Event;

class OrderUpdateEvent extends Event
{
Expand Down
2 changes: 1 addition & 1 deletion src/CartBundle/Event/PaymentCreateEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Commercetools\Symfony\CartBundle\Event;

use Symfony\Component\EventDispatcher\Event;
use Symfony\Contracts\EventDispatcher\Event;

class PaymentCreateEvent extends Event
{
Expand Down
2 changes: 1 addition & 1 deletion src/CartBundle/Event/PaymentPostCreateEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
namespace Commercetools\Symfony\CartBundle\Event;

use Commercetools\Core\Model\Payment\Payment;
use Symfony\Component\EventDispatcher\Event;
use Symfony\Contracts\EventDispatcher\Event;

/**
* Class PaymentPostCreateEvent
Expand Down
2 changes: 1 addition & 1 deletion src/CartBundle/Event/PaymentPostUpdateEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

use Commercetools\Core\Model\Payment\Payment;
use Commercetools\Core\Request\AbstractAction;
use Symfony\Component\EventDispatcher\Event;
use Symfony\Contracts\EventDispatcher\Event;

class PaymentPostUpdateEvent extends Event
{
Expand Down
2 changes: 1 addition & 1 deletion src/CartBundle/Event/PaymentUpdateEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

use Commercetools\Core\Model\Payment\Payment;
use Commercetools\Core\Request\AbstractAction;
use Symfony\Component\EventDispatcher\Event;
use Symfony\Contracts\EventDispatcher\Event;

class PaymentUpdateEvent extends Event
{
Expand Down
18 changes: 7 additions & 11 deletions src/CartBundle/Manager/CartManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
use Commercetools\Symfony\CartBundle\Model\CartUpdateBuilder;
use Symfony\Component\Security\Core\User\UserInterface;

class CartManager
class CartManager implements CartManagerInterface
{
/**
* @var CartRepository
Expand Down Expand Up @@ -74,13 +74,11 @@ public function createCartForUser($locale, $currency, Location $location, LineIt
throw new InvalidArgumentException('At least one of `customerId` or `anonymousId` should be present');
}

$event = new CartCreateEvent();
$this->dispatcher->dispatch(CartCreateEvent::class, $event);
$this->dispatcher->dispatch(new CartCreateEvent());

$cart = $this->repository->createCart($locale, $currency, $location, $lineItemDraftCollection, $customerId, $anonymousId);

$eventPost = new CartPostCreateEvent($cart);
$this->dispatcher->dispatch(CartPostCreateEvent::class, $eventPost);
$this->dispatcher->dispatch(new CartPostCreateEvent($cart));

return $cart;
}
Expand All @@ -105,7 +103,7 @@ public function dispatch(Cart $cart, AbstractAction $action, $eventName = null)
$eventName = is_null($eventName) ? get_class($action) : $eventName;

$event = new CartUpdateEvent($cart, $action);
$event = $this->dispatcher->dispatch($eventName, $event);
$event = $this->dispatcher->dispatch($event, $eventName);

return $event->getActions();
}
Expand All @@ -132,7 +130,7 @@ public function apply(Cart $cart, array $actions)
public function dispatchPostUpdate(Cart $cart, array $actions)
{
$event = new CartPostUpdateEvent($cart, $actions);
$event = $this->dispatcher->dispatch(CartPostUpdateEvent::class, $event);
$event = $this->dispatcher->dispatch($event);

return $event->getActions();
}
Expand All @@ -143,11 +141,9 @@ public function dispatchPostUpdate(Cart $cart, array $actions)
public function dispatchPostGet(Cart $cart = null)
{
if (is_null($cart)) {
$event = new CartNotFoundEvent();
$this->dispatcher->dispatch(CartNotFoundEvent::class, $event);
$this->dispatcher->dispatch(new CartNotFoundEvent());
} else {
$event = new CartGetEvent($cart);
$this->dispatcher->dispatch(CartGetEvent::class, $event);
$this->dispatcher->dispatch(new CartGetEvent($cart));
}
}
}
49 changes: 49 additions & 0 deletions src/CartBundle/Manager/CartManagerInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php
/**
*
*/

namespace Commercetools\Symfony\CartBundle\Manager;

use Commercetools\Core\Model\Cart\Cart;
use Commercetools\Core\Request\AbstractAction;
use Commercetools\Symfony\CartBundle\Model\CartUpdateBuilder;

interface CartManagerInterface
{
/**
* @param Cart $cart
* @return CartUpdateBuilder
*/
public function update(Cart $cart);


/**
* @param Cart $cart
* @param AbstractAction $action
* @param string|null $eventName
* @return AbstractAction[]
*/
public function dispatch(Cart $cart, AbstractAction $action, $eventName = null);


/**
* @param Cart $cart
* @param array $actions
* @return Cart
*/
public function apply(Cart $cart, array $actions);

/**
* @param Cart $cart
* @param array $actions
* @return AbstractAction[]
*/
public function dispatchPostUpdate(Cart $cart, array $actions);


/**
* @param Cart|null $cart
*/
public function dispatchPostGet(Cart $cart = null);
}

0 comments on commit 71ca1b8

Please sign in to comment.