Skip to content

Commit 62c0d79

Browse files
authored
Merge pull request #562 from adobe-commerce-tier-4/PR_Apr23_doleksandr
[Support Tier-4 odubovyk] 05-20-2025 Regular delivery of bugfixes and improvements
2 parents c7a53b3 + 1d80235 commit 62c0d79

File tree

11 files changed

+371
-8
lines changed

11 files changed

+371
-8
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
/**
4+
* Copyright 2025 Adobe
5+
* All Rights Reserved.
6+
*/
7+
-->
8+
9+
<entities xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
10+
xsi:noNamespaceSchemaLocation="urn:magento:mftf:DataGenerator/etc/dataProfileSchema.xsd">
11+
<entity name="Msi_US_Address_CA_Not_Default_Address" type="address" extends="US_Address_CA">
12+
<data key="default_billing">false</data>
13+
<data key="default_shipping">false</data>
14+
</entity>
15+
</entities>

InventoryAdminUi/Test/Mftf/Data/MsiCustomerData.xml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,18 @@
3434
<data key="website_id">0</data>
3535
<requiredEntity type="address">US_Address_TX</requiredEntity>
3636
</entity>
37+
<entity name="Msi_US_Customer_NY_CA_Addresses" type="customer">
38+
<data key="group_id">1</data>
39+
<data key="default_billing">true</data>
40+
<data key="default_shipping">true</data>
41+
<data key="email" unique="prefix">John.Doe@example.com</data>
42+
<data key="firstname">John</data>
43+
<data key="lastname">Doe</data>
44+
<data key="fullname">John Doe</data>
45+
<data key="password">pwdTest123!</data>
46+
<data key="store_id">0</data>
47+
<data key="website_id">0</data>
48+
<requiredEntity type="address">US_Address_NY</requiredEntity>
49+
<requiredEntity type="address">Msi_US_Address_CA_Not_Default_Address</requiredEntity>
50+
</entity>
3751
</entities>
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?php
2+
/**
3+
* Copyright 2025 Adobe
4+
* All Rights Reserved.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\InventoryInStorePickupFrontend\Model\Ui;
9+
10+
use Magento\Checkout\Model\ConfigProviderInterface;
11+
use Magento\Checkout\Model\Session as CheckoutSession;
12+
use Magento\InventoryInStorePickupShippingApi\Model\IsInStorePickupDeliveryCartInterface;
13+
14+
/**
15+
* Provide "selectedPickupLocationCode" in checkout config.
16+
*
17+
* @SuppressWarnings(PHPMD.CookieAndSessionMisuse)
18+
*/
19+
class SelectedPickupLocationCodeProvider implements ConfigProviderInterface
20+
{
21+
/**
22+
* @param IsInStorePickupDeliveryCartInterface $isInStorePickupDeliveryCart
23+
* @param CheckoutSession $checkoutSession
24+
*/
25+
public function __construct(
26+
private readonly IsInStorePickupDeliveryCartInterface $isInStorePickupDeliveryCart,
27+
private readonly CheckoutSession $checkoutSession
28+
) {
29+
}
30+
31+
/**
32+
* @inheritdoc
33+
*/
34+
public function getConfig()
35+
{
36+
$config = [];
37+
if ($this->isInStorePickupDeliveryCart->execute($this->checkoutSession->getQuote())) {
38+
$pickupLocationCode = $this->checkoutSession->getQuote()
39+
->getShippingAddress()
40+
?->getExtensionAttributes()
41+
?->getPickupLocationCode();
42+
43+
if ($pickupLocationCode) {
44+
$config['selectedPickupLocationCode'] = $pickupLocationCode;
45+
}
46+
}
47+
return $config;
48+
}
49+
}

