From 98ff1839b38ee76eef1715c4d861abba7bd07633 Mon Sep 17 00:00:00 2001 From: franciscof Date: Mon, 29 Apr 2024 22:12:19 -0300 Subject: [PATCH 1/3] improve shipping or billing address editing --- .../Magento/Customer/Block/Address/Edit.php | 26 +++++++++++++++---- .../templates/account/dashboard/address.phtml | 4 +-- .../frontend/templates/address/book.phtml | 4 +-- .../frontend/templates/address/edit.phtml | 12 +++++---- 4 files changed, 32 insertions(+), 14 deletions(-) diff --git a/app/code/Magento/Customer/Block/Address/Edit.php b/app/code/Magento/Customer/Block/Address/Edit.php index 9ac1870cd17d9..1c38ca7d81340 100644 --- a/app/code/Magento/Customer/Block/Address/Edit.php +++ b/app/code/Magento/Customer/Block/Address/Edit.php @@ -242,12 +242,28 @@ public function getBackUrl() * * @return string */ - public function getSaveUrl() + public function getSaveUrl($defaultShipping = 0, $defaultBilling = 0) { - return $this->_urlBuilder->getUrl( - 'customer/address/formPost', - ['_secure' => true, 'id' => $this->getAddress()->getId()] - ); + $queryParams = ['_secure' => true]; + if ($defaultShipping == 1) { + $queryParams['default_shipping'] = 1; + } elseif ($defaultBilling == 1) { + $queryParams['default_billing'] = 1; + } + + if ($this->getAddress()->isDefaultBilling() && $this->getAddress()->isDefaultShipping()) { + $postURL = $this->_urlBuilder->getUrl( + 'customer/address/formPost', + $queryParams + ); + } else { + $queryParams['id'] = $this->getAddress()->getId(); + $postURL = $this->_urlBuilder->getUrl( + 'customer/address/formPost', + $queryParams + ); + } + return $postURL; } /** diff --git a/app/code/Magento/Customer/view/frontend/templates/account/dashboard/address.phtml b/app/code/Magento/Customer/view/frontend/templates/account/dashboard/address.phtml index d306e8c7c734f..577852b57f843 100644 --- a/app/code/Magento/Customer/view/frontend/templates/account/dashboard/address.phtml +++ b/app/code/Magento/Customer/view/frontend/templates/account/dashboard/address.phtml @@ -22,7 +22,7 @@
- escapeHtml(__('Edit Address')) ?> + escapeHtml(__('Edit Billing Address')) ?>
@@ -35,7 +35,7 @@
- escapeHtml(__('Edit Address')) ?> + escapeHtml(__('Edit Shipping Address')) ?>
diff --git a/app/code/Magento/Customer/view/frontend/templates/address/book.phtml b/app/code/Magento/Customer/view/frontend/templates/address/book.phtml index 8e401f51509f6..7e2a3d1fa4eed 100644 --- a/app/code/Magento/Customer/view/frontend/templates/address/book.phtml +++ b/app/code/Magento/Customer/view/frontend/templates/address/book.phtml @@ -20,7 +20,7 @@
- + escapeHtml(__('Change Billing Address')) ?>
@@ -45,7 +45,7 @@
- + escapeHtml(__('Change Shipping Address')) ?>
diff --git a/app/code/Magento/Customer/view/frontend/templates/address/edit.phtml b/app/code/Magento/Customer/view/frontend/templates/address/edit.phtml index a958f831e18a8..ea3729139f301 100644 --- a/app/code/Magento/Customer/view/frontend/templates/address/edit.phtml +++ b/app/code/Magento/Customer/view/frontend/templates/address/edit.phtml @@ -12,6 +12,8 @@ $viewModel = $block->getViewModel(); $regionProvider = $block->getRegionProvider(); ?> + + getLayout()->createBlock(\Magento\Customer\Block\Widget\Company::class) ?> getLayout()->createBlock(\Magento\Customer\Block\Widget\Telephone::class) ?> getLayout()->createBlock(\Magento\Customer\Block\Widget\Fax::class) ?> @@ -31,11 +33,11 @@ $regionProvider = $block->getRegionProvider(); trim(str_replace('required-entry', '', $_streetValidationClass)) : ''; ?> addressGetAttributeValidationClass('region'); ?>
+action="escapeUrl($block->getSaveUrl($shippingParam, $billingParam)) ?>" + method="post" + id="form-validate" + enctype="multipart/form-data" + data-hasrequired="escapeHtmlAttr(__('* Required Fields')) ?>">
escapeHtml(__('Contact Information')) ?>
getBlockHtml('formkey') ?> From 6eb70f04e2c888d63e8e6cd887c0b828974d0faa Mon Sep 17 00:00:00 2001 From: franciscof Date: Tue, 30 Apr 2024 12:13:35 -0300 Subject: [PATCH 2/3] Update coding standard issues --- .../Magento/Customer/Block/Address/Edit.php | 2 + .../templates/account/dashboard/address.phtml | 24 +++++++++--- .../frontend/templates/address/book.phtml | 38 +++++++++++-------- .../frontend/templates/address/edit.phtml | 4 +- 4 files changed, 45 insertions(+), 23 deletions(-) diff --git a/app/code/Magento/Customer/Block/Address/Edit.php b/app/code/Magento/Customer/Block/Address/Edit.php index 1c38ca7d81340..c0b71cc4b39db 100644 --- a/app/code/Magento/Customer/Block/Address/Edit.php +++ b/app/code/Magento/Customer/Block/Address/Edit.php @@ -240,6 +240,8 @@ public function getBackUrl() /** * Return the Url for saving. * + * @param int $defaultShipping Default shipping flag + * @param int $defaultBilling Default billing flag * @return string */ public function getSaveUrl($defaultShipping = 0, $defaultBilling = 0) diff --git a/app/code/Magento/Customer/view/frontend/templates/account/dashboard/address.phtml b/app/code/Magento/Customer/view/frontend/templates/account/dashboard/address.phtml index 577852b57f843..e72a6e6a12d64 100644 --- a/app/code/Magento/Customer/view/frontend/templates/account/dashboard/address.phtml +++ b/app/code/Magento/Customer/view/frontend/templates/account/dashboard/address.phtml @@ -8,13 +8,15 @@ ?>
- escapeHtml(__('Address Book')) ?> - escapeHtml(__('Manage Addresses')) ?> + escapeHtml(__('Address Book')) ?> + + escapeHtml(__('Manage Addresses')) ?> +
- escapeHtml(__('Default Billing Address')) ?> + escapeHtml(__('Default Billing Address')) ?>
@@ -22,12 +24,17 @@
- escapeHtml(__('Default Shipping Address')) ?> + escapeHtml(__('Default Shipping Address')) ?>
@@ -35,7 +42,12 @@
diff --git a/app/code/Magento/Customer/view/frontend/templates/address/book.phtml b/app/code/Magento/Customer/view/frontend/templates/address/book.phtml index 7e2a3d1fa4eed..f209d997984ee 100644 --- a/app/code/Magento/Customer/view/frontend/templates/address/book.phtml +++ b/app/code/Magento/Customer/view/frontend/templates/address/book.phtml @@ -7,12 +7,12 @@ /** @var \Magento\Customer\Block\Address\Book $block */ ?>
-
escapeHtml(__('Default Addresses')) ?>
+
escapeHtml(__('Default Addresses')) ?>
- getDefaultBilling()) : ?> + getDefaultBilling()): ?>
- escapeHtml(__('Default Billing Address')) ?> + escapeHtml(__('Default Billing Address')) ?>
@@ -20,24 +20,28 @@
- +
- escapeHtml(__('Default Billing Address')) ?> + + escapeHtml(__('Default Billing Address')) ?> +
-

