Skip to content

Commit 5e11df0

Browse files
committed
Merge branch 'ACP2E-3294' of https://github.com/adobe-commerce-tier-4/magento2ce into PR-10-01-2024
2 parents 27954df + 397e522 commit 5e11df0

File tree

2 files changed

+100
-0
lines changed
  • app/code/Magento/Sales/view/adminhtml/web/order/create
  • dev/tests/js/jasmine/tests/app/code/Magento/Sales/adminhtml/js/order/create

2 files changed

+100
-0
lines changed

app/code/Magento/Sales/view/adminhtml/web/order/create/scripts.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,12 +326,26 @@
326326

327327
if (this.isBillingField(fieldName)) {
328328
syncName = fieldName.replace('billing', 'shipping');
329+
330+
if (fieldName.indexOf('country')) {
331+
jQuery('#order-shipping_address_region').css(
332+
'display',
333+
jQuery('#order-billing_address_region').css('display')
334+
);
335+
jQuery('#order-shipping_address_region_id').css(
336+
'display',
337+
jQuery('#order-billing_address_region_id').css('display')
338+
);
339+
}
329340
}
330341

331342
$(container).select('[name="' + syncName + '"]').each(function (element) {
332343
if (~['input', 'textarea', 'select'].indexOf(element.tagName.toLowerCase())) {
333344
if (element.type === "checkbox") {
334345
element.checked = fieldValue.checked;
346+
} else if (element.type === "select" || element.type === "select-one") {
347+
element.innerHTML = fieldValue.innerHTML;
348+
element.value = fieldValue.value;
335349
} else {
336350
element.value = fieldValue.value;
337351
}

dev/tests/js/jasmine/tests/app/code/Magento/Sales/adminhtml/js/order/create/scripts.test.js

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,92 @@ define([
160160
jQueryAjax = undefined;
161161
});
162162

163+
describe('Testing syncAddressField method', function () {
164+
it('Synchronize region and region_id fields display when called with field named "country"', function () {
165+
let form, billingCountryId, billingRegionId, billingRegion, billingCountryIdOption1,
166+
billingCountryIdOption2, shippingCountryId, shippingRegionId, shippingRegion, billingRegionOption1,
167+
billingRegionOption2, shippingCountryIdOption1, shippingOption2, shippingRegionOption1,
168+
shippingRegionOption2;
169+
170+
form = document.createElement('form');
171+
172+
//create billing country id field
173+
billingCountryId = document.createElement('select');
174+
billingCountryId.name = 'order[billing_address][country_id]';
175+
billingCountryIdOption1 = document.createElement('option');
176+
billingCountryIdOption1.value = 'USA';
177+
billingCountryIdOption1.innerText = 'United States of America';
178+
billingCountryIdOption2 = document.createElement('option');
179+
billingCountryIdOption2.value = 'RO';
180+
billingCountryIdOption2.innerText = 'Romania';
181+
billingCountryId.appendChild(billingCountryIdOption1);
182+
billingCountryId.appendChild(billingCountryIdOption2);
183+
form.appendChild(billingCountryId);
184+
185+
//create billing region id field
186+
billingRegionId = document.createElement('select');
187+
billingRegionId.name = 'order[billing_address][region_id]';
188+
billingRegionId.id = 'order-billing_address_region_id';
189+
billingRegionOption1 = document.createElement('option');
190+
billingRegionOption1.value = 'NY';
191+
billingRegionOption1.innerText = 'New York';
192+
billingRegionOption2 = document.createElement('option');
193+
billingRegionOption2.value = 'TX';
194+
billingRegionOption2.innerText = 'Texas';
195+
billingRegionId.appendChild(billingRegionOption1);
196+
billingRegionId.appendChild(billingRegionOption2);
197+
form.appendChild(billingRegionId);
198+
199+
//create hidden billing region field
200+
billingRegion = document.createElement('input');
201+
billingRegion.name = 'order[billing_address][region]';
202+
billingRegion.id = 'order-billing_address_region';
203+
billingRegion.style.display = 'none';
204+
form.appendChild(billingRegion);
205+
206+
//create shipping country id field
207+
shippingCountryId = document.createElement('select');
208+
shippingCountryId.name = 'order[shipping_address][country_id]';
209+
shippingCountryIdOption1 = document.createElement('option');
210+
shippingCountryIdOption1.value = 'USA';
211+
shippingCountryIdOption1.innerText = 'United States of America';
212+
shippingOption2 = document.createElement('option');
213+
shippingOption2.value = 'RO';
214+
shippingOption2.innerText = 'Romania';
215+
shippingCountryId.appendChild(shippingCountryIdOption1);
216+
shippingCountryId.appendChild(shippingOption2);
217+
shippingCountryId.value = 'RO';
218+
form.appendChild(shippingCountryId);
219+
220+
//create shipping region id field
221+
shippingRegionId = document.createElement('select');
222+
shippingRegionId.name = 'order[shipping_address][region_id]';
223+
shippingRegionId.id = 'order-shipping_address_region_id';
224+
shippingRegionOption1 = document.createElement('option');
225+
shippingRegionOption1.value = 'B';
226+
shippingRegionOption1.innerText = 'Bucuresti';
227+
shippingRegionOption2 = document.createElement('option');
228+
shippingRegionOption2.value = 'CT';
229+
shippingRegionOption2.innerText = 'Constanta';
230+
shippingRegionId.appendChild(shippingRegionOption1);
231+
shippingRegionId.appendChild(shippingRegionOption2);
232+
form.appendChild(shippingRegionId);
233+
234+
//create shipping region field
235+
shippingRegion = document.createElement('input');
236+
shippingRegion.name = 'order[shipping_address][region]';
237+
shippingRegion.id = 'order-shipping_address_region';
238+
form.appendChild(shippingRegion);
239+
240+
document.body.appendChild(form);
241+
order = new window.AdminOrder({});
242+
order.syncAddressField(form, 'order[billing_address][country_id]', billingCountryId);
243+
244+
expect(shippingCountryId.value).toEqual('USA');
245+
expect(shippingRegion.style.display).toEqual('none');
246+
});
247+
});
248+
163249
it('test that setStoreId calls loadArea with a callback', function () {
164250
init();
165251
spyOn(order, 'loadArea').and.callFake(function () {

0 commit comments

Comments
 (0)