0

I'm implementing my own design to My Account dashboard. Unfortunately, I'm not able to open the Address Book and Address Information. When am clicking those links, I'm getting the below attached error.

enter image description here

<?php
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */

// @codingStandardsIgnoreFile

/** @var \Magento\Customer\Block\Widget\Name $block */

/*
<?= $block->getLayout()->createBlock('Magento\Customer\Block\Widget\Name')
   ->setObject($block->getAddress())
   ->toHtml() ?>

For checkout/onepage/shipping.phtml:

<?= $block->getLayout()->createBlock('Magento\Customer\Block\Widget\Name')
   ->setObject($block->getAddress())
   ->setFieldIdFormat('shipping:%s')
   ->setFieldNameFormat('shipping[%s]')
   ->toHtml() ?>
*/

$prefix = $block->showPrefix();
$middle = $block->showMiddlename();
$suffix = $block->showSuffix();
?>
<?php if (($prefix || $middle || $suffix) && !$block->getNoWrap()): ?>
<div class="field required fullname <?= $block->escapeHtmlAttr($block->getContainerClassName()) ?>">
    <label for="<?= $block->escapeHtmlAttr($block->getFieldId('firstname')) ?>" class="label"><span><?= $block->escapeHtml(__('Name')) ?></span></label>
    <div class="control">
        <fieldset class="fieldset fieldset-fullname">
        <div class="fields">