escapeHtml(__('You have no default billing address in your address book.')) ?>

+

escapeHtml(__('You have no default billing address in your address book.')) ?>

- getDefaultShipping()) : ?> + getDefaultShipping()): ?>
- escapeHtml(__('Default Shipping Address')) ?> + escapeHtml(__('Default Shipping Address')) ?>
@@ -45,16 +49,20 @@
- +
- escapeHtml(__('Default Shipping Address')) ?> + + escapeHtml(__('Default Shipping Address')) ?> +
-

escapeHtml(__('You have no default shipping address in your address book.')) ?>

+

escapeHtml(__('You have no default shipping address in your address book.')) ?>

diff --git a/app/code/Magento/Customer/view/frontend/templates/address/edit.phtml b/app/code/Magento/Customer/view/frontend/templates/address/edit.phtml index ea3729139f301..8f9aac546ff61 100644 --- a/app/code/Magento/Customer/view/frontend/templates/address/edit.phtml +++ b/app/code/Magento/Customer/view/frontend/templates/address/edit.phtml @@ -12,8 +12,8 @@ $viewModel = $block->getViewModel(); $regionProvider = $block->getRegionProvider(); ?> - - +getRequest()->getParam('shippingAddress') !== null; ?> +getRequest()->getParam('billingAddress') !== null; ?> getLayout()->createBlock(\Magento\Customer\Block\Widget\Company::class) ?> getLayout()->createBlock(\Magento\Customer\Block\Widget\Telephone::class) ?> getLayout()->createBlock(\Magento\Customer\Block\Widget\Fax::class) ?> From ddda6d7156cc5914a3bccfd2ad252b750b4f474f Mon Sep 17 00:00:00 2001 From: franciscof Date: Thu, 1 May 2025 21:48:20 -0300 Subject: [PATCH 3/3] update and improve save params --- .../Magento/Customer/Block/Address/Edit.php | 38 ++++++++++++------- .../frontend/templates/address/edit.phtml | 8 ++-- 2 files changed, 30 insertions(+), 16 deletions(-) diff --git a/app/code/Magento/Customer/Block/Address/Edit.php b/app/code/Magento/Customer/Block/Address/Edit.php index 788cd3db96528..296d62f9ac3ae 100644 --- a/app/code/Magento/Customer/Block/Address/Edit.php +++ b/app/code/Magento/Customer/Block/Address/Edit.php @@ -1,8 +1,10 @@ getSaveUrlWithParams(); + } + + /** + * Return the Url for saving with parameters. + * * @param int $defaultShipping Default shipping flag * @param int $defaultBilling Default billing flag * @return string */ - public function getSaveUrl($defaultShipping = 0, $defaultBilling = 0) + public function getSaveUrlWithParams($defaultShipping = 0, $defaultBilling = 0) { $queryParams = ['_secure' => true]; + + // Consolidate $defaultShipping and $defaultBilling conditions if ($defaultShipping == 1) { $queryParams['default_shipping'] = 1; - } elseif ($defaultBilling == 1) { + } + if ($defaultBilling == 1) { $queryParams['default_billing'] = 1; } - if ($this->getAddress()->isDefaultBilling() && $this->getAddress()->isDefaultShipping()) { - $postURL = $this->_urlBuilder->getUrl( - 'customer/address/formPost', - $queryParams - ); - } else { + // 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(); - $postURL = $this->_urlBuilder->getUrl( - 'customer/address/formPost', - $queryParams - ); } - return $postURL; + + // URL construction remains in a single block + return $this->_urlBuilder->getUrl( + 'customer/address/formPost', + $queryParams + ); } /** diff --git a/app/code/Magento/Customer/view/frontend/templates/address/edit.phtml b/app/code/Magento/Customer/view/frontend/templates/address/edit.phtml index 6125c7f31c7c1..67f3c201a72b7 100644 --- a/app/code/Magento/Customer/view/frontend/templates/address/edit.phtml +++ b/app/code/Magento/Customer/view/frontend/templates/address/edit.phtml @@ -12,8 +12,10 @@ $viewModel = $block->getViewModel(); $regionProvider = $block->getRegionProvider(); ?> -getRequest()->getParam('shippingAddress') !== null; ?> -getRequest()->getParam('billingAddress') !== null; ?> +getRequest()->getParam('shippingAddress') !== null) ? 1 : 0; +$defaultBilling = ($block->getRequest()->getParam('billingAddress') !== null) ? 1 : 0; +?> getLayout()->createBlock(\Magento\Customer\Block\Widget\Company::class) ?> getLayout()->createBlock(\Magento\Customer\Block\Widget\Telephone::class) ?> getLayout()->createBlock(\Magento\Customer\Block\Widget\Fax::class) ?> @@ -33,7 +35,7 @@ $regionProvider = $block->getRegionProvider(); trim(str_replace('required-entry', '', $_streetValidationClass)) : ''; ?> addressGetAttributeValidationClass('region'); ?>