Best practices for using Git with Magento?

前端 未结 5 1774
攒了一身酷
攒了一身酷 2020-12-28 08:33

I\'m working at figuring out how to best work within my own repo for custom code while integrating with a vendor\'s library (in this case Magento). In my case, I will not n

5条回答
  •  眼角桃花
    2020-12-28 08:49

    Your question is more about git's submodule vs. subtree in general. I can't think of any Magento specifics that will influence the comparison. Most probably you are aware of subtree merging strategies which I will recommend but I am not sure why do you need to merge at a first place.

    Best practice of merging is to avoid it and Magento architecture is flexible enough to allow it. Follow a simple rule set:

    1. Avoid patching the vendor code.
    2. If you can't. Before doing a patch, consider packing your changes into a custom Magento module and placing it into app/code/local.

    If your modification concerns PHP code:

    1. You can benefit from OOP and minimize changes to a certain methods only. Extend respective classes.
    2. Overwrite respective class using the Magento configuration mechanism in config.xml.
    3. If previous is impossible to achieve - place your changes (patched classes) into app/code/local, i.e. higher in include_path order so that your code will be efficiently used instead of the vendor's code.

    If your modification concerns phtml templating -> use Magento layout mechanism to replace vendor's phtml with yours. A proper design customization will require heavy modification activities and layout work anyway.

    If your modification concerns JS -> again, use layouts to link the code placed in js or skin folders.

提交回复
热议问题