Skip to content

Commit 9f3e63d

Browse files
authored
Merge pull request #508 from adobe-commerce-tier-4/PR-10-04-24
[Support Tier-4 horytsky] 10-04-2024 Regular delivery of bugfixes and improvements
2 parents 8210705 + 2f12fe6 commit 9f3e63d

File tree

8 files changed

+140
-5
lines changed

8 files changed

+140
-5
lines changed
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
<?php
2+
/**
3+
* Copyright 2024 Adobe
4+
* All Rights Reserved.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\InventoryInStorePickupSales\Model\ResourceModel\SourceSelection;
9+
10+
use Magento\Framework\App\ResourceConnection;
11+
use Magento\Sales\Api\Data\OrderInterface;
12+
use Magento\InventoryInStorePickupApi\Api\Data\PickupLocationInterface;
13+
14+
/**
15+
* Get list of orders based on pickup location code
16+
*/
17+
class GetActiveStorePickupOrdersBySource
18+
{
19+
private const ORDER_ID = 'order_id';
20+
21+
/**
22+
* @var ResourceConnection
23+
*/
24+
private $connection;
25+
26+
/**
27+
* @var array
28+
*/
29+
private $statesToFilter;
30+
31+
/**
32+
* @param ResourceConnection $connection
33+
* @param array $statesToFilter
34+
*/
35+
public function __construct(
36+
ResourceConnection $connection,
37+
array $statesToFilter = []
38+
) {
39+
$this->connection = $connection;
40+
$this->statesToFilter = $statesToFilter;
41+
}
42+
43+
/**
44+
* Gets list of orders ids placed by store pickup which are not complete yet.
45+
*
46+
* @param string $pickupLocationCode
47+
* @return array
48+
*/
49+
public function execute(string $pickupLocationCode): array
50+
{
51+
$connection = $this->connection->getConnection('sales');
52+
$table1 = $this->connection->getTableName('sales_order', 'sales');
53+
$table2 = $this->connection->getTableName('inventory_pickup_location_order', 'sales');
54+
$select = $connection->select()
55+
->from($table1, 'entity_id')
56+
->joinLeft($table2, 'sales_order.entity_id = ' . self::ORDER_ID)
57+
->where(
58+
'inventory_pickup_location_order.' . PickupLocationInterface::PICKUP_LOCATION_CODE . '= ?',
59+
$pickupLocationCode
60+
)
61+
->where(OrderInterface::STATE . ' NOT IN (?)', $this->statesToFilter);
62+
63+
return $connection->fetchAll($select);
64+
}
65+
}

InventoryInStorePickupSales/Model/SourceSelection/GetActiveStorePickupOrdersBySource.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616

