Skip to content

Commit ed9cfe4

Browse files
merge magento-commerce/2.3-develop into magento-tsg/MC-40510
2 parents 3c0c7ab + ac8d550 commit ed9cfe4

File tree

7 files changed

+84
-14
lines changed

7 files changed

+84
-14
lines changed

app/code/Magento/Sales/Test/Mftf/Test/AdminSaveInAddressBookCheckboxStateTest.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@
4747
<actionGroup ref="addSimpleProductToOrder" stepKey="addSimpleProductToOrder">
4848
<argument name="product" value="$$createSimpleProduct$$"/>
4949
</actionGroup>
50+
<!-- By default checkbox 'Add to address book' must be unchecked -->
51+
<dontSeeCheckboxIsChecked selector="{{AdminOrderFormBillingAddressSection.SaveAddress}}" stepKey="checkBoxAddBillingAddressIsUnchecked"/>
5052
<!-- Just in case uncheck and check 'Same as Billing Address checkbox' -->
5153
<comment userInput="Just in case uncheck and check 'Same as Billing Address checkbox'" stepKey="uncheckAndCheckAgain"/>
5254
<uncheckOption selector="{{AdminOrderFormShippingAddressSection.SameAsBilling}}" stepKey="unCheckSameAsShippingAddressCheckbox"/>
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Sales\ViewModel\Customer\Address\Billing;
9+
10+
use Magento\Framework\View\Element\Block\ArgumentInterface;
11+
use Magento\Sales\Model\AdminOrder\Create;
12+
13+
/**
14+
* Customer billing address data provider
15+
*/
16+
class AddressDataProvider implements ArgumentInterface
17+
{
18+
/**
19+
* @var Create
20+
*/
21+
private $orderCreate;
22+
23+
/**
24+
* Customer billing address
25+
*
26+
* @param Create $orderCreate
27+
*/
28+
public function __construct(
29+
Create $orderCreate
30+
) {
31+
$this->orderCreate = $orderCreate;
32+
}
33+
34+
/**
35+
* Get save billing address in the address book
36+
*
37+
* @return int
38+
*/
39+
public function getSaveInAddressBook(): int
40+
{
41+
return (int)$this->orderCreate->getBillingAddress()->getSaveInAddressBook();
42+
}
43+
}

app/code/Magento/Sales/i18n/en_US.csv

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -799,3 +799,4 @@ Refunds,Refunds
799799
"Allow Zero GrandTotal","Allow Zero GrandTotal"
800800
"Could not save the shipment tracking","Could not save the shipment tracking"
801801
"Please enter a coupon code!","Please enter a coupon code!"
802+
"Add to address book","Add to address book"

app/code/Magento/Sales/view/adminhtml/layout/sales_order_create_index.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
<arguments>
5656
<argument name="customerAddressFormatter" xsi:type="object">Magento\Sales\ViewModel\Customer\AddressFormatter</argument>
5757
<argument name="customerAddressCollection" xsi:type="object">Magento\Customer\Model\ResourceModel\Address\Collection</argument>
58+
<argument name="billingAddressDataProvider" xsi:type="object">Magento\Sales\ViewModel\Customer\Address\Billing\AddressDataProvider</argument>
5859
</arguments>
5960
</block>
6061
<block class="Magento\Sales\Block\Adminhtml\Order\Create\Shipping\Method" template="Magento_Sales::order/create/abstract.phtml" name="shipping_method">

app/code/Magento/Sales/view/adminhtml/layout/sales_order_create_load_block_billing_address.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
<arguments>
1313
<argument name="customerAddressFormatter" xsi:type="object">Magento\Sales\ViewModel\Customer\AddressFormatter</argument>
1414
<argument name="customerAddressCollection" xsi:type="object">Magento\Customer\Model\ResourceModel\Address\Collection</argument>
15+
<argument name="billingAddressDataProvider" xsi:type="object">Magento\Sales\ViewModel\Customer\Address\Billing\AddressDataProvider</argument>
1516
</arguments>
1617
</block>
1718
</referenceContainer>

