The right developer. approach for overriding twig patterns

I recently decided to take a look at Sylius, because I like the idea of ​​a symfony2 developer-friendly project.

I tried looking through various documentation articles, but I didn’t seem to be able to find the answer to a very fundamental question that I have: which is the recommended way to start development on a new -store webpage that will include (at least) the option implement your own HTML templates and still be able to easily upgrade Sylius to future versions?

The best approach I could come up with is to create a new package (in my case, with a name WebBundle), which is based on the standard one SyliusWebBundle. Here is the problem. To get the minimum permission to allow Sylius to use the templates in my kit, and not by default, I had to go through many hoops. Here are a few things I have done so far:

  • Copy the contents of the source directory Controllerfrom SyliusWebBundle. Modified return values ​​use WebBundle, and not SyliusWebBundlepart of the string in the argument $this->render(), as well as class namespaces.
  • I copied the YAML files in the directory Resources/config/routingfrom SyliusWebBundleto my package. Changed links SyliusWebBundlein YAML files, similar to the above.
  • New sections have been added to app/config/config.yml, in particular this part (intended to redefine content 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 links to the default controllers in the YAML files in the directory Resources/config/routing/frontend, but before I start next , I need to know if this is the right approach or if I'm going the wrong way.

My goal is to make the store as simple as possible for updating with new versions of Sylius, so I would like to avoid modifying the main library files and, instead, selectively redefine functionality using my own packages, if necessary.

However, at present, Silius does not seem “oriented” to this approach, if I have not missed anything.

, (CoreBundle, WebBundle, YAML), . , - .

+4
1

( symfony ):

app/Resources/SyliusWebBundle/views/Frontend/Checkout/Step/
   security.html.twig
   addressing.html.twig
   shipping.html.twig
   payment.html.twig
   finalize.html.twig
+1

Source: https://habr.com/ru/post/1570259/


All Articles