3

I want to include Company field on the shipping-information-content block on the Checkout if a customer fills the field on the previous page.

The relevant block on checkout_index_index.xml is

<item name="shipping-information" xsi:type="array">
    <item name="component" xsi:type="string">Magento_Checkout/js/view/shipping-information</item>
    <item name="config" xsi:type="array">
        <item name="deps" xsi:type="string">checkout.steps.shipping-step.shippingAddress</item>
    </item>
    <item name="displayArea" xsi:type="string">shipping-information</item>
    <item name="children" xsi:type="array">
        <item name="ship-to" xsi:type="array">
            <item name="component" xsi:type="string">Magento_Checkout/js/view/shipping-information/list</item>
            <item name="displayArea" xsi:type="string">ship-to</item>
        </item>
    </item>
</item>

I added a picture that specifies which block I mean:

Screenshot of missing shipping information

Can anyone offer their advice?

6
  • can't see the image , upload again Commented Oct 11, 2017 at 9:28
  • Company field already exists in Magento2 on checkout page.
    – St3phan
    Commented Oct 11, 2017 at 9:33
  • I added a direct link to imgur for the picture @Manoj Commented Oct 11, 2017 at 9:36
  • I know that it exists, I want it to show on the Ship To: section on the last page of our checkout! Commented Oct 11, 2017 at 9:37
  • okay got it , let me see if I can help you on this Commented Oct 11, 2017 at 9:42

2 Answers 2

3

For Adding company field on the Ship To section and shipping address follow below steps :

To add Company/New field in shipping address section, override:

vendor/magento/module-checkout/view/frontend/web/template/shipping-address/address-renderer/default.html

To add Company/New field field in sidebar Ship To section override:

vendor/magento/module-checkout/view/frontend/web/template/shipping-information/address-renderer/default.html

To override create requirejs-config.js at

app/code/Vendor/Module/view/frontend/requirejs-config.js

var config = {
    map: {
        '*': {
            'Magento_Checkout/template/shipping-address/address-renderer/default.html':
                'Vendor_Module/template/shipping-address/address-renderer/default.html',

            'Magento_Checkout/template/shipping-information/address-renderer/default.html':
                'Vendor_Module/template/shipping-information/address-renderer/default.html'
        }
    }
};

After that add this line of code in overridden file where you want to display company field.

<!-- ko text: address().company --><!-- /ko -->

For example

app/code/Vendor/Module/view/frontend/web/template/shipping-information/address-renderer/default.html

<div class="shipping-address-item" data-bind="css: isSelected() ? 'selected-item' : 'not-selected-item'">
    <!-- ko text: address().prefix --><!-- /ko --> <!-- ko text: address().firstname --><!-- /ko -->
    <!-- ko text: address().lastname --><!-- /ko --> <!-- ko text: address().suffix --><!-- /ko --><br/>
    <!-- ko text: address().street --><!-- /ko --><br/>
    <!-- ko text: address().company -->
    <!-- ko text: address().city --><!-- /ko -->, <!-- ko text: address().region --><!-- /ko --> <!-- ko text: address().postcode --><!-- /ko --><br/>
    <!-- ko text: getCountryName(address().countryId) --><!-- /ko --><br/>
    <!-- ko text: address().telephone --><!-- /ko --><br/>
    <!-- ko foreach: { data: address().customAttributes, as: 'element' } -->
        <!-- ko foreach: { data: Object.keys(element), as: 'attribute' } -->
            <!-- ko text: element[attribute].value --><!-- /ko -->
         <!-- /ko -->
    <!-- /ko -->
    <!-- ko if: (address().isEditable()) -->
    <button type="button"
            class="action edit-address-link"
            data-bind="click: editAddress, visible: address().isEditable()">
        <span data-bind="i18n: 'Edit'"></span>
    </button>
    <!-- /ko -->
    <button type="button" data-bind="click: selectAddress" class="action action-select-shipping-item">
        <span data-bind="i18n: 'Ship Here'"></span>
    </button>
</div>

Then run necessary commands , hope this should help you out.

9
  • I can't seem to make it work. The requirejs-config.js file breaks the part at the bottom right completely, it shows an error message specifying that the call to the correct files does not exist. Further I only have company showing at the bottom right, after which it shows completely nothing. However I overwrote the files not under app/code/... but under app/design/... Commented Oct 11, 2017 at 12:49
  • You responded late , left from work-station, will help you tomorrow to solve this Commented Oct 11, 2017 at 12:52
  • have you copied files from vendor to app/code ? Commented Oct 11, 2017 at 12:58
  • But why to app/code? It is a layout change right, so should it not be copied to app/design? In app/code I only have plugins Commented Oct 11, 2017 at 13:08
  • not a layout , you are adding that in Ship TO Section, if already present there than you can move via XMl , so its better to extend as suggested and try, that will solve your problem Commented Oct 12, 2017 at 3:44
0

Overwrite vendor/magento/module-checkout/view/frontend/web/template/shipping-information/address-renderer/default.html

Add following code after country for displaying company (Right sidebar renderer)


<!-- ko text: address().company --><!-- /ko -->

For under payment method add following code after country:

Overwrite [vendor/magento/module-checkout/view/frontend/web/template/billing-address/details.html]


<!-- ko text: currentBillingAddress().company --><!-- /ko -->
1
  • For some reasons this is not working for me: I edited the files in my theme and did the redeploy but the changes is not taking effect. I tried to change the magento core files and it worked, but if I change it on my custom theme it is not working. Any idea?
    – Korbin
    Commented Nov 28, 2018 at 10:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.