app/code/Magento/Sales/view/adminhtml/layout/sales_order_create_load_block_data.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
<arguments>
3131
<argument name="customerAddressFormatter" xsi:type="object">Magento\Sales\ViewModel\Customer\AddressFormatter</argument>
3232
<argument name="customerAddressCollection" xsi:type="object">Magento\Customer\Model\ResourceModel\Address\Collection</argument>
33+
<argument name="billingAddressDataProvider" xsi:type="object">Magento\Sales\ViewModel\Customer\Address\Billing\AddressDataProvider</argument>
3334
</arguments>
3435
</block>
3536
<block class="Magento\Sales\Block\Adminhtml\Order\Create\Shipping\Method" template="Magento_Sales::order/create/abstract.phtml" name="shipping_method">

app/code/Magento/Sales/view/adminhtml/templates/order/create/form/address.phtml

Lines changed: 35 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
$addressCollection = $block->getData('customerAddressCollection');
1313

1414
$addressArray = [];
15-
if ($block->getCustomerId()) :
15+
if ($block->getCustomerId()):
1616
$addressArray = $addressCollection->setCustomerFilter([$block->getCustomerId()])->toArray();
1717
endif;
1818

@@ -22,9 +22,15 @@ endif;
2222
$customerAddressFormatter = $block->getData('customerAddressFormatter');
2323

2424
/**
25-
* @var \Magento\Sales\Block\Adminhtml\Order\Create\Billing\Address|\Magento\Sales\Block\Adminhtml\Order\Create\Shipping\Address $block
25+
* @var \Magento\Sales\ViewModel\Customer\Address\Billing\AddressDataProvider $billingAddressDataProvider
2626
*/
27-
if ($block->getIsShipping()) :
27+
$billingAddressDataProvider = $block->getData('billingAddressDataProvider');
28+
29+
/**
30+
* @var \Magento\Sales\Block\Adminhtml\Order\Create\Billing\Address|
31+
* \Magento\Sales\Block\Adminhtml\Order\Create\Shipping\Address $block
32+
*/
33+
if ($block->getIsShipping()):
2834
$_fieldsContainerId = 'order-shipping_address_fields';
2935
$_addressChoiceContainerId = 'order-shipping_address_choice';
3036
?>
@@ -35,7 +41,7 @@ if ($block->getIsShipping()) :
3541
});
3642
</script>
3743
<?php
38-
else :
44+
else:
3945
$_fieldsContainerId = 'order-billing_address_fields';
4046
$_addressChoiceContainerId = 'order-billing_address_choice';
4147
?>
@@ -52,29 +58,37 @@ endif; ?>
5258
<span><?= $block->escapeHtml($block->getHeaderText()) ?></span>
5359
</legend><br>
5460