InventoryInStorePickupFrontend/Test/Mftf/Test/StorefrontGuestPickupInStorePreselectedTest.xml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,5 +146,28 @@
146146
<argument name="customer" value="Simple_US_Customer_NY"/>
147147
<argument name="address" value="US_Address_NY"/>
148148
</actionGroup>
149+
<!--Fill shipping information with Lost Angeles address-->
150+
<actionGroup ref="FillGuestCheckoutShippingAddressWithCountryAndStateActionGroup" stepKey="guestCheckoutFillingWithCAAddress">
151+
<argument name="customer" value="Simple_US_Customer_CA"/>
152+
<argument name="customerAddress" value="US_Address_California"/>
153+
</actionGroup>
154+
<!--Switch to In Pick In Store-->
155+
<actionGroup ref="StorefrontPickInStoreActionGroup" stepKey="pickInStore4"/>
156+
<!--Verify that store is selected-->
157+
<actionGroup ref="StorefrontAssertSelectedStoreActionGroup" stepKey="verifyThatStoreIsSelectedAfterChangingShippingAddressToCA">
158+
<argument name="sourceName" value="$losAngelesSource.source[name]$"/>
159+
</actionGroup>
160+
<!--Navigate to Payments-->
161+
<actionGroup ref="StorefrontPickInStoreNavigateToPaymentActionGroup" stepKey="navigateToPaymentStep"/>
162+
<!--Go to home page -->
163+
<actionGroup ref="StorefrontOpenHomePageActionGroup" stepKey="goToHomePage"/>
164+
<!--Clear local storage to remove checkout data from browser-->
165+
<executeJS function="window.localStorage.clear();" stepKey="clearLocalStorage"/>
166+
<!--Navigate to checkout-->
167+
<actionGroup ref="GoToCheckoutFromMinicartActionGroup" stepKey="goToCheckoutFromMinicart2"/>
168+
<!--Verify that store is selected-->
169+
<actionGroup ref="StorefrontAssertSelectedStoreActionGroup" stepKey="verifyThatStoreIsSelectedAfterVisitingHomePage">
170+
<argument name="sourceName" value="$losAngelesSource.source[name]$"/>
171+
</actionGroup>
149172
</test>
150173
</tests>

InventoryInStorePickupFrontend/Test/Mftf/Test/StorefrontLoggedInCustomerPickupInStorePreselectedTest.xml

