Skip to content

Commit

Permalink
Merge branch 'store-pickup' into MSI-2182-Source-Entity-expansion-wit…
Browse files Browse the repository at this point in the history
…h-Pickup-Location-attributes
  • Loading branch information
ishakhsuvarov authored May 30, 2019
2 parents 9dd0a25 + 8381ced commit 2488b17
Show file tree
Hide file tree
Showing 50 changed files with 1,314 additions and 34 deletions.
59 changes: 59 additions & 0 deletions InventoryInStorePickup/Model/GetIsAnyPickupLocationAvailable.php
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;
}
}
2 changes: 1 addition & 1 deletion InventoryInStorePickup/Model/PickupLocation.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
use Magento\InventoryInStorePickupApi\Api\Data\PickupLocationInterface;

/**
* @inheritdoc
* {@inheritdoc}
* @codeCoverageIgnore
*/
class PickupLocation implements PickupLocationInterface
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,20 @@ protected function setUp()
/**
* @magentoDataFixture ../../../../app/code/Magento/InventoryApi/Test/_files/products.php
* @magentoDataFixture ../../../../app/code/Magento/InventoryApi/Test/_files/sources.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
* @magentoDataFixture ../../../../app/code/Magento/InventoryApi/Test/_files/source_items.php
* @magentoDataFixture ../../../../app/code/Magento/InventoryApi/Test/_files/source_items_eu_stock_only.php
* @magentoDataFixture ../../../../app/code/Magento/InventoryIndexer/Test/_files/reindex_inventory.php
* @magentoDataFixture ../../../../app/code/Magento/InventoryInStorePickup/Test/_files/create_in_store_pickup_quote_on_eu_website.php
* @magentoDataFixture ../../../../app/code/Magento/InventoryInStorePickup/Test/_files/add_products_from_eu_stock_to_cart.php
* @magentoDataFixture ../../../../app/code/Magento/InventoryInStorePickup/Test/_files/place_order.php
*
* @magentoConfigFixture store_for_eu_website_store carriers/in_store/active 1
* @magentoConfigFixture store_for_eu_website_store carriers/in_store/price 5.95
*
* @magentoDbIsolation disabled
*/
public function testPickupLocationSaveWithOrder()
Expand Down
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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,17 @@ protected function setUp()
* @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
* @magentoDataFixture ../../../../app/code/Magento/InventoryApi/Test/_files/source_items.php
* @magentoDataFixture ../../../../app/code/Magento/InventoryInStorePickup/Test/_files/source_items.php
* @magentoDataFixture ../../../../app/code/Magento/InventoryIndexer/Test/_files/reindex_inventory.php
* @magentoDataFixture ../../../../app/code/Magento/InventoryInStorePickup/Test/_files/source_pickup_location_attributes.php
* @magentoDataFixture ../../../../app/code/Magento/InventoryInStorePickup/Test/_files/create_in_store_pickup_quote_on_eu_website.php
* @magentoDataFixture ../../../../app/code/Magento/InventoryInStorePickup/Test/_files/add_products_from_eu_stock_to_cart.php
* @magentoDataFixture ../../../../app/code/Magento/InventoryInStorePickup/Test/_files/place_order.php
*
* @magentoConfigFixture store_for_eu_website_store carriers/in_store/active 1
*
* @magentoDbIsolation disabled
*
* @dataProvider dataProvider
*
* @param string $sourceId
Expand Down Expand Up @@ -118,8 +123,8 @@ private function setPickupLocation(OrderInterface $createdOrder, string $sourceI
public function dataProvider(): array
{
return [
['eu-1', true],
['eu-2', false],
['eu-1', false],
['eu-2', true],
['eu-3', false],
['eu-disabled', false],
['us-1', false],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,15 @@ protected function setUp()
* @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
* @magentoDataFixture ../../../../app/code/Magento/InventoryApi/Test/_files/source_items.php
* @magentoDataFixture ../../../../app/code/Magento/InventoryInStorePickup/Test/_files/source_items.php
* @magentoDataFixture ../../../../app/code/Magento/InventoryIndexer/Test/_files/reindex_inventory.php
* @magentoDataFixture ../../../../app/code/Magento/InventoryInStorePickup/Test/_files/source_pickup_location_attributes.php
* @magentoDataFixture ../../../../app/code/Magento/InventoryInStorePickup/Test/_files/create_in_store_pickup_quote_on_eu_website.php
* @magentoDataFixture ../../../../app/code/Magento/InventoryInStorePickup/Test/_files/add_products_from_eu_stock_to_cart.php
* @magentoDataFixture ../../../../app/code/Magento/InventoryInStorePickup/Test/_files/place_order.php
*
* @magentoConfigFixture store_for_eu_website_store carriers/in_store/active 1
*
* @magentoDbIsolation disabled
* @dataProvider dataProvider
*
Expand Down Expand Up @@ -167,8 +171,8 @@ private function setPickupLocation(OrderInterface $createdOrder, string $sourceI
public function dataProvider(): array
{
return [
['eu-1', null],
['eu-2', 'The order is not ready for pickup'],
['eu-1', 'The order is not ready for pickup'],
['eu-2', null],
['eu-3', 'The order is not ready for pickup'],
['eu-disabled', 'The order is not ready for pickup'],
['us-1', 'The order is not ready for pickup'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,21 +74,27 @@ public function testWithoutStorePickup()
* @magentoDataFixture ../../../../app/code/Magento/InventorySalesApi/Test/_files/stock_website_sales_channels.php
* @magentoDataFixture ../../../../app/code/Magento/InventoryInStorePickup/Test/_files/source_items.php
* @magentoDataFixture ../../../../app/code/Magento/InventoryIndexer/Test/_files/reindex_inventory.php
* @magentoDataFixture ../../../../app/code/Magento/InventoryInStorePickup/Test/_files/source_pickup_location_attributes.php
* @magentoDataFixture ../../../../app/code/Magento/InventoryInStorePickup/Test/_files/create_in_store_pickup_quote_on_eu_website.php
* @magentoDataFixture ../../../../app/code/Magento/InventoryInStorePickup/Test/_files/add_products_from_eu_stock_to_cart.php
* @magentoDataFixture ../../../../app/code/Magento/InventoryInStorePickup/Test/_files/place_order.php
* @magentoDataFixture ../../../../app/code/Magento/InventoryInStorePickup/Test/_files/set_order_pickup_location.php
* @magentoDataFixture ../../../../app/code/Magento/InventoryInStorePickup/Test/_files/create_multiple_quotes_on_eu_website.php
* @magentoDataFixture ../../../../app/code/Magento/InventoryInStorePickup/Test/_files/place_multiple_orders_on_eu_website.php
* @magentoDataFixture ../../../../app/code/Magento/InventoryInStorePickup/Test/_files/mark_sources_as_pickup_location.php
* @dataProvider SingleStorePickupOrderProvider
*
* @magentoConfigFixture store_for_eu_website_store carriers/in_store/active 1
* @magentoConfigFixture store_for_eu_website_store carriers/flatrate/active 1
*
* @magentoDbIsolation disabled
*
* @dataProvider SingleStorePickupOrderProvider
*
* @param string $sourceCode
* @param string $sku
* @param float $qtyExpected
*
* @throws
* @throws \Magento\Framework\Exception\NoSuchEntityException
*/
public function testSingleStorePickupOrder(string $sourceCode, string $sku, float $qtyExpected)
{
Expand All @@ -105,17 +111,23 @@ public function testSingleStorePickupOrder(string $sourceCode, string $sku, floa
* @magentoDataFixture ../../../../app/code/Magento/InventorySalesApi/Test/_files/stock_website_sales_channels.php
* @magentoDataFixture ../../../../app/code/Magento/InventoryInStorePickup/Test/_files/source_items.php
* @magentoDataFixture ../../../../app/code/Magento/InventoryIndexer/Test/_files/reindex_inventory.php
* @magentoDataFixture ../../../../app/code/Magento/InventoryInStorePickup/Test/_files/source_pickup_location_attributes.php
* @magentoDataFixture ../../../../app/code/Magento/InventoryInStorePickup/Test/_files/create_in_store_pickup_quote_on_eu_website.php
* @magentoDataFixture ../../../../app/code/Magento/InventoryInStorePickup/Test/_files/add_products_from_eu_stock_to_cart.php
* @magentoDataFixture ../../../../app/code/Magento/InventoryInStorePickup/Test/_files/place_order.php
* @magentoDataFixture ../../../../app/code/Magento/InventoryInStorePickup/Test/_files/set_order_pickup_location.php
* @magentoDataFixture ../../../../app/code/Magento/InventoryInStorePickup/Test/_files/create_multiple_quotes_on_eu_website.php
* @magentoDataFixture ../../../../app/code/Magento/InventoryInStorePickup/Test/_files/place_multiple_orders_on_eu_website.php
* @magentoDataFixture ../../../../app/code/Magento/InventoryInStorePickup/Test/_files/set_orders_pickup_location.php
* @magentoDataFixture ../../../../app/code/Magento/InventoryInStorePickup/Test/_files/mark_sources_as_pickup_location.php
* @dataProvider MultipleStorePickupOrdersProvider
*
* @magentoConfigFixture store_for_eu_website_store carriers/in_store/active 1
* @magentoConfigFixture store_for_eu_website_store carriers/flatrate/active 1
*
* @magentoDbIsolation disabled
*
* @dataProvider MultipleStorePickupOrdersProvider
*
* @param string $sourceCode
* @param string $sku
* @param float $qtyExpected
Expand Down Expand Up @@ -156,7 +168,7 @@ public function SingleStorePickupOrderProvider(): array
{
return [
['eu-1', 'SKU-1', 2.0], //3.5 reserved
['eu-2', 'SKU-1', 3.0],
['eu-2', 'SKU-1', 3.5],
['eu-3', 'SKU-1', 10.0],
['us-1', 'SKU-2', 5.0],
['eu-2', 'SKU-3', 6.0],
Expand All @@ -172,7 +184,7 @@ public function MultipleStorePickupOrdersProvider(): array
{
return [
['eu-1', 'SKU-1', 1.0], //3.5 + 1.0 reserved
['eu-2', 'SKU-1', 3.0],
['eu-2', 'SKU-1', 3.5],
['eu-2', 'SKU-2', 2.0], // 1.0 reserved
['eu-3', 'SKU-1', 10.0],
['us-1', 'SKU-2', 5.0],
Expand Down
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);
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/
declare(strict_types=1);

use Magento\InventoryInStorePickup\Model\Carrier\InStorePickup;
use Magento\Quote\Api\CartManagementInterface;
use Magento\Quote\Api\CartRepositoryInterface;
use Magento\Quote\Api\Data\AddressInterface;
Expand All @@ -28,6 +29,7 @@
$cart = $cartRepository->get($cartId);
$cart->setCustomerEmail('admin@example.com');
$cart->setCustomerIsGuest(true);

$store = $storeRepository->get('store_for_eu_website');
$cart->setStoreId($store->getId());
$storeManager->setCurrentStore($store->getCode());
Expand All @@ -52,8 +54,8 @@
$cart->setBillingAddress($address);
$cart->setShippingAddress($address);
$cart->getPayment()->setMethod('checkmo');
/** Will be replaced with 'In Store Pickup' delivery method */
$cart->getShippingAddress()->setShippingMethod('flatrate_flatrate');

$cart->getShippingAddress()->setShippingMethod('in_store_pickup');
$cart->getShippingAddress()->setCollectShippingRates(true);
$cart->getShippingAddress()->collectShippingRates();
$cartRepository->save($cart);
11 changes: 0 additions & 11 deletions InventoryInStorePickup/Test/_files/place_order.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
$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);

Expand All @@ -25,13 +23,4 @@
->create();
$cart = current($cartRepository->getList($searchCriteria)->getItems());

$product = $productRepository->get('SKU-1');
$requestData = [
'product' => $product->getProductId(),
'qty' => 3.5
];
$request = new \Magento\Framework\DataObject($requestData);
$cart->addProduct($product, $request);

$cartRepository->save($cart);
$cartManagement->placeOrder($cart->getId());
Loading

0 comments on commit 2488b17

Please sign in to comment.