cancel
Showing results for 
Search instead for 
Did you mean: 

Why to keep things simple if they can be kept complicated?

Why to keep things simple if they can be kept complicated?

I am extremely surprised why Magento developers implemented a JavaScript templating system to make things more complicated instead of keeping them simple with the already developed templating system based on phtml files?

 

I have spent several days trying to remove one field in the shipping form (for instance, it is the company field) but of course with no success until now. That is a very trivial task, why did Magento make this so complicated?

 

Besides that, no good documents are found explaining about ths templating system in detail. For example, this is the form:

 

 

    <div id="shipping-new-address-form" class="fieldset address">
        <!-- ko foreach: getRegion('additional-fieldsets') -->
        <!-- ko template: getTemplate() --><!-- /ko -->
        <!--/ko-->
        <!-- ko if: (isCustomerLoggedIn) -->
        <div class="field choice" data-bind="visible: !isFormInline">
            <input type="checkbox" class="checkbox" id="shipping-save-in-address-book" data-bind="checked: saveInAddressBook" />
            <label class="label" for="shipping-save-in-address-book">
                <span data-bind="i18n: 'Save in address book'"></span>
            </label>
        </div>
        <!-- /ko -->
    </div>

I found that getRegion('additional-fieldsets')  lists all children defined:

 

 

<item name="displayArea" xsi:type="string">additional-fieldsets</item>
<item name="children" xsi:type="array">........</item>

I have discovered that if I add <item name="visible" xsi:type="boolean">false</item> as a child of company field, that field is not displayed, but, after that field is a field called "fax" that is not actually displayed, however, there is no visible = false item. Why? 

 

Furthermore, I need to transform the city input field into a dropdown field, how to do that?

 

In order to just modify one field, is it necessary to copy whole jsLayout or just the node I want to change?

 

Is there some reference about this in some part of the world?

 

Best regards

Jaime

1 REPLY 1

Re: Why to keep things simple if they can be kept complicated?

Magento always had significant amount of JS code. But that was not structure and all parts of system were implemented differently. In Magento 2 we started the process of unification of JS application.

 

Anther reason for improved JS framework is that we have reviewed our approach to page rendering and page caching:

All user-agnostic content (catalog, CMS) is rendered on server and cached in public cache (edge servers like Varnish) and all user-specific content (Cart, wishlist, checkout data) should be cached and rendered in browser. M1 approach of rendering all content on server and just loading user-specific block contents with AJAX led to limited UIs, inefficient cache invalidations, more AJAX calls, and confusing couplings between JS code & PHP code.

 

So we needed more robust JS application framework to render more content in browser. UI component approach was used. 

 

Hope this answers your question about motivation for more complex JS framework.

 

As for checkout documentation, it's available here: http://devdocs.magento.com/guides/v2.0/howdoi/checkout/checkout_overview.html