Lines changed: 48 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
<requiredEntity createDataKey="stock"/>
4545
<requiredEntity createDataKey="austinSource"/>
4646
</createData>
47-
<createData entity="Simple_US_Customer_CA_NY_Addresses" stepKey="customer"/>
47+
<createData entity="Msi_US_Customer_NY_CA_Addresses" stepKey="customer"/>
4848
<createData entity="_defaultCategory" stepKey="category"/>
4949
<createData entity="SimpleProduct" stepKey="product">
5050
<requiredEntity createDataKey="category"/>
@@ -95,8 +95,17 @@
9595
</actionGroup>
9696
<!--Navigate to checkout-->
9797
<actionGroup ref="GoToCheckoutFromMinicartActionGroup" stepKey="goToCheckoutFromMinicart"/>
98-
<!-- Verify that selected address is Lost Angeles address -->
99-
<actionGroup ref="CheckSelectedShippingAddressInCheckoutActionGroup" stepKey="assertSelectedShippingAddressIsLA">
98+
<!-- Verify that selected address is NY address -->
99+
<comment userInput="Comment is added to preserve the step key for backward compatibility" stepKey="assertSelectedShippingAddressIsLA"/>
100+
<actionGroup ref="CheckSelectedShippingAddressInCheckoutActionGroup" stepKey="assertSelectedShippingAddressIsNYAsDefaultAddress">
101+
<argument name="customerVar" value="$customer$" />
102+
<argument name="customerAddressVar" value="US_Address_NY" />
103+
</actionGroup>
104+
<!--Select CA address-->
105+
<waitForElementVisible selector="{{CheckoutShippingSection.shipHereButton(US_Address_CA.postcode)}}" stepKey="waitForShipHereVisibleCA1"/>
106+
<click selector="{{CheckoutShippingSection.shipHereButton(US_Address_CA.postcode)}}" stepKey="clickShipHereCA1"/>
107+
<!--Verify that selected address is CA address-->
108+
<actionGroup ref="CheckSelectedShippingAddressInCheckoutActionGroup" stepKey="assertSelectedShippingAddressIsCA1">
100109
<argument name="customerVar" value="$customer$" />
101110
<argument name="customerAddressVar" value="US_Address_CA" />
102111
</actionGroup>
@@ -117,13 +126,18 @@
117126
</actionGroup>
118127
<!--Click 'Shipping'-->
119128
<actionGroup ref="StorefrontSelectShippingActionGroup" stepKey="switchToShipping"/>
120-
<!--Verify that selected address is Lost Angeles address-->
129+
<!--Verify that selected address is CA address-->
121130
<actionGroup ref="CheckSelectedShippingAddressInCheckoutActionGroup" stepKey="assertSelectedShippingAddressIsLAAfterPageRefresh">
122131
<argument name="customerVar" value="$customer$" />
123132
<argument name="customerAddressVar" value="US_Address_CA" />
124133
</actionGroup>
125134
<!--Refresh Page-->
126135
<actionGroup ref="ReloadPageActionGroup" stepKey="refreshPage2"/>
136+
<!--Verify that selected address is CA address-->
137+
<actionGroup ref="CheckSelectedShippingAddressInCheckoutActionGroup" stepKey="assertSelectedShippingAddressIsCAAfterPageRefresh2">
138+
<argument name="customerVar" value="$customer$" />
139+
<argument name="customerAddressVar" value="US_Address_CA" />
140+
</actionGroup>
127141
<!--Switch to In Pick In Store-->
128142
<actionGroup ref="StorefrontPickInStoreActionGroup" stepKey="pickInStore2"/>
129143
<!--Verify that store is pre-selected-->
@@ -133,12 +147,12 @@
133147
<!--Click 'Shipping'-->
134148
<actionGroup ref="StorefrontSelectShippingActionGroup" stepKey="switchToShipping2"/>
135149
<!--Select NY address-->
136-
<waitForElementVisible selector="{{CheckoutShippingMethodsSection.shipHereButton}}" stepKey="waitForShipHereVisible"/>
137-
<click selector="{{CheckoutShippingMethodsSection.shipHereButton}}" stepKey="clickShipHere"/>
150+
<waitForElementVisible selector="{{CheckoutShippingSection.shipHereButton(US_Address_NY.postcode)}}" stepKey="waitForShipHereVisible"/>
151+
<click selector="{{CheckoutShippingSection.shipHereButton(US_Address_NY.postcode)}}" stepKey="clickShipHere"/>
138152
<!-- Verify that selected address is NY address -->
139153
<actionGroup ref="CheckSelectedShippingAddressInCheckoutActionGroup" stepKey="assertSelectedShippingAddressIsNY">
140154
<argument name="customerVar" value="$customer$" />
141-
<argument name="customerAddressVar" value="US_Address_NY_Not_Default_Address" />
155+
<argument name="customerAddressVar" value="US_Address_NY" />
142156
</actionGroup>
143157
<!--Switch to In Pick In Store-->
144158
<actionGroup ref="StorefrontPickInStoreActionGroup" stepKey="pickInStore3"/>
@@ -153,7 +167,33 @@
153167
<!-- Verify that selected address is NY address -->
154168
<actionGroup ref="CheckSelectedShippingAddressInCheckoutActionGroup" stepKey="assertSelectedShippingAddressIsNYAfterPageRefresh">
155169
<argument name="customerVar" value="$customer$" />
156-
<argument name="customerAddressVar" value="US_Address_NY_Not_Default_Address" />
170+
<argument name="customerAddressVar" value="US_Address_NY" />
171+
</actionGroup>
172+
<!--Select CA address-->
173+
<waitForElementVisible selector="{{CheckoutShippingSection.shipHereButton(US_Address_CA.postcode)}}" stepKey="waitForShipHereVisibleCA2"/>
174+
<click selector="{{CheckoutShippingSection.shipHereButton(US_Address_CA.postcode)}}" stepKey="clickShipHereCA2"/>
175+
<!--Verify that selected address is CA address-->
176+
<actionGroup ref="CheckSelectedShippingAddressInCheckoutActionGroup" stepKey="assertSelectedShippingAddressIsCA2">
177+
<argument name="customerVar" value="$customer$" />
178+
<argument name="customerAddressVar" value="US_Address_CA" />
179+
</actionGroup>
180+
<!--Switch to In Pick In Store-->
181+
<actionGroup ref="StorefrontPickInStoreActionGroup" stepKey="pickInStore4"/>
182+
<!--Verify that store is selected-->
183+
<actionGroup ref="StorefrontAssertSelectedStoreActionGroup" stepKey="verifyThatStoreIsSelectedAfterChangingShippingAddressToCA">
184+
<argument name="sourceName" value="$losAngelesSource.source[name]$"/>
185+
</actionGroup>
186+
<!--Navigate to Payments-->
187+
<actionGroup ref="StorefrontPickInStoreNavigateToPaymentActionGroup" stepKey="navigateToPaymentStep"/>
188+
<!--Go to home page -->
189+
<actionGroup ref="StorefrontOpenHomePageActionGroup" stepKey="goToHomePage"/>
190+
<!--Clear local storage to remove checkout data from browser-->
191+
<executeJS function="window.localStorage.clear();" stepKey="clearLocalStorage"/>
192+
<!--Navigate to checkout-->
193+
<actionGroup ref="GoToCheckoutFromMinicartActionGroup" stepKey="goToCheckoutFromMinicart2"/>
194+
<!--Verify that store is selected-->
195+
<actionGroup ref="StorefrontAssertSelectedStoreActionGroup" stepKey="verifyThatStoreIsSelectedAfterVisitingHomePage">
196+
<argument name="sourceName" value="$losAngelesSource.source[name]$"/>
157197
</actionGroup>
158198
</test>
159199
</tests>

