4

I recently decided to take a look at Sylius, since I love the idea of a developer-friendly Symfony2 project.

I tried to look through the various documentation articles, but I didn't seem to be able to find the answer for a very fundamental question that I have: what is the recommended way to start development on a new web-store, which will include (at the very least), the ability to implement one's own HTML template designs, and still be able to easily upgrade Sylius to future versions?

The best approach that I was able to come up with is to create a new bundle (in my case, named WebBundle) which is based on the default SyliusWebBundle. Here's the problem. In order to get the bare minimum of allowing Sylius to use the templates in my bundle, rather than the default one, I had to go through many hoops. Here are several things I have done so far:

  • Copied the contents of the original Controller directory from SyliusWebBundle. Changed return values to use WebBundle rather than SyliusWebBundle a part of the string in the argument to $this->render(), as well as the class namespaces.
  • Copied the YAML files in the Resources/config/routing directory from SyliusWebBundle to my bundle. Changed SyliusWebBundle references in the YAML files, similar to the above.
  • Added new sections to app/config/config.yml, specifically this part (intended to override the contents of addCheckoutSection() in Sylius\Bundle\CoreBundle\DependencyInjection\Configuration):

     sylius_core:
        # ...
        checkout:
            steps:
                security:
                    template: 'WebBundle:Frontend/Checkout/Step:security.html.twig'
                addressing:
                    template: 'WebBundle:Frontend/Checkout/Step:addressing.html.twig'
                shipping:
                    template: 'WebBundle:Frontend/Checkout/Step:shipping.html.twig'
                payment:
                    template: 'WebBundle:Frontend/Checkout/Step:payment.html.twig'
                finalize:
                    template: 'WebBundle:Frontend/Checkout/Step:finalize.html.twig'
    

I have a lot more work in changing all the default controller references in the YAML files in Resources/config/routing/frontend directory, but before I proceed onward, I need to know if this is the correct approach, or if I'm going down the wrong path.

My goal is to make the store as easy to upgrade as possible with new releases of Sylius, so I'd like to avoid modifying core library files, and instead selectively overriding functionality using my own bundles, as needed.

However, Sylius currently doesn't yet appear to be "geared" towards this approach, unless I missed something.

The fact that I had to override functionality from more than one bundle (CoreBundle as well as WebBundle, per the above YAML section), made me pause with my current approach. I hope someone might be able to steer me in the right direction.

Redoubt
  • 41
  • 1
  • You should only extend any of Sylius bundles in very specific cases, such as adding a compiler pass. – gvf Jun 23 '15 at 16:23

1 Answers1

1

you can override all templates in the app folder (this is part of symfony and works with all bundles):

app/Resources/SyliusWebBundle/views/Frontend/Checkout/Step/
   security.html.twig
   addressing.html.twig
   shipping.html.twig
   payment.html.twig
   finalize.html.twig
wodka
  • 1,067
  • 8
  • 17