-
Notifications
You must be signed in to change notification settings - Fork 247
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'store-pickup' into MSI-2182-Source-Entity-expansion-wit…
…h-Pickup-Location-attributes
- Loading branch information
Showing
50 changed files
with
1,314 additions
and
34 deletions.
There are no files selected for viewing
59 changes: 59 additions & 0 deletions
59
InventoryInStorePickup/Model/GetIsAnyPickupLocationAvailable.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magento\InventoryInStorePickup\Model; | ||
|
||
use Magento\Framework\Exception\NoSuchEntityException; | ||
use Magento\InventoryInStorePickupApi\Api\GetIsAnyPickupLocationAvailableInterface; | ||
use Magento\InventoryInStorePickupApi\Api\GetPickupLocationsAssignedToStockOrderedByPriorityInterface; | ||
use Magento\InventorySalesApi\Api\Data\SalesChannelInterface; | ||
use Magento\InventorySalesApi\Api\GetStockBySalesChannelInterface; | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
class GetIsAnyPickupLocationAvailable implements GetIsAnyPickupLocationAvailableInterface | ||
{ | ||
/** | ||
* @var GetPickupLocationsAssignedToStockOrderedByPriorityInterface | ||
*/ | ||
private $getPickupLocations; | ||
|
||
/** | ||
* @var GetStockBySalesChannelInterface | ||
*/ | ||
private $getStockBySalesChannel; | ||
|
||
/** | ||
* @param GetPickupLocationsAssignedToStockOrderedByPriorityInterface $getPickupLocations | ||
* @param GetStockBySalesChannelInterface $getStockBySalesChannel | ||
*/ | ||
public function __construct( | ||
GetPickupLocationsAssignedToStockOrderedByPriorityInterface $getPickupLocations, | ||
GetStockBySalesChannelInterface $getStockBySalesChannel | ||
) { | ||
$this->getPickupLocations = $getPickupLocations; | ||
$this->getStockBySalesChannel = $getStockBySalesChannel; | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function execute(SalesChannelInterface $salesChannel): bool | ||
{ | ||
$result = false; | ||
|
||
try { | ||
$stock = $this->getStockBySalesChannel->execute($salesChannel); | ||
$result = count($this->getPickupLocations->execute((int)$stock->getStockId())) > 0; | ||
} catch (NoSuchEntityException $exception) { | ||
return $result; | ||
} | ||
|
||
return $result; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
InventoryInStorePickup/Test/Integration/GetIsAnyPickupLocationAvailableTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magento\InventoryInStorePickup\Test\Integration; | ||
|
||
use Magento\InventoryInStorePickup\Model\GetIsAnyPickupLocationAvailable; | ||
use Magento\InventorySalesApi\Api\Data\SalesChannelInterfaceFactory; | ||
use Magento\InventorySalesApi\Api\Data\SalesChannelInterface; | ||
use Magento\TestFramework\Helper\Bootstrap; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
/** | ||
* Integration tests coverage for @see \Magento\InventoryInStorePickup\Model\GetIsAnyPickupLocationAvailable. | ||
*/ | ||
class GetIsAnyPickupLocationAvailableTest extends TestCase | ||
{ | ||
/** | ||
* @var GetIsAnyPickupLocationAvailable | ||
*/ | ||
private $getIsPickupLocationAvailable; | ||
|
||
/** | ||
* @var SalesChannelInterfaceFactory | ||
*/ | ||
private $salesChannelFactory; | ||
|
||
public function setUp() | ||
{ | ||
$this->getIsPickupLocationAvailable = Bootstrap::getObjectManager()->get(GetIsAnyPickupLocationAvailable::class); | ||
$this->salesChannelFactory = Bootstrap::getObjectManager()->get(SalesChannelInterfaceFactory::class); | ||
} | ||
|
||
/** | ||
* @magentoDataFixture ../../../../app/code/Magento/InventoryApi/Test/_files/sources.php | ||
* @magentoDataFixture ../../../../app/code/Magento/InventoryInStorePickup/Test/_files/source_addresses.php | ||
* @magentoDataFixture ../../../../app/code/Magento/InventoryInStorePickup/Test/_files/source_pickup_location_attributes.php | ||
* @magentoDataFixture ../../../../app/code/Magento/InventoryApi/Test/_files/stocks.php | ||
* @magentoDataFixture ../../../../app/code/Magento/InventoryApi/Test/_files/stock_source_links.php | ||
* @magentoDataFixture ../../../../app/code/Magento/InventorySalesApi/Test/_files/websites_with_stores.php | ||
* @magentoDataFixture ../../../../app/code/Magento/InventorySalesApi/Test/_files/stock_website_sales_channels.php | ||
* | ||
* @magentoDbIsolation disabled | ||
*/ | ||
public function testExecuteWithAvailableLocations() | ||
{ | ||
$salesChannel = $this->salesChannelFactory->create(); | ||
$salesChannel->setType(SalesChannelInterface::TYPE_WEBSITE); | ||
$salesChannel->setCode('eu_website'); | ||
$result = $this->getIsPickupLocationAvailable->execute($salesChannel); | ||
$this->assertTrue($result); | ||
} | ||
|
||
/** | ||
* @magentoDataFixture ../../../../app/code/Magento/InventoryApi/Test/_files/sources.php | ||
* @magentoDataFixture ../../../../app/code/Magento/InventoryInStorePickup/Test/_files/source_addresses.php | ||
* @magentoDataFixture ../../../../app/code/Magento/InventoryApi/Test/_files/stocks.php | ||
* @magentoDataFixture ../../../../app/code/Magento/InventoryApi/Test/_files/stock_source_links.php | ||
* @magentoDataFixture ../../../../app/code/Magento/InventorySalesApi/Test/_files/websites_with_stores.php | ||
* @magentoDataFixture ../../../../app/code/Magento/InventorySalesApi/Test/_files/stock_website_sales_channels.php | ||
* | ||
* @magentoDbIsolation disabled | ||
*/ | ||
public function testExecuteWithoutAvailableLocations() | ||
{ | ||
$salesChannel = $this->salesChannelFactory->create(); | ||
$salesChannel->setType(SalesChannelInterface::TYPE_WEBSITE); | ||
$salesChannel->setCode('eu_website'); | ||
$result = $this->getIsPickupLocationAvailable->execute($salesChannel); | ||
$this->assertFalse($result); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
InventoryInStorePickup/Test/_files/add_products_from_eu_stock_to_cart.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
use Magento\Catalog\Api\ProductRepositoryInterface; | ||
use Magento\Framework\Api\SearchCriteriaBuilder; | ||
use Magento\Quote\Api\CartManagementInterface; | ||
use Magento\Quote\Api\CartRepositoryInterface; | ||
use Magento\TestFramework\Helper\Bootstrap; | ||
|
||
/** @var SearchCriteriaBuilder $searchCriteriaBuilder */ | ||
$searchCriteriaBuilder = Bootstrap::getObjectManager()->get(SearchCriteriaBuilder::class); | ||
/** @var CartRepositoryInterface $cartRepository */ | ||
$cartRepository = Bootstrap::getObjectManager()->get(CartRepositoryInterface::class); | ||
/** @var ProductRepositoryInterface $productRepository */ | ||
$productRepository = Bootstrap::getObjectManager()->get(ProductRepositoryInterface::class); | ||
/** @var CartManagementInterface $cartManagement */ | ||
$cartManagement = Bootstrap::getObjectManager()->get(CartManagementInterface::class); | ||
|
||
$searchCriteria = $searchCriteriaBuilder | ||
->addFilter('reserved_order_id', 'in_store_pickup_test_order') | ||
->create(); | ||
$cart = current($cartRepository->getList($searchCriteria)->getItems()); | ||
|
||
|
||
$itemsToAdd = [ | ||
'SKU-1' => 3.5, | ||
'SKU-2' => 2 | ||
]; | ||
|
||
foreach ($itemsToAdd as $sku => $qty) { | ||
$product = $productRepository->get($sku); | ||
$requestData = [ | ||
'product' => $product->getProductId(), | ||
'qty' => $qty | ||
]; | ||
$request = new \Magento\Framework\DataObject($requestData); | ||
$cart->addProduct($product, $request); | ||
} | ||
|
||
$cart->getShippingAddress()->setCollectShippingRates(true); | ||
$cart->getShippingAddress()->collectShippingRates(); | ||
$cartRepository->save($cart); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.