1717
/**
1818
* Gets list of orders placed by store pickup which are not complete yet
19+
*
20+
* @deprecated
21+
* @see Magento\InventoryInStorePickupSales\Model\ResourceModel\SourceSelection\GetActiveStorePickupOrdersBySource
1922
*/
2023
class GetActiveStorePickupOrdersBySource
2124
{

InventoryInStorePickupSales/Model/SourceSelection/GetOrderItemsByOrdersListAndSku.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public function __construct(
4646
/**
4747
* Get order items by the orders list provided and a certain order item`s SKU.
4848
*
49-
* @param OrderInterface[] $orders
49+
* @param array $orders
5050
* @param string $sku
5151
* @return OrderItemSearchResultInterface
5252
*/
@@ -58,8 +58,8 @@ public function execute(array $orders, string $sku): OrderItemSearchResultInterf
5858
implode(
5959
',',
6060
array_map(
61-
function (OrderInterface $order) {
62-
return $order->getEntityId();
61+
function (array $row) {
62+
return $row['entity_id'];
6363
},
6464
$orders
6565
)

InventoryInStorePickupSales/Model/SourceSelection/GetSourceItemQtyAvailableService.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use Magento\InventoryApi\Api\Data\SourceItemInterface;
1313
use Magento\InventoryApi\Api\SourceRepositoryInterface;
1414
use Magento\InventorySourceSelectionApi\Model\GetSourceItemQtyAvailableInterface;
15+
use Magento\InventoryInStorePickupSales\Model\ResourceModel\SourceSelection\GetActiveStorePickupOrdersBySource;
1516
use Magento\Sales\Api\Data\OrderInterface;
1617
use Magento\Sales\Api\Data\OrderItemInterface;
1718

@@ -102,8 +103,7 @@ private function getStorePickupOrdersBySourceItem(SourceItemInterface $sourceIte
102103

103104
if ($source->getExtensionAttributes() && $source->getExtensionAttributes()->getIsPickupLocationActive()) {
104105
return $this->getSourceActiveStorePickupOrders
105-
->execute($source->getSourceCode())
106-
->getItems();
106+
->execute($source->getSourceCode());
107107
}
108108

109109
return [];
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<?php
2+
/**
3+
* Copyright 2024 Adobe
4+
* All Rights Reserved.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\InventoryInStorePickupSales\Test\Integration\SourceSelection;
9+
10+
use Magento\InventoryInStorePickupSales\Model\ResourceModel\SourceSelection\GetActiveStorePickupOrdersBySource;
11+
use Magento\TestFramework\Helper\Bootstrap;
12+
use PHPUnit\Framework\TestCase;
13+
14+
/**
15+
* @inheritdoc
16+
*/
17+
class GetActiveStorePickupOrdersBySourceTest extends TestCase
18+
{
19+
/**
20+
* @var GetActiveStorePickupOrdersBySource
21+
*/
22+
private $getActiveStorePickupOrdersBySource;
23+
24+
protected function setUp(): void
25+
{
26+
$om = Bootstrap::getObjectManager();
27+
$this->getActiveStorePickupOrdersBySource = $om->get(GetActiveStorePickupOrdersBySource::class);
28+
}
29+
30+
/**
31+
* @magentoDataFixture Magento_InventoryApi::Test/_files/products.php
32+
* @magentoDataFixture Magento_InventoryApi::Test/_files/sources.php
33+
* @magentoDataFixture Magento_InventoryApi::Test/_files/stocks.php
34+
* @magentoDataFixture Magento_InventoryApi::Test/_files/stock_source_links.php
35+
* @magentoDataFixture Magento_InventorySalesApi::Test/_files/websites_with_stores.php
36+
* @magentoDataFixture Magento_InventorySalesApi::Test/_files/stock_website_sales_channels.php
37+
* @magentoDataFixture Magento_InventoryInStorePickupApi::Test/_files/source_items.php
38+
* @magentoDataFixture Magento_InventoryIndexer::Test/_files/reindex_inventory.php
39+
* @magentoDataFixture Magento_InventoryInStorePickupApi::Test/_files/source_addresses.php
40+
* @magentoDataFixture Magento_InventoryInStorePickupApi::Test/_files/source_pickup_location_attributes.php
41+
* @magentoDataFixture Magento_InventoryInStorePickupSalesApi::Test/_files/create_in_store_pickup_quote_on_eu_website_guest.php
42+
* @magentoDataFixture Magento_InventoryInStorePickupSalesApi::Test/_files/place_order.php
43+
*
44+
* @magentoConfigFixture store_for_eu_website_store carriers/instore/active 1
45+
*
46+
* @magentoDbIsolation disabled
47+
*/
48+
public function testExecute() : void
49+
{
50+
$code = 'eu-1';
51+
$result = $this->getActiveStorePickupOrdersBySource->execute($code);
52+
$this->assertArrayHasKey('entity_id', $result[0]);
53+
$this->assertArrayHasKey('pickup_location_code', $result[0]);
54+
$this->assertEquals($code, $result[0]['pickup_location_code']);
55+
}
56+
}

InventoryInStorePickupSales/etc/di.xml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,15 @@
2626
</argument>
2727
</arguments>
2828
</type>
29+
<type name="Magento\InventoryInStorePickupSales\Model\ResourceModel\SourceSelection\GetActiveStorePickupOrdersBySource">
30+
<arguments>
31+
<argument name="statesToFilter" xsi:type="array">
32+
<item xsi:type="const" name="complete">Magento\Sales\Model\Order::STATE_COMPLETE</item>
33+
<item xsi:type="const" name="closed">Magento\Sales\Model\Order::STATE_CLOSED</item>
34+
<item xsi:type="const" name="canceled">Magento\Sales\Model\Order::STATE_CANCELED</item>
35+
</argument>
36+
</arguments>
37+
</type>
2938
<preference for="Magento\InventorySourceSelectionApi\Model\GetSourceItemQtyAvailableInterface" type="Magento\InventoryInStorePickupSales\Model\SourceSelection\GetSourceItemQtyAvailableService"/>
3039
<preference for="Magento\InventoryInStorePickupSalesApi\Model\IsStorePickupOrderInterface" type="Magento\InventoryInStorePickupSales\Model\IsStorePickupOrder"/>
3140
<type name="Magento\InventoryInStorePickupSales\Observer\UpdateOrderGrid">

InventoryProductAlert/Test/_files/product_alert_customer.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,5 @@
1717
$stock->setCustomerId(1)
1818
->setProductId($product->getId())
1919
->setWebsiteId(1)
20+
->setStoreId(1)
2021
->save();

InventoryProductAlert/Test/_files/product_alert_eu_website_customer.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,5 @@
2121
$stock->setCustomerId(2)
2222
->setProductId($product->getId())
2323
->setWebsiteId($website->getId())
24+
->setStoreId($website->getDefaultStore()->getId())
2425
->save();

0 commit comments

Comments
 (0)