<?php endif; ?>

    <?php if ($prefix): ?>
        <div class="field field-name-prefix<?php if ($block->isPrefixRequired()) echo ' required' ?>">
            <label class="label" for="<?= $block->escapeHtmlAttr($block->getFieldId('prefix')) ?>"><span><?= $block->escapeHtml($block->getStoreLabel('prefix')) ?></span></label>
            <div class="control">
                <?php if ($block->getPrefixOptions() === false): ?>
                    <input type="text" id="<?= $block->escapeHtmlAttr($block->getFieldId('prefix')) ?>"
                           name="<?= $block->escapeHtmlAttr($block->getFieldName('prefix')) ?>"
                           value="<?= $block->escapeHtmlAttr($block->getObject()->getPrefix()) ?>"
                           title="<?= $block->escapeHtmlAttr($block->getStoreLabel('prefix')) ?>"
                           class="input-text <?= $block->escapeHtmlAttr($block->getAttributeValidationClass('prefix')) ?>" <?php if ($block->isPrefixRequired()) echo ' data-validate="{required:true}"' ?>>
                <?php else: ?>
                    <select id="<?= $block->escapeHtmlAttr($block->getFieldId('prefix')) ?>"
                            name="<?= $block->escapeHtmlAttr($block->getFieldName('prefix')) ?>"
                            title="<?= $block->escapeHtmlAttr($block->getStoreLabel('prefix')) ?>"
                            class="<?= $block->escapeHtmlAttr($block->getAttributeValidationClass('prefix')) ?>" <?php if ($block->isPrefixRequired()) echo ' data-validate="{required:true}"' ?> >
                        <?php foreach ($block->getPrefixOptions() as $_option): ?>
                            <option value="<?= $block->escapeHtmlAttr($_option) ?>"<?php if ($block->getObject()->getPrefix() == $_option): ?> selected="selected"<?php endif; ?>>
                                <?= $block->escapeHtml(__($_option)) ?>
                            </option>
                        <?php endforeach; ?>
                    </select>
                <?php endif; ?>
            </div>
        </div>
    <?php endif; ?>
      <div class="address-row-wrap">
        <div class="col-6">
        <div class="field field-name-firstname single-row required">
            <label class="label" for="<?= $block->escapeHtmlAttr($block->getFieldId('firstname')) ?>"><span><?= $block->escapeHtml($block->getStoreLabel('firstname')) ?></span></label>
            <div class="control">
                <input type="text" id="<?= $block->escapeHtmlAttr($block->getFieldId('firstname')) ?>"
                       name="<?= $block->escapeHtmlAttr($block->getFieldName('firstname')) ?>"
                       value="<?= $block->escapeHtmlAttr($block->getObject()->getFirstname()) ?>"
                       title="<?= $block->escapeHtmlAttr($block->getStoreLabel('firstname')) ?>"
                       class="input-text my-account-input <?= $block->escapeHtmlAttr($block->getAttributeValidationClass('firstname')) ?>" <?php if ($block->getAttributeValidationClass('firstname') == 'required-entry') echo ' data-validate="{required:true}"' ?>>
            </div>
        </div>
      </div>
    <?php if ($middle): ?>
        <?php $isMiddlenameRequired = $block->isMiddlenameRequired(); ?>
        <div class="field field-name-middlename<?= $isMiddlenameRequired ? ' required' : '' ?>">
            <label class="label" for="<?= $block->escapeHtmlAttr($block->getFieldId('middlename')) ?>"><span><?= $block->escapeHtml($block->getStoreLabel('middlename')) ?></span></label>
            <div class="control">
                <input type="text" id="<?= $block->escapeHtmlAttr($block->getFieldId('middlename')) ?>"
                       name="<?= $block->escapeHtmlAttr($block->getFieldName('middlename')) ?>"
                       value="<?= $block->escapeHtmlAttr($block->getObject()->getMiddlename()) ?>"
                       title="<?= $block->escapeHtmlAttr($block->getStoreLabel('middlename')) ?>"
                       class="input-text my-account-input <?= $block->escapeHtmlAttr($block->getAttributeValidationClass('middlename')) ?>" <?= $isMiddlenameRequired ? ' data-validate="{required:true}"' : '' ?>>
            </div>
        </div>
    <?php endif; ?>
        <div class="col-6">
          <div class="field field-name-lastname single-row required">
              <label class="label" for="<?= $block->escapeHtmlAttr($block->getFieldId('lastname')) ?>"><span><?= $block->escapeHtml($block->getStoreLabel('lastname')) ?></span></label>
              <div class="control">
                  <input type="text" id="<?= $block->escapeHtmlAttr($block->getFieldId('lastname')) ?>"
                         name="<?= $block->escapeHtmlAttr($block->getFieldName('lastname')) ?>"
                         value="<?= $block->escapeHtmlAttr($block->getObject()->getLastname()) ?>"
                         title="<?= $block->escapeHtmlAttr($block->getStoreLabel('lastname')) ?>"
                         class="input-text my-account-input <?= $block->escapeHtmlAttr($block->getAttributeValidationClass('lastname')) ?>" <?php if ($block->getAttributeValidationClass('lastname') == 'required-entry') echo ' data-validate="{required:true}"' ?>>
              </div>
          </div>
        </div>
      </div>
    <?php if ($suffix): ?>
        <div class="field field-name-suffix<?php if ($block->isSuffixRequired()) echo ' required' ?>">
            <label class="label" for="<?= $block->escapeHtmlAttr($block->getFieldId('suffix')) ?>"><span><?= $block->escapeHtml($block->getStoreLabel('suffix')) ?></span></label>
            <div class="control">
                <?php if ($block->getSuffixOptions() === false): ?>
                    <input type="text" id="<?= $block->escapeHtmlAttr($block->getFieldId('suffix')) ?>"
                           name="<?= $block->escapeHtmlAttr($block->getFieldName('suffix')) ?>"
                           value="<?= $block->escapeHtmlAttr($block->getObject()->getSuffix()) ?>"
                           title="<?= $block->escapeHtmlAttr($block->getStoreLabel('suffix')) ?>"
                           class="input-text <?= $block->escapeHtmlAttr($block->getAttributeValidationClass('suffix')) ?>" <?php if ($block->isSuffixRequired()) echo ' data-validate="{required:true}"' ?>>
                <?php else: ?>
                    <select id="<?= $block->escapeHtmlAttr($block->getFieldId('suffix')) ?>"
                            name="<?= $block->escapeHtmlAttr($block->getFieldName('suffix')) ?>"
                            title="<?= $block->escapeHtmlAttr($block->getStoreLabel('suffix')) ?>"
                            class="<?= $block->escapeHtmlAttr($block->getAttributeValidationClass('suffix')) ?>" <?php if ($block->isSuffixRequired()) echo ' data-validate="{required:true}"' ?>>
                        <?php foreach ($block->getSuffixOptions() as $_option): ?>
                            <option value="<?= $block->escapeHtmlAttr($_option) ?>"<?php if ($block->getObject()->getSuffix() == $_option): ?> selected="selected"<?php endif; ?>>
                                <?= $block->escapeHtml(__($_option)) ?>
                            </option>
                        <?php endforeach; ?>
                    </select>
                <?php endif; ?>
            </div>
        </div>
    <?php endif; ?>

    <?php if (($prefix || $middle || $suffix) && !$block->getNoWrap()): ?>
            </div>
        </fieldset>
    </div>
</div>
<?php endif; ?>

Any help will be appreciated!

9
  • Can you please update some more infor here ? Oct 23, 2019 at 12:27
  • I have directly added my custom classes into the core files but am not sure where am I wrong.
    – MagentoDev
    Oct 23, 2019 at 12:29
  • In which file you've added classes ? Oct 23, 2019 at 12:30
  • Is that XML file? Oct 23, 2019 at 12:30
  • No, its phtml file
    – MagentoDev
    Oct 23, 2019 at 12:30

1 Answer 1

1

You can replace your .phtml file with this content..

<?php
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */

// @codingStandardsIgnoreFile

/** @var \Magento\Customer\Block\Widget\Name $block */

/*
<?= $block->getLayout()->createBlock('Magento\Customer\Block\Widget\Name')
   ->setObject($block->getAddress())
   ->toHtml() ?>

For checkout/onepage/shipping.phtml:

<?= $block->getLayout()->createBlock('Magento\Customer\Block\Widget\Name')
   ->setObject($block->getAddress())
   ->setFieldIdFormat('shipping:%s')
   ->setFieldNameFormat('shipping[%s]')
   ->toHtml() ?>
*/

$prefix = $block->showPrefix();
$middle = $block->showMiddlename();
$suffix = $block->showSuffix();
?>
<?php if (($prefix || $middle || $suffix) && !$block->getNoWrap()): ?>
<div class="field required fullname <?= $block->escapeHtmlAttr($block->getContainerClassName()) ?>">
    <label for="<?= $block->escapeHtmlAttr($block->getFieldId('firstname')) ?>" class="label"><span><?= $block->escapeHtml(__('Name')) ?></span></label>
    <div class="control">
        <fieldset class="fieldset fieldset-fullname">
        <div class="fields">
<?php endif; ?>

    <?php if ($prefix): ?>
        <div class="field field-name-prefix<?php if ($block->isPrefixRequired()): echo ' required'; endif; ?>">
            <label class="label" for="<?= $block->escapeHtmlAttr($block->getFieldId('prefix')) ?>"><span><?= $block->escapeHtml($block->getStoreLabel('prefix')) ?></span></label>
            <div class="control">
                <?php if ($block->getPrefixOptions() === false): ?>
                    <input type="text" id="<?= $block->escapeHtmlAttr($block->getFieldId('prefix')) ?>"
                           name="<?= $block->escapeHtmlAttr($block->getFieldName('prefix')) ?>"
                           value="<?= $block->escapeHtmlAttr($block->getObject()->getPrefix()) ?>"
                           title="<?= $block->escapeHtmlAttr($block->getStoreLabel('prefix')) ?>"
                           class="input-text <?= $block->escapeHtmlAttr($block->getAttributeValidationClass('prefix')) ?>" <?php if($block->isPrefixRequired()): echo ' data-validate="{required:true}"'; endif; ?>>
                <?php else: ?>
                    <select id="<?= $block->escapeHtmlAttr($block->getFieldId('prefix')) ?>"
                            name="<?= $block->escapeHtmlAttr($block->getFieldName('prefix')) ?>"
                            title="<?= $block->escapeHtmlAttr($block->getStoreLabel('prefix')) ?>"
                            class="<?= $block->escapeHtmlAttr($block->getAttributeValidationClass('prefix')) ?>" <?php if ($block->isPrefixRequired()): echo ' data-validate="{required:true}"'; endif; ?> >
                        <?php foreach ($block->getPrefixOptions() as $_option): ?>
                            <option value="<?= $block->escapeHtmlAttr($_option) ?>"<?php if ($block->getObject()->getPrefix() == $_option): ?> selected="selected"<?php endif; ?>>
                                <?= $block->escapeHtml(__($_option)) ?>
                            </option>
                        <?php endforeach; ?>
                    </select>
                <?php endif; ?>
            </div>
        </div>
    <?php endif; ?>
      <div class="address-row-wrap">
        <div class="col-6">
        <div class="field field-name-firstname single-row required">
            <label class="label" for="<?= $block->escapeHtmlAttr($block->getFieldId('firstname')) ?>"><span><?= $block->escapeHtml($block->getStoreLabel('firstname')) ?></span></label>
            <div class="control">
                <input type="text" id="<?= $block->escapeHtmlAttr($block->getFieldId('firstname')) ?>"
                       name="<?= $block->escapeHtmlAttr($block->getFieldName('firstname')) ?>"
                       value="<?= $block->escapeHtmlAttr($block->getObject()->getFirstname()) ?>"
                       title="<?= $block->escapeHtmlAttr($block->getStoreLabel('firstname')) ?>"
                       class="input-text my-account-input <?= $block->escapeHtmlAttr($block->getAttributeValidationClass('firstname')) ?>" <?php if ($block->getAttributeValidationClass('firstname') == 'required-entry'): echo ' data-validate="{required:true}"'; endif; ?>>
            </div>
        </div>
      </div>
    <?php if ($middle): ?>
        <?php $isMiddlenameRequired = $block->isMiddlenameRequired(); ?>
        <div class="field field-name-middlename<?= $isMiddlenameRequired ? ' required' : '' ?>">
            <label class="label" for="<?= $block->escapeHtmlAttr($block->getFieldId('middlename')) ?>"><span><?= $block->escapeHtml($block->getStoreLabel('middlename')) ?></span></label>
            <div class="control">
                <input type="text" id="<?= $block->escapeHtmlAttr($block->getFieldId('middlename')) ?>"
                       name="<?= $block->escapeHtmlAttr($block->getFieldName('middlename')) ?>"
                       value="<?= $block->escapeHtmlAttr($block->getObject()->getMiddlename()) ?>"
                       title="<?= $block->escapeHtmlAttr($block->getStoreLabel('middlename')) ?>"
                       class="input-text my-account-input <?= $block->escapeHtmlAttr($block->getAttributeValidationClass('middlename')) ?>" <?= $isMiddlenameRequired ? ' data-validate="{required:true}"' : '' ?>>
            </div>
        </div>
    <?php endif; ?>
        <div class="col-6">
          <div class="field field-name-lastname single-row required">
              <label class="label" for="<?= $block->escapeHtmlAttr($block->getFieldId('lastname')) ?>"><span><?= $block->escapeHtml($block->getStoreLabel('lastname')) ?></span></label>
              <div class="control">
                  <input type="text" id="<?= $block->escapeHtmlAttr($block->getFieldId('lastname')) ?>"
                         name="<?= $block->escapeHtmlAttr($block->getFieldName('lastname')) ?>"
                         value="<?= $block->escapeHtmlAttr($block->getObject()->getLastname()) ?>"
                         title="<?= $block->escapeHtmlAttr($block->getStoreLabel('lastname')) ?>"
                         class="input-text my-account-input <?= $block->escapeHtmlAttr($block->getAttributeValidationClass('lastname')) ?>" <?php if ($block->getAttributeValidationClass('lastname') == 'required-entry'): echo ' data-validate="{required:true}"'; endif; ?>>
              </div>
          </div>
        </div>
      </div>
    <?php if ($suffix): ?>
        <div class="field field-name-suffix<?php if ($block->isSuffixRequired()): echo ' required'; endif; ?>">
            <label class="label" for="<?= $block->escapeHtmlAttr($block->getFieldId('suffix')) ?>"><span><?= $block->escapeHtml($block->getStoreLabel('suffix')) ?></span></label>
            <div class="control">
                <?php if ($block->getSuffixOptions() === false): ?>
                    <input type="text" id="<?= $block->escapeHtmlAttr($block->getFieldId('suffix')) ?>"
                           name="<?= $block->escapeHtmlAttr($block->getFieldName('suffix')) ?>"
                           value="<?= $block->escapeHtmlAttr($block->getObject()->getSuffix()) ?>"
                           title="<?= $block->escapeHtmlAttr($block->getStoreLabel('suffix')) ?>"
                           class="input-text <?= $block->escapeHtmlAttr($block->getAttributeValidationClass('suffix')) ?>" <?php if ($block->isSuffixRequired()) echo ' data-validate="{required:true}"' ?>>
                <?php else: ?>
                    <select id="<?= $block->escapeHtmlAttr($block->getFieldId('suffix')) ?>"
                            name="<?= $block->escapeHtmlAttr($block->getFieldName('suffix')) ?>"
                            title="<?= $block->escapeHtmlAttr($block->getStoreLabel('suffix')) ?>"
                            class="<?= $block->escapeHtmlAttr($block->getAttributeValidationClass('suffix')) ?>" <?php if ($block->isSuffixRequired()): echo ' data-validate="{required:true}"'; endif; ?>>
                        <?php foreach ($block->getSuffixOptions() as $_option): ?>
                            <option value="<?= $block->escapeHtmlAttr($_option) ?>"<?php if ($block->getObject()->getSuffix() == $_option): ?> selected="selected"<?php endif; ?>>
                                <?= $block->escapeHtml(__($_option)) ?>
                            </option>
                        <?php endforeach; ?>
                    </select>
                <?php endif; ?>
            </div>
        </div>
    <?php endif; ?>

    <?php if (($prefix || $middle || $suffix) && !$block->getNoWrap()): ?>
            </div>
        </fieldset>
    </div>
</div>
<?php endif; ?>

In your if conditions endif missing everywhere.

You can use if condition like this if you want to add class in html

<div class="test <?php if($somecondition): echo 'required'; endif; ?>">Test</div>

Hope this will help you!

3
  • Thanks. I have tried but its not working. Is it possible to remove and regenerate all the folder in vendor directory because i'm not sure where I have updated.
    – MagentoDev
    Oct 23, 2019 at 13:08
  • What error now you're getting there ? Can you please let me know ? Oct 23, 2019 at 13:53
  • Seen that I have closed the div after endif that's caused the issue.
    – MagentoDev
    Oct 23, 2019 at 14:17

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.