Skip to content

Commit a31a7ea

Browse files
committed
Merge remote-tracking branch 'local/ACP2E-1225' into PR_combine
2 parents 4670034 + 2c2ab18 commit a31a7ea

File tree

2 files changed

+127
-1
lines changed

2 files changed

+127
-1
lines changed

app/code/Magento/Sales/Model/AdminOrder/Create.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1490,8 +1490,12 @@ public function setShippingAsBilling($flag)
14901490
$tmpAddress->unsAddressId()->unsAddressType();
14911491
$data = $tmpAddress->getData();
14921492
$data['save_in_address_book'] = 0;
1493+
$shippingAddressTmp = $this->getShippingAddress()->getData();
14931494
// Do not duplicate address (billing address will do saving too)
14941495
$this->getShippingAddress()->addData($data);
1496+
if (array_key_exists('weight', $shippingAddressTmp) && !empty($shippingAddressTmp['weight'])) {
1497+
$this->getShippingAddress()->setWeight($shippingAddressTmp['weight']);
1498+
}
14951499
}
14961500
$this->getShippingAddress()->setSameAsBilling($flag);
14971501
$this->setRecollect(true);

app/code/Magento/Sales/Test/Unit/Model/AdminOrder/CreateTest.php

Lines changed: 123 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
*/
4040
class CreateTest extends TestCase
4141
{
42-
const CUSTOMER_ID = 1;
42+
public const CUSTOMER_ID = 1;
4343

4444
/**
4545
* @var Create
@@ -461,4 +461,126 @@ public function testInitFromOrder()
461461

462462
$this->adminOrderCreate->initFromOrder($this->orderMock);
463463
}
464+
465+
/**
466+
* Test case for setShippingAsBilling
467+
*
468+
* @dataProvider setShippingAsBillingDataProvider
469+
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
470+
*/
471+
public function testSetShippingAsBilling(bool $flag, array $billingData, array $shippingData): void
472+
{
473+
$billingAddress = $this->createPartialMock(Address::class, ['getData']);
474+
$shippingAddress = $this->createPartialMock(
475+
Address::class,
476+
[
477+
'addData',
478+
'setSameAsBilling',
479+
'getData',
480+
]
481+
);
482+
$billingAddress->expects($this->any())
483+
->method('getData')
484+
->willReturn($billingData);
485+
$shippingAddress->expects($this->any())
486+
->method('getData')
487+
->willReturn($shippingData);
488+
$shippingAddress->expects($this->any())
489+
->method('addData')
490+
->willReturnSelf();
491+
$shippingAddress->expects($this->any())
492+
->method('setSameAsBilling')
493+
->with($flag)
494+
->willReturnSelf();
495+
$quote = $this->getMockBuilder(Quote::class)
496+
->disableOriginalConstructor()
497+
->setMethods(
498+
[
499+
'getBillingAddress',
500+
'getShippingAddress',
501+
'setRecollect'
502+
]
503+
)
504+
->getMock();
505+
506+
$quote->expects($this->any())
507+
->method('getBillingAddress')
508+
->willReturn($billingAddress);
509+
$quote->expects($this->any())
510+
->method('getShippingAddress')
511+
->willReturn($shippingAddress);
512+
$quote->expects($this->any())
513+
->method('setRecollect')
514+
->willReturn(true);
515+
$this->sessionQuote
516+
->method('getQuote')
517+
->willReturn($quote);
518+
$this->adminOrderCreate->setShippingAsBilling($flag);
519+
}
520+
521+
/**
522+
* Data provider for setShippingAsBilling function
523+
*
524+
* @return array
525+
*/
526+
public function setShippingAsBillingDataProvider(): array
527+
{
528+
return [
529+
'testcase when sameAsBillingFlag is false' => [
530+
false,
531+
[
532+
'quote_id' => 1,
533+
'entity_id' => 1,
534+
'same_as_billing' => 1,
535+
'customer_address_id' => null,
536+
'weight' => '0.0000',
537+
'free_shipping' => '0'
538+
],
539+
[
540+
'quote_id' => 1,
541+
'entity_id' => 1,
542+
'same_as_billing' => 1,
543+
'customer_address_id' => null,
544+
'weight' => '0.0000',
545+
'free_shipping' => '0'
546+
]
547+
],
548+
'testcase when sameAsBillingFlag is true and there is no `weight` property' => [
549+
true,
550+
[
551+
'quote_id' => 1,
552+
'entity_id' => 1,
553+
'same_as_billing' => 1,
554+
'customer_address_id' => null,
555+
'free_shipping' => '0'
556+
],
557+
[
558+
'quote_id' => 1,
559+
'entity_id' => 1,
560+
'same_as_billing' => 1,
561+
'customer_address_id' => null,
562+
'free_shipping' => '0'
563+
]
564+
],
565+
'testcase when sameAsBillingFlag is true and there is `weight` property' => [
566+
false,
567+
[
568+
'quote_id' => 1,
569+
'entity_id' => 1,
570+
'same_as_billing' => 1,
571+
'customer_address_id' => null,
572+
'weight' => '0.0000',
573+
'free_shipping' => '1'
574+
],
575+
[
576+
'quote_id' => 1,
577+
'entity_id' => 1,
578+
'same_as_billing' => 1,
579+
'customer_address_id' => null,
580+
'weight' => '8.0000',
581+
'free_shipping' => '1'
582+
]
583+
]
584+
];
585+
}
464586
}

0 commit comments

Comments
 (0)