55-
<fieldset id="<?= $block->escapeHtmlAttr($_addressChoiceContainerId) ?>" class="admin__fieldset order-choose-address">
56-
<?php if ($block->getIsShipping()) : ?>
61+
<fieldset id="<?= $block->escapeHtmlAttr($_addressChoiceContainerId) ?>"
62+
class="admin__fieldset order-choose-address">
63+
<?php if ($block->getIsShipping()): ?>
5764
<div class="admin__field admin__field-option admin__field-shipping-same-as-billing">
5865
<input type="checkbox" id="order-shipping_same_as_billing" name="shipping_same_as_billing"
5966
onclick="order.setShippingAsBilling(this.checked)" class="admin__control-checkbox"
60-
<?php if ($block->getIsAsBilling()) : ?>checked<?php endif; ?> />
67+
<?php if ($block->getIsAsBilling()): ?>checked<?php endif; ?> />
6168
<label for="order-shipping_same_as_billing" class="admin__field-label">
6269
<?= $block->escapeHtml(__('Same As Billing Address')) ?>
6370
</label>
6471
</div>
6572
<?php endif; ?>
6673
<div class="admin__field admin__field-select-from-existing-address">
67-
<label class="admin__field-label"><?= $block->escapeHtml(__('Select from existing customer addresses:')) ?></label>
74+
<label class="admin__field-label">
75+
<?= $block->escapeHtml(__('Select from existing customer addresses:')) ?>
76+
</label>
6877
<?php $_id = $block->getForm()->getHtmlIdPrefix() . 'customer_address_id' ?>
6978
<div class="admin__field-control">
7079
<select id="<?= $block->escapeHtmlAttr($_id) ?>"
7180
name="<?= /* @noEscape */ $block->getForm()->getHtmlNamePrefix() ?>[customer_address_id]"
72-
onchange="order.selectAddress(this, '<?= $block->escapeHtmlAttr($block->escapeJs($_fieldsContainerId)) ?>')"
81+
onchange="order.selectAddress(
82+
this,
83+
'<?= $block->escapeHtmlAttr($block->escapeJs($_fieldsContainerId)) ?>')"
7384
class="admin__control-select">
7485
<option value=""><?= $block->escapeHtml(__('Add New Address')) ?></option>
75-
<?php foreach ($addressArray as $addressId => $address) : ?>
86+
<?php foreach ($addressArray as $addressId => $address): ?>
7687
<option
77-
value="<?= $block->escapeHtmlAttr($addressId) ?>"<?php if ($addressId == $block->getAddressId()) : ?> selected="selected"<?php endif; ?>>
88+
value="<?= $block->escapeHtmlAttr($addressId) ?>"
89+
<?php if ($addressId == $block->getAddressId()): ?>
90+
selected="selected"
91+
<?php endif; ?>>
7892
<?= $block->escapeHtml($customerAddressFormatter->getAddressAsString($address)) ?>
7993
</option>
8094
<?php endforeach; ?>
@@ -87,9 +101,16 @@ endif; ?>
87101
<?= $block->getForm()->toHtml() ?>
88102

89103
<div class="admin__field admin__field-option order-save-in-address-book">
90-
<input name="<?= /* @noEscape */ $block->getForm()->getHtmlNamePrefix() ?>[save_in_address_book]" type="checkbox" id="<?= /* @noEscape */ $block->getForm()->getHtmlIdPrefix() ?>save_in_address_book" value="1"<?php if (!$block->getDontSaveInAddressBook()) : ?> checked="checked"<?php endif; ?> class="admin__control-checkbox"/>
104+
<input name="<?= /* @noEscape */ $block->getForm()->getHtmlNamePrefix() ?>[save_in_address_book]"
105+
type="checkbox" id="<?= /* @noEscape */ $block->getForm()->getHtmlIdPrefix() ?>save_in_address_book"
106+
value="1"
107+
<?php if ($billingAddressDataProvider && $billingAddressDataProvider->getSaveInAddressBook() ||
108+
$block->getIsShipping() && !$block->getDontSaveInAddressBook() && !$block->getAddressId()): ?>
109+
checked="checked"
110+
<?php endif; ?>
111+
class="admin__control-checkbox"/>
91112
<label for="<?= /* @noEscape */ $block->getForm()->getHtmlIdPrefix() ?>save_in_address_book"
92-
class="admin__field-label"><?= $block->escapeHtml(__('Save in address book')) ?></label>
113+
class="admin__field-label"><?= $block->escapeHtml(__('Add to address book')) ?></label>
93114
</div>
94115
</div>
95116
<?php $hideElement = 'address-' . ($block->getIsShipping() ? 'shipping' : 'billing') . '-overlay'; ?>
@@ -101,7 +122,7 @@ endif; ?>
101122
require(["Magento_Sales/order/create/form"], function(){
102123
order.bindAddressFields('<?= $block->escapeJs($_fieldsContainerId) ?>');
103124
order.bindAddressFields('<?= $block->escapeJs($_addressChoiceContainerId) ?>');
104-
<?php if ($block->getIsShipping() && $block->getIsAsBilling()) : ?>
125+
<?php if ($block->getIsShipping() && $block->getIsAsBilling()): ?>
105126
order.disableShippingAddress(true);
106127
<?php endif; ?>
107128
});

0 commit comments

Comments
 (0)