1

I need to add a conditional by checking the information of an custom attribute, for example if it is 'S' to show the address, if it is 'B' not to show the address

I need to modify the next template:

\vendor\magento\module-checkout\view\frontend\web\template\shipping-address\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().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 if: element[attribute].value != null -->
            <!-- ko text: element[attribute].value --><!-- /ko --><br/>
        <!-- /ko -->
        <!-- ko if: element[attribute].value == null -->
            <!-- ko text: element[attribute] --><!-- /ko --><br/>
        <!-- /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>

Where does Magento get the address() object?

1

Hope Doing well.

please find this model file and you have address function here! which is used to get address.

Magento\Quote\Model\Quote

this are the functions. please do some debugging by your self.

/**
 * Retrieve quote billing address
 *
 * @return Address
 */
public function getBillingAddress()
{
    return $this->_getAddressByType(Address::TYPE_BILLING);
}

/**
 * Retrieve quote shipping address
 *
 * @return Address
 */
public function getShippingAddress()
{
    return $this->_getAddressByType(Address::TYPE_SHIPPING);
}

protected function _getAddressByType($type)
{
    foreach ($this->getAddressesCollection() as $address) {
        if ($address->getAddressType() == $type && !$address->isDeleted()) {
            return $address;
        }
    }

    $address = $this->_quoteAddressFactory->create()->setAddressType($type);
    $this->addAddress($address);
    return $address;
}

magento get shipping address data from here.

magento_directory/vendor/magento/module-checkout/view/frontend/web/js/view/shipping-information/list.js

line no. 35

 quote.shippingAddress.subscribe(function (address) {
                self.createRendererComponent(address);
            });

please find this things and do some debugging by your self you will definitely get your result.

Thanks

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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