Skip to content

Enabling Individual Editing of Shipping and Billing Addresses from the Customer Dashboard #38677

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: 2.4-develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 32 additions & 2 deletions app/code/Magento/Customer/Block/Address/Edit.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
<?php

/**
* Copyright © Magento, Inc. All rights reserved.
* Copyright 2017 Adobe
* See COPYING.txt for license details.
*/

namespace Magento\Customer\Block\Address;

use Magento\Customer\Api\AddressMetadataInterface;
Expand Down Expand Up @@ -244,9 +246,37 @@ public function getBackUrl()
*/
public function getSaveUrl()
{
return $this->getSaveUrlWithParams();
}

/**
* Return the Url for saving with parameters.
*
* @param int $defaultShipping Default shipping flag
* @param int $defaultBilling Default billing flag
* @return string
*/
public function getSaveUrlWithParams($defaultShipping = 0, $defaultBilling = 0)
{
$queryParams = ['_secure' => true];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess we can simplified this section as follows:

$queryParams = ['_secure' => true];

// Consolidate $defaultShipping and $defaultBilling conditions
if ($defaultShipping == 1) {
    $queryParams['default_shipping'] = 1;
}
if ($defaultBilling == 1) {
    $queryParams['default_billing'] = 1;
}

// Add 'id' parameter only if the address is not both default billing and shipping
if (!$this->getAddress()->isDefaultBilling() || !$this->getAddress()->isDefaultShipping()) {
    $queryParams['id'] = $this->getAddress()->getId();
}

// URL construction remains in a single block
$postURL = $this->_urlBuilder->getUrl(
    'customer/address/formPost',
    $queryParams
);

Just a sample code, just check the condition before implementing the same.


// Consolidate $defaultShipping and $defaultBilling conditions
if ($defaultShipping == 1) {
$queryParams['default_shipping'] = 1;
}
if ($defaultBilling == 1) {
$queryParams['default_billing'] = 1;
}

// Add 'id' parameter only if the address is not both default billing and shipping
if (!$this->getAddress()->isDefaultBilling() || !$this->getAddress()->isDefaultShipping()) {
$queryParams['id'] = $this->getAddress()->getId();
}

// URL construction remains in a single block
return $this->_urlBuilder->getUrl(
'customer/address/formPost',
['_secure' => true, 'id' => $this->getAddress()->getId()]
$queryParams
);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,41 +1,53 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* Copyright 2017 Adobe
* See COPYING.txt for license details.
*/

/** @var \Magento\Customer\Block\Account\Dashboard\Address $block */
?>
<div class="block block-dashboard-addresses">
<div class="block-title">
<strong><?= $block->escapeHtml(__('Address Book')) ?></strong>
<a class="action edit" href="<?= $block->escapeUrl($block->getAddressBookUrl()) ?>"><span><?= $block->escapeHtml(__('Manage Addresses')) ?></span></a>
<strong><?= $escaper->escapeHtml(__('Address Book')) ?></strong>
<a class="action edit" href="<?= $escaper->escapeUrl($block->getAddressBookUrl()) ?>">
<span><?= $escaper->escapeHtml(__('Manage Addresses')) ?></span>
</a>
</div>
<div class="block-content">
<div class="box box-billing-address">
<strong class="box-title">
<span><?= $block->escapeHtml(__('Default Billing Address')) ?></span>
<span><?= $escaper->escapeHtml(__('Default Billing Address')) ?></span>
</strong>
<div class="box-content">
<address>
<?= $block->getPrimaryBillingAddressHtml() ?>
</address>
</div>
<div class="box-actions">
<a class="action edit" href="<?= $block->escapeUrl($block->getPrimaryBillingAddressEditUrl()) ?>" data-ui-id="default-billing-edit-link"><span><?= $block->escapeHtml(__('Edit Address')) ?></span></a>
<a
class="action edit"
href="<?= $escaper->escapeUrl($block->getPrimaryBillingAddressEditUrl() . '?billingAddress') ?>"
data-ui-id="default-billing-edit-link">
<span><?= $escaper->escapeHtml(__('Edit Billing Address')) ?></span>
</a>
</div>
</div>
<div class="box box-shipping-address">
<strong class="box-title">
<span><?= $block->escapeHtml(__('Default Shipping Address')) ?></span>
<span><?= $escaper->escapeHtml(__('Default Shipping Address')) ?></span>
</strong>
<div class="box-content">
<address>
<?= $block->getPrimaryShippingAddressHtml() ?>
</address>
</div>
<div class="box-actions">
<a class="action edit" href="<?= $block->escapeUrl($block->getPrimaryShippingAddressEditUrl()) ?>" data-ui-id="default-shipping-edit-link"><span><?= $block->escapeHtml(__('Edit Address')) ?></span></a>
<a
class="action edit"
href="<?= $escaper->escapeUrl($block->getPrimaryShippingAddressEditUrl() . '?shippingAddress') ?>"
data-ui-id="default-shipping-edit-link">
<span><?= $escaper->escapeHtml(__('Edit Shipping Address')) ?></span>
</a>
</div>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* Copyright 2017 Adobe
* All Rights Reserved.
Expand All @@ -22,7 +23,9 @@
</div>
<div class="box-actions">
<a class="action edit"
href="<?= $escaper->escapeUrl($block->getAddressEditUrl($defaultBillingAddress)) ?>">
href="
<?= $escaper->escapeUrl($block->getAddressEditUrl($defaultBillingAddress) . '?billingAddress')
?>">
<span><?= $escaper->escapeHtml(__('Change Billing Address')) ?></span>
</a>
</div>
Expand Down Expand Up @@ -50,7 +53,9 @@
</div>
<div class="box-actions">
<a class="action edit"
href="<?= $escaper->escapeUrl($block->getAddressEditUrl($defaultShippingAddress)) ?>">
href="
<?= $escaper->escapeUrl($block->getAddressEditUrl($defaultShippingAddress) . '?shippingAddress') ?>
">
<span><?= $escaper->escapeHtml(__('Change Shipping Address')) ?></span>
</a>
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* Copyright 2017 Adobe
* See COPYING.txt for license details.
*/

Expand All @@ -12,6 +12,10 @@
$viewModel = $block->getViewModel();
$regionProvider = $block->getRegionProvider();
?>
<?php
$defaultShipping = ($block->getRequest()->getParam('shippingAddress') !== null) ? 1 : 0;
$defaultBilling = ($block->getRequest()->getParam('billingAddress') !== null) ? 1 : 0;
?>
<?php $_company = $block->getLayout()->createBlock(\Magento\Customer\Block\Widget\Company::class) ?>
<?php $_telephone = $block->getLayout()->createBlock(\Magento\Customer\Block\Widget\Telephone::class) ?>
<?php $_fax = $block->getLayout()->createBlock(\Magento\Customer\Block\Widget\Fax::class) ?>
Expand All @@ -31,11 +35,11 @@ $regionProvider = $block->getRegionProvider();
trim(str_replace('required-entry', '', $_streetValidationClass)) : ''; ?>
<?php $_regionValidationClass = $viewModel->addressGetAttributeValidationClass('region'); ?>
<form class="form-address-edit"
action="<?= $escaper->escapeUrl($block->getSaveUrl()) ?>"
method="post"
id="form-validate"
enctype="multipart/form-data"
data-hasrequired="<?= $escaper->escapeHtmlAttr(__('* Required Fields')) ?>">
action="<?= $escaper->escapeUrl($block->getSaveUrlWithParams($defaultShipping, $defaultBilling)) ?>"
method="post"
id="form-validate"
enctype="multipart/form-data"
data-hasrequired="<?= $escaper->escapeHtmlAttr(__('* Required Fields')) ?>">
<fieldset class="fieldset">
<legend class="legend"><span><?= $escaper->escapeHtml(__('Contact Information')) ?></span></legend><br>
<?= $block->getBlockHtml('formkey') ?>
Expand Down