Skip to content

Commit

Permalink
Merge branch '1.2'
Browse files Browse the repository at this point in the history
* 1.2:
  Mention roadmap in README
  Unify catch block in ShopBasedCartContext
  handle dynamically templates with or without bundle
  fix phpspec for resource loader
  fix routing templates for sf4
  [HOTFIX] Missing configuration for channel in sonata
  the name of file was wrong
  • Loading branch information
pamil committed Jul 3, 2018
2 parents 45003b5 + 084ecfd commit e26947a
Show file tree
Hide file tree
Showing 6 changed files with 125 additions and 8 deletions.
6 changes: 6 additions & 0 deletions README.md
Expand Up @@ -25,6 +25,12 @@ Documentation

Documentation is available at [docs.sylius.com](http://docs.sylius.com).

Roadmap
-------

Our roadmap is available to browse, vote and comment as a [Github project](https://github.com/orgs/Sylius/projects/2).
You can also see all roadmap related issues by filtering [those labeled with "Roadmap"](https://github.com/Sylius/Sylius/labels/Roadmap).

Community
---------

Expand Down
@@ -1,7 +1,7 @@
How to change a redirect after the add to cart action?
======================================================

Currently **Sylius** by default is using route definition and **sylus-add-to-cart.js** script to handle redirect after successful add to cart action.
Currently **Sylius** by default is using route definition and **sylius-add-to-cart.js** script to handle redirect after successful add to cart action.

.. code-block:: yaml
Expand Down
Expand Up @@ -103,6 +103,7 @@ sonata_block:
address: ~
addresses: ~
cart: ~
channel: ~
customer: ~
form: ~
order: ~
Expand Down
6 changes: 5 additions & 1 deletion src/Sylius/Bundle/ResourceBundle/Routing/ResourceLoader.php
Expand Up @@ -185,7 +185,11 @@ private function createRoute(
$defaults['_sylius']['filterable'] = $configuration['filterable'];
}
if (isset($configuration['templates']) && in_array($actionName, ['show', 'index', 'create', 'update'], true)) {
$defaults['_sylius']['template'] = sprintf('%s:%s.html.twig', $configuration['templates'], $actionName);
$defaults['_sylius']['template'] = sprintf(
false === strpos($configuration['templates'], ':') ? '%s/%s.html.twig' : '%s:%s.html.twig',
$configuration['templates'],
$actionName
);
}
if (isset($configuration['redirect']) && in_array($actionName, ['create', 'update'], true)) {
$defaults['_sylius']['redirect'] = $this->getRouteName($metadata, $configuration, $configuration['redirect']);
Expand Down
112 changes: 111 additions & 1 deletion src/Sylius/Bundle/ResourceBundle/spec/Routing/ResourceLoaderSpec.php
Expand Up @@ -730,7 +730,7 @@ function it_generates_routing_for_a_section(
$this->load($configuration, 'sylius.resource')->shouldReturn($routeCollection);
}

function it_generates_routing_with_custom_templates_namespace(
function it_generates_routing_with_custom_templates_namespace_in_bundle(
RegistryInterface $resourceRegistry,
MetadataInterface $metadata,
RouteFactoryInterface $routeFactory,
Expand Down Expand Up @@ -840,6 +840,116 @@ function it_generates_routing_with_custom_templates_namespace(
$this->load($configuration, 'sylius.resource')->shouldReturn($routeCollection);
}

function it_generates_routing_with_custom_templates_namespace_out_of_bundle(
RegistryInterface $resourceRegistry,
MetadataInterface $metadata,
RouteFactoryInterface $routeFactory,
RouteCollection $routeCollection,
Route $showRoute,
Route $indexRoute,
Route $createRoute,
Route $updateRoute,
Route $bulkDeleteRoute,
Route $deleteRoute
): void {
$resourceRegistry->get('sylius.product')->willReturn($metadata);
$metadata->getApplicationName()->willReturn('sylius');
$metadata->getName()->willReturn('product');
$metadata->getPluralName()->willReturn('products');
$metadata->getServiceId('controller')->willReturn('sylius.controller.product');

$routeFactory->createRouteCollection()->willReturn($routeCollection);

$configuration =
<<<EOT
alias: sylius.product
templates: admin/product
EOT;

$showDefaults = [
'_controller' => 'sylius.controller.product:showAction',
'_sylius' => [
'template' => 'admin/product/show.html.twig',
'permission' => false,
],
];
$routeFactory
->createRoute('/products/{id}', $showDefaults, [], [], '', [], ['GET'])
->willReturn($showRoute)
;
$routeCollection->add('sylius_product_show', $showRoute)->shouldBeCalled();

$indexDefaults = [
'_controller' => 'sylius.controller.product:indexAction',
'_sylius' => [
'template' => 'admin/product/index.html.twig',
'permission' => false,
],
];
$routeFactory
->createRoute('/products/', $indexDefaults, [], [], '', [], ['GET'])
->willReturn($indexRoute)
;
$routeCollection->add('sylius_product_index', $indexRoute)->shouldBeCalled();

$createDefaults = [
'_controller' => 'sylius.controller.product:createAction',
'_sylius' => [
'template' => 'admin/product/create.html.twig',
'permission' => false,
],
];
$routeFactory
->createRoute('/products/new', $createDefaults, [], [], '', [], ['GET', 'POST'])
->willReturn($createRoute)
;
$routeCollection->add('sylius_product_create', $createRoute)->shouldBeCalled();

$updateDefaults = [
'_controller' => 'sylius.controller.product:updateAction',
'_sylius' => [
'template' => 'admin/product/update.html.twig',
'permission' => false,
],
];
$routeFactory
->createRoute('/products/{id}/edit', $updateDefaults, [], [], '', [], ['GET', 'PUT', 'PATCH'])
->willReturn($updateRoute)
;
$routeCollection->add('sylius_product_update', $updateRoute)->shouldBeCalled();

$bulkDeleteDefaults = [
'_controller' => 'sylius.controller.product:bulkDeleteAction',
'_sylius' => [
'permission' => false,
'paginate' => false,
'repository' => [
'method' => 'findById',
'arguments' => ['$ids'],
],
],
];
$routeFactory
->createRoute('/products/bulk-delete', $bulkDeleteDefaults, [], [], '', [], ['DELETE'])
->willReturn($bulkDeleteRoute)
;
$routeCollection->add('sylius_product_bulk_delete', $bulkDeleteRoute)->shouldBeCalled();

$deleteDefaults = [
'_controller' => 'sylius.controller.product:deleteAction',
'_sylius' => [
'permission' => false,
],
];
$routeFactory
->createRoute('/products/{id}', $deleteDefaults, [], [], '', [], ['DELETE'])
->willReturn($deleteRoute)
;
$routeCollection->add('sylius_product_delete', $deleteRoute)->shouldBeCalled();

$this->load($configuration, 'sylius.resource')->shouldReturn($routeCollection);
}

function it_excludes_specific_routes_if_configured(
RegistryInterface $resourceRegistry,
MetadataInterface $metadata,
Expand Down
Expand Up @@ -72,11 +72,7 @@ public function getCart(): BaseOrderInterface
$cart->setChannel($channel);
$cart->setCurrencyCode($channel->getBaseCurrency()->getCode());
$cart->setLocaleCode($this->shopperContext->getLocaleCode());
} catch (ChannelNotFoundException $exception) {
throw new CartNotFoundException('Sylius was not able to prepare the cart.', $exception);
} catch (CurrencyNotFoundException $exception) {
throw new CartNotFoundException('Sylius was not able to prepare the cart.', $exception);
} catch (LocaleNotFoundException $exception) {
} catch (ChannelNotFoundException | CurrencyNotFoundException | LocaleNotFoundException $exception) {
throw new CartNotFoundException('Sylius was not able to prepare the cart.', $exception);
}

Expand Down

0 comments on commit e26947a

Please sign in to comment.