InventoryInStorePickupFrontend/etc/frontend/di.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
<argument name="configProviders" xsi:type="array">
1212
<item name="website_code_config_provider" xsi:type="object">Magento\InventoryInStorePickupFrontend\Model\Ui\WebsiteCodeConfigProvider</item>
1313
<item name="in_store_pickup_checkout_config_provider" xsi:type="object">Magento\InventoryInStorePickupFrontend\Model\Ui\DelimiterConfigProvider</item>
14+
<item name="inventory_in_store_pickup_frontend_selected_pickup_location_code_checkout_config_provider" xsi:type="object">Magento\InventoryInStorePickupFrontend\Model\Ui\SelectedPickupLocationCodeProvider</item>
1415
</argument>
1516
</arguments>
1617
</type>

InventoryInStorePickupFrontend/view/frontend/web/js/view/store-pickup.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,11 @@ define([
267267
selectedSourceCode = this.getPickupLocationCodeFromAddress(selectedPickupAddress);
268268
}
269269

270+
if (!selectedSourceCode) {
271+
// Get the source code from the checkout config
272+
selectedSourceCode = window.checkoutConfig.selectedPickupLocationCode;
273+
}
274+
270275
if (selectedSourceCode) {
271276
pickupLocationsService
272277
.getLocation(selectedSourceCode)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
<?php
2+
/**
3+
* Copyright 2025 Adobe
4+
* All Rights Reserved.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\InventoryInStorePickupQuote\Plugin\Quote;
9+
10+
use Magento\Customer\Api\Data\CustomerInterface;
11+
use Magento\Framework\Api\DataObjectHelper;
12+
use Magento\Framework\Exception\NoSuchEntityException;
13+
use Magento\InventoryInStorePickup\Model\ExtractPickupLocationAddressData;
14+
use Magento\InventoryInStorePickupApi\Model\GetPickupLocationInterface;
15+
use Magento\InventoryInStorePickupQuote\Model\IsPickupLocationShippingAddress;
16+
use Magento\InventoryInStorePickupQuote\Model\GetShippingAddressData;
17+
use Magento\InventoryInStorePickupQuote\Model\GetWebsiteCodeByStoreId;
18+
use Magento\InventoryInStorePickupShippingApi\Model\IsInStorePickupDeliveryCartInterface;
19+
use Magento\InventorySalesApi\Api\Data\SalesChannelInterface;
20+
use Magento\Quote\Api\Data\AddressInterface;
21+
use Magento\Quote\Model\Quote;
22+
use Magento\Quote\Model\Quote\Address;
23+
24+
/**
25+
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
26+
*/
27+
class ReplaceShippingAddressWithPickupLocationAddressOnAssignCustomer
28+
{
29+
/**
30+
* @param IsInStorePickupDeliveryCartInterface $isInStorePickupDeliveryCart
31+
* @param GetPickupLocationInterface $getPickupLocation
32+
* @param ExtractPickupLocationAddressData $extractPickupLocationShippingAddressData
33+
* @param DataObjectHelper $dataObjectHelper
34+
* @param GetShippingAddressData $getShippingAddressData
35+
* @param IsPickupLocationShippingAddress $isPickupLocationShippingAddress
36+
* @param GetWebsiteCodeByStoreId $getWebsiteCodeByStoreId
37+
*/
38+
public function __construct(
39+
private readonly IsInStorePickupDeliveryCartInterface $isInStorePickupDeliveryCart,
40+
private readonly GetPickupLocationInterface $getPickupLocation,
41+
private readonly ExtractPickupLocationAddressData $extractPickupLocationShippingAddressData,
42+
private readonly DataObjectHelper $dataObjectHelper,
43+
private readonly GetShippingAddressData $getShippingAddressData,
44+
private readonly IsPickupLocationShippingAddress $isPickupLocationShippingAddress,
45+
private readonly GetWebsiteCodeByStoreId $getWebsiteCodeByStoreId
46+
) {
47+
}
48+
49+
/**
50+
* Replace Shipping Address with Pickup Location Shipping Address for Quote when customer is assigned to Quote.
51+
*
52+
* The original method overrides the shipping address with customer default shipping address which results in
53+
* removing the pickup location address.
54+
*
55+
* @param Quote $quote
56+
* @param CustomerInterface $customer
57+
* @param Address|null $billingAddress
58+
* @param Address|null $shippingAddress
59+
* @return array
60+
*/
61+
public function beforeAssignCustomerWithAddressChange(
62+
Quote $quote,
63+
CustomerInterface $customer,
64+
?Address $billingAddress = null,
65+
?Address $shippingAddress = null
66+
): array {
67+
if (null === $shippingAddress
68+
&& $this->isInStorePickupDeliveryCart->execute($quote)
69+
&& $quote->getShippingAddress()?->getExtensionAttributes()?->getPickupLocationCode()
70+
) {
71+
try {
72+
$location = $this->getPickupLocation->execute(
73+
(string) $quote->getShippingAddress()->getExtensionAttributes()->getPickupLocationCode(),
74+
SalesChannelInterface::TYPE_WEBSITE,
75+
$this->getWebsiteCodeByStoreId->execute((int)$quote->getStoreId())
76+
);
77+
} catch (NoSuchEntityException $e) { // phpcs:ignore Magento2.CodeAnalysis.EmptyBlock.DetectedCatch
78+
// Pickup location is not found or is invalid for this store
79+
}
80+
if (isset($location)) {
81+
$shippingAddress = $quote->getShippingAddress();
82+
if (!$this->isPickupLocationShippingAddress->execute($location, $shippingAddress)) {
83+
$pickupLocationAddressData = $this->getShippingAddressData->execute()
84+
+ $this->extractPickupLocationShippingAddressData->execute($location);
85+
86+
$this->dataObjectHelper->populateWithArray(
87+
$shippingAddress,
88+
$pickupLocationAddressData,
89+
AddressInterface::class
90+
);
91+
}
92+
}
93+
}
94+
return [$customer, $billingAddress, $shippingAddress];
95+
}
96+
}

0 commit comments

Comments
 (0)