Skip to content

Commit 9e0a769

Browse files
committed
Merge remote-tracking branch 'l3/MC-39354' into BUGFIX-11-23
2 parents c298521 + 3067d2d commit 9e0a769

File tree

3 files changed

+176
-0
lines changed

3 files changed

+176
-0
lines changed

dev/tests/integration/testsuite/Magento/Checkout/Api/GuestShippingInformationManagementTest.php

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
use Magento\Customer\Api\CustomerRepositoryInterface;
1313
use Magento\Framework\Api\SearchCriteriaBuilder;
1414
use Magento\Framework\Exception\InputException;
15+
use Magento\Framework\Exception\LocalizedException;
16+
use Magento\Framework\Exception\NoSuchEntityException;
1517
use Magento\Quote\Api\CartRepositoryInterface;
1618
use Magento\Quote\Api\Data\ShippingAssignmentInterface;
1719
use Magento\TestFramework\Helper\Bootstrap;
@@ -120,6 +122,51 @@ public function testDifferentAddresses(bool $swapShipping): void
120122
$this->management->saveAddressInformation($idMask->getMaskedId(), $shippingInformation);
121123
}
122124

125+
/**
126+
* Test save address information with customer custom address attribute for quote
127+
*
128+
* @return void
129+
*
130+
* @throws LocalizedException
131+
* @throws NoSuchEntityException
132+
* @magentoDataFixture Magento/Sales/_files/quote.php
133+
* @magentoDataFixture Magento/Customer/_files/customer_address_with_custom_text_attribute.php
134+
*/
135+
public function testSaveAddressInformationWithCustomerCustomAddressAttribute(): void
136+
{
137+
$carts = $this->cartRepo->getList(
138+
$this->searchCriteria->addFilter('reserved_order_id', 'test01')->create()
139+
)->getItems();
140+
$currentQuote = array_pop($carts);
141+
$guestCustomer = $this->customerRepo->get('JohnDoe@mail.com');
142+
143+
$customerCustomAddressAttribute = $guestCustomer->getCustomAttributes();
144+
145+
/** @var ShippingAssignmentInterface $shippingAssignment */
146+
$shippingAssignment = $currentQuote->getExtensionAttributes()->getShippingAssignments()[0];
147+
$shippingAddress = $shippingAssignment->getShipping()->getAddress();
148+
$billingAddress = $currentQuote->getBillingAddress();
149+
150+
if ($customerCustomAddressAttribute) {
151+
$shippingAddress->setCustomAttributes($customerCustomAddressAttribute);
152+
$billingAddress->setCustomAttributes($customerCustomAddressAttribute);
153+
}
154+
155+
/** @var ShippingInformationInterface $shippingInformation */
156+
$shippingInformation = $this->shippingFactory->create();
157+
$shippingInformation->setBillingAddress($billingAddress);
158+
$shippingInformation->setShippingAddress($shippingAddress);
159+
$shippingInformation->setShippingMethodCode('flatrate');
160+
$shippingInformation->setShippingCarrierCode('flatrate');
161+
/** @var QuoteIdMask $idMask */
162+
$idMask = $this->maskFactory->create();
163+
$idMask->load($currentQuote->getId(), 'quote_id');
164+
165+
$paymentDetails = $this->management->saveAddressInformation($idMask->getMaskedId(), $shippingInformation);
166+
$this->assertNotEmpty($paymentDetails);
167+
$this->assertEquals($currentQuote->getGrandTotal(), $paymentDetails->getTotals()->getSubtotal());
168+
}
169+
123170
/**
124171
* Different variations for addresses test.
125172
*
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
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+
use Magento\Customer\Model\Address;
9+
use Magento\Customer\Model\Customer;
10+
use Magento\Eav\Model\Config;
11+
use Magento\Eav\Model\Entity\Type;
12+
use Magento\Framework\Registry;
13+
use Magento\TestFramework\Helper\Bootstrap;
14+
use Magento\Customer\Model\Attribute;
15+
use Magento\Eav\Model\Entity\Attribute\Set;
16+
17+
$objectManager = Bootstrap::getObjectManager();
18+
/** @var $entityType Type */
19+
$entityType = $objectManager
20+
->create(Config::class)
21+
->getEntityType('customer');
22+
23+
/** @var $attributeSet Set */
24+
$attributeSet = Bootstrap::getObjectManager()
25+
->create(Set::class);
26+
27+
$select = Bootstrap::getObjectManager()->create(
28+
Attribute::class,
29+
[
30+
'data' => [
31+
'frontend_input' => 'text',
32+
'frontend_label' => ['test_text_attribute'],
33+
'sort_order' => 1,
34+
'backend_type' => 'varchar',
35+
'is_user_defined' => 1,
36+
'is_system' => 0,
37+
'is_used_in_grid' => 1,
38+
'is_required' => '0',
39+
'is_visible' => 1,
40+
'used_in_forms' => [
41+
'customer_address_edit',
42+
'adminhtml_customer_address'
43+
],
44+
'attribute_set_id' => $entityType->getDefaultAttributeSetId(),
45+
'attribute_group_id' => $attributeSet->getDefaultGroupId($entityType->getDefaultAttributeSetId()),
46+
'entity_type_id' => $entityType->getId(),
47+
'default_value' => '',
48+
],
49+
]
50+
);
51+
$select->setAttributeCode('test_text_attribute');
52+
$select->save();
53+
54+
$customer = $objectManager
55+
->create(Customer::class);
56+
$customer->setWebsiteId(1)
57+
->setEntityId(1)
58+
->setEntityTypeId($entityType->getId())
59+
->setAttributeSetId($entityType->getDefaultAttributeSetId())
60+
->setEmail('JohnDoe@mail.com')
61+
->setPassword('password')
62+
->setGroupId(1)
63+
->setStoreId(1)
64+
->setIsActive(1)
65+
->setFirstname('John')
66+
->setLastname('Doe')
67+
->setGender(2)
68+
->setTestTextAttribute('123');
69+
$customer->isObjectNew(true);
70+
// Create address
71+
$address = $objectManager->create(Address::class);
72+
// default_billing and default_shipping information would not be saved, it is needed only for simple check
73+
$address->addData(
74+
[
75+
'firstname' => 'Charles',
76+
'lastname' => 'Alston',
77+
'street' => '3781 Neuport Lane',
78+
'city' => 'Panola',
79+
'country_id' => 'US',
80+
'region_id' => '51',
81+
'postcode' => '30058',
82+
'telephone' => '770-322-3514',
83+
'default_billing' => 1,
84+
'default_shipping' => 1,
85+
]
86+
);
87+
// Assign customer and address
88+
$customer->addAddress($address);
89+
$customer->save();
90+
// Mark last address as default billing and default shipping for current customer
91+
$customer->setDefaultBilling($address->getId());
92+
$customer->setDefaultShipping($address->getId());
93+
$customer->save();
94+
95+
$objectManager->get(Registry::class)->unregister('_fixture/Magento_ImportExport_Customer');
96+
$objectManager->get(Registry::class)->register('_fixture/Magento_ImportExport_Customer', $customer);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
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+
use Magento\Customer\Model\Customer;
9+
use Magento\Framework\Registry;
10+
use Magento\TestFramework\Helper\Bootstrap;
11+
use Magento\Customer\Model\Attribute;
12+
13+
/** @var Registry $registry */
14+
$registry = Bootstrap::getObjectManager()->get(Registry::class);
15+
$registry->unregister('isSecureArea');
16+
$registry->register('isSecureArea', true);
17+
18+
/** @var $attribute Attribute */
19+
$attribute = Bootstrap::getObjectManager()->create(
20+
Attribute::class
21+
);
22+
$attribute->loadByCode('customer', 'test_text_attribute');
23+
$attribute->delete();
24+
25+
/** @var Customer $customer */
26+
$customer = Bootstrap::getObjectManager()
27+
->create(Customer::class);
28+
$customer->setWebsiteId(1);
29+
$customer->loadByEmail('JohnDoe@mail.com');
30+
$customer->delete();
31+
32+
$registry->unregister('isSecureArea');
33+
$registry->register('isSecureArea', false);

0 commit comments

Comments
 (0)