init
This commit is contained in:
@@ -0,0 +1,163 @@
|
||||
<?php
|
||||
/**
|
||||
* eSUN customer address book.
|
||||
*
|
||||
* @var \Magento\Customer\Block\Address\Book $block
|
||||
* @var \Magento\Framework\Escaper $escaper
|
||||
* @var \Esun\Customer\ViewModel\AddressBook $viewModel
|
||||
*/
|
||||
$viewModel = $block->getData('view_model');
|
||||
$defaultShippingId = (int) $block->getDefaultShipping();
|
||||
$defaultBillingId = (int) $block->getDefaultBilling();
|
||||
$defaultShipping = $defaultShippingId ? $block->getAddressById($defaultShippingId) : null;
|
||||
$defaultBilling = $defaultBillingId ? $block->getAddressById($defaultBillingId) : null;
|
||||
$additionalAddresses = $block->getAdditionalAddresses();
|
||||
$shippingAddresses = [];
|
||||
|
||||
if ($defaultShipping instanceof \Magento\Customer\Api\Data\AddressInterface) {
|
||||
$shippingAddresses[] = $defaultShipping;
|
||||
}
|
||||
|
||||
if (is_array($additionalAddresses)) {
|
||||
foreach ($additionalAddresses as $address) {
|
||||
if ($address instanceof \Magento\Customer\Api\Data\AddressInterface) {
|
||||
$shippingAddresses[] = $address;
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
<section class="esun-address-book" data-mage-init='{"Esun_Customer/js/address-book":{}}'>
|
||||
<h1 class="esun-address-book__title"><?= $escaper->escapeHtml(__('Manage Address Book')) ?></h1>
|
||||
|
||||
<nav class="esun-address-book__tabs" aria-label="<?= $escaper->escapeHtmlAttr(__('Address type')) ?>">
|
||||
<button class="esun-address-book__tab is-active"
|
||||
type="button"
|
||||
data-address-tab="shipping"
|
||||
aria-selected="true">
|
||||
<?= $escaper->escapeHtml(__('Shipping Address')) ?>
|
||||
</button>
|
||||
<button class="esun-address-book__tab"
|
||||
type="button"
|
||||
data-address-tab="billing"
|
||||
aria-selected="false">
|
||||
<?= $escaper->escapeHtml(__('Billing Address')) ?>
|
||||
</button>
|
||||
<a class="esun-address-book__add" href="<?= $escaper->escapeUrl($block->getAddAddressUrl()) ?>">
|
||||
<span class="esun-address-book__add-icon" aria-hidden="true">+</span>
|
||||
<?= $escaper->escapeHtml(__('Add New Address')) ?>
|
||||
</a>
|
||||
</nav>
|
||||
|
||||
<div class="esun-address-book__panel is-active" data-address-panel="shipping">
|
||||
<?php if ($shippingAddresses): ?>
|
||||
<div class="esun-address-book__grid">
|
||||
<?php foreach ($shippingAddresses as $address): ?>
|
||||
<?php $addressId = (int) $address->getId(); ?>
|
||||
<article class="esun-address-card">
|
||||
<div class="esun-address-card__content">
|
||||
<div class="esun-address-card__identity">
|
||||
<strong><?= $escaper->escapeHtml($viewModel->getName($address)) ?></strong>
|
||||
<?php if ($address->getTelephone()): ?>
|
||||
<a href="tel:<?= $escaper->escapeHtmlAttr($address->getTelephone()) ?>">
|
||||
<?= $escaper->escapeHtml($address->getTelephone()) ?>
|
||||
</a>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
<address>
|
||||
<?php foreach ($viewModel->getStreetLines($address) as $streetLine): ?>
|
||||
<span><?= $escaper->escapeHtml($streetLine) ?></span>
|
||||
<?php endforeach; ?>
|
||||
<?php if ($locality = $viewModel->getLocalityLine($address)): ?>
|
||||
<span><?= $escaper->escapeHtml($locality) ?></span>
|
||||
<?php endif; ?>
|
||||
<?php if ($country = $viewModel->getCountryName($address)): ?>
|
||||
<span><?= $escaper->escapeHtml($country) ?></span>
|
||||
<?php endif; ?>
|
||||
</address>
|
||||
</div>
|
||||
<div class="esun-address-card__actions">
|
||||
<?php if ($addressId === $defaultShippingId): ?>
|
||||
<span class="esun-address-card__default">
|
||||
<?= $escaper->escapeHtml(__('Default')) ?>
|
||||
</span>
|
||||
<?php endif; ?>
|
||||
<?php if ($addressId !== $defaultShippingId && $addressId !== $defaultBillingId): ?>
|
||||
<a class="action delete"
|
||||
href="#"
|
||||
role="delete-address"
|
||||
data-address="<?= $escaper->escapeHtmlAttr((string) $addressId) ?>">
|
||||
<?= $escaper->escapeHtml(__('Delete')) ?>
|
||||
</a>
|
||||
<?php endif; ?>
|
||||
<a class="action edit"
|
||||
href="<?= $escaper->escapeUrl($block->getAddressEditUrl($addressId)) ?>">
|
||||
<?= $escaper->escapeHtml(__('Edit')) ?>
|
||||
</a>
|
||||
</div>
|
||||
</article>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
<?php else: ?>
|
||||
<div class="esun-address-book__empty">
|
||||
<?= $escaper->escapeHtml(__('You have no shipping address in your address book.')) ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
|
||||
<div class="esun-address-book__panel" data-address-panel="billing" hidden>
|
||||
<?php if ($defaultBilling): ?>
|
||||
<div class="esun-address-book__grid">
|
||||
<article class="esun-address-card">
|
||||
<div class="esun-address-card__content">
|
||||
<div class="esun-address-card__identity">
|
||||
<strong><?= $escaper->escapeHtml($viewModel->getName($defaultBilling)) ?></strong>
|
||||
<?php if ($defaultBilling->getTelephone()): ?>
|
||||
<a href="tel:<?= $escaper->escapeHtmlAttr($defaultBilling->getTelephone()) ?>">
|
||||
<?= $escaper->escapeHtml($defaultBilling->getTelephone()) ?>
|
||||
</a>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
<address>
|
||||
<?php foreach ($viewModel->getStreetLines($defaultBilling) as $streetLine): ?>
|
||||
<span><?= $escaper->escapeHtml($streetLine) ?></span>
|
||||
<?php endforeach; ?>
|
||||
<?php if ($locality = $viewModel->getLocalityLine($defaultBilling)): ?>
|
||||
<span><?= $escaper->escapeHtml($locality) ?></span>
|
||||
<?php endif; ?>
|
||||
<?php if ($country = $viewModel->getCountryName($defaultBilling)): ?>
|
||||
<span><?= $escaper->escapeHtml($country) ?></span>
|
||||
<?php endif; ?>
|
||||
</address>
|
||||
</div>
|
||||
<div class="esun-address-card__actions">
|
||||
<span class="esun-address-card__default">
|
||||
<?= $escaper->escapeHtml(__('Default')) ?>
|
||||
</span>
|
||||
<a class="action edit"
|
||||
href="<?= $escaper->escapeUrl($block->getAddressEditUrl($defaultBillingId)) ?>">
|
||||
<?= $escaper->escapeHtml(__('Edit')) ?>
|
||||
</a>
|
||||
</div>
|
||||
</article>
|
||||
</div>
|
||||
<?php else: ?>
|
||||
<div class="esun-address-book__empty">
|
||||
<p><?= $escaper->escapeHtml(__('You have no default billing address in your address book.')) ?></p>
|
||||
<a class="action primary" href="<?= $escaper->escapeUrl($block->getAddAddressUrl()) ?>">
|
||||
<?= $escaper->escapeHtml(__('Add New Address')) ?>
|
||||
</a>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<script type="text/x-magento-init">
|
||||
{
|
||||
".esun-address-book": {
|
||||
"address": {
|
||||
"deleteAddress": "a[role='delete-address']",
|
||||
"deleteUrlPrefix": "<?= $escaper->escapeJs($escaper->escapeUrl($block->getDeleteUrl())) ?>id/"
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
Reference in New Issue
Block a user