Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MSI-2826-Hide-store-pickup-during-order-submissions-if-one-of-the-products-is-not-available-for-pickup. #2839

Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
8e5937b
MSI-2826-Hide-store-pickup-during-order-submissions-if-one-of-the-pro…
Feb 22, 2020
91944a1
MSI-2826-Hide-store-pickup-during-order-submissions-if-one-of-the-pro…
Feb 22, 2020
f2629b9
MSI-2826-Hide-store-pickup-during-order-submissions-if-one-of-the-pro…
Feb 23, 2020
3ea65f6
MSI-2826-Hide-store-pickup-during-order-submissions-if-one-of-the-pro…
Feb 26, 2020
9eeff2d
Merge branch '1.2-develop' into MSI-2826-Hide-store-pickup-during-ord…
swnsma Feb 26, 2020
f6fd5cd
MSI-2826-Hide-store-pickup-during-order-submissions-if-one-of-the-pro…
Mar 2, 2020
b82f853
Merge branch 'MSI-2826-Hide-store-pickup-during-order-submissions-if-…
Mar 2, 2020
ae23a8d
Merge branch '1.2-develop' into MSI-2826-Hide-store-pickup-during-ord…
novikor Mar 2, 2020
82bcd00
MSI-2826-Hide-store-pickup-during-order-submissions-if-one-of-the-pro…
Mar 5, 2020
118c105
Merge branch '1.2-develop' into MSI-2826-Hide-store-pickup-during-ord…
novikor Mar 5, 2020
c987966
Merge branch 'MSI-2826-Hide-store-pickup-during-order-submissions-if-…
Mar 5, 2020
e919c4a
magento/inventory#2839: Used extension attributes
Mar 5, 2020
55dfc2b
magento/inventory#2839: Added frontend part
Mar 5, 2020
83c2d67
magento/inventory#2839: Moved to filters extensions attributes
Mar 8, 2020
cf3af8f
magento/inventory#2839: Moved plugin to filters resolver
Mar 8, 2020
0467c33
MSI-2826-Hide-store-pickup-during-order-submissions-if-one-of-the-pro…
Mar 8, 2020
5cd20f6
Merge branch 'MSI-2826-Hide-store-pickup-during-order-submissions-if-…
Mar 8, 2020
2d5b329
MSI-2826-Hide-store-pickup-during-order-submissions-if-one-of-the-pro…
Mar 8, 2020
d7d3fff
MSI-2826-Hide-store-pickup-during-order-submissions-if-one-of-the-pro…
Mar 8, 2020
a68100a
MSI-2826-Hide-store-pickup-during-order-submissions-if-one-of-the-pro…
Mar 8, 2020
92b11dd
Merge branch '1.2-develop' into MSI-2826-Hide-store-pickup-during-ord…
swnsma Mar 8, 2020
e3a7261
MSI-2826-Hide-store-pickup-during-order-submissions-if-one-of-the-pro…
Mar 8, 2020
07847c6
Merge branch 'MSI-2826-Hide-store-pickup-during-order-submissions-if-…
Mar 8, 2020
b6e4657
MSI-2826-Hide-store-pickup-during-order-submissions-if-one-of-the-pro…
Mar 9, 2020
6d6acb8
magento/inventory#2839: Minor fixes
Mar 12, 2020
87365be
Merge remote-tracking branch 'origin/1.2-develop' into MSI-2826-Hide-…
Mar 12, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\InventoryInStorePickupShipping\Model;

use Magento\Framework\Api\SearchCriteriaBuilder;
use Magento\InventoryApi\Api\Data\StockSourceLinkInterface;
use Magento\InventoryApi\Api\GetStockSourceLinksInterface;
use Magento\InventoryApi\Api\SourceRepositoryInterface;
use Magento\InventoryInStorePickupShipping\Model\ResourceModel\GetPickupLocationIntersectionForSkues;
use Magento\InventoryInStorePickupShippingApi\Api\Data\RequestInterface;
use Magento\InventoryInStorePickupShippingApi\Api\GetAvailableLocationsForPickupInterface;
use Magento\InventorySalesApi\Api\StockResolverInterface;

/**
* @inheritdoc
*/
class GetAvailableLocationsForPickup implements GetAvailableLocationsForPickupInterface
{
/**
* @var GetPickupLocationIntersectionForSkues
*/
private $getPickupLocationIntersectionForSkues;

/**
* @var StockResolverInterface
*/
private $stockResolver;

/**
* @var GetStockSourceLinksInterface
*/
private $getStockSourceLinks;

/**
* @var SourceRepositoryInterface
*/
private $sourceRepository;

/**
* @var SearchCriteriaBuilder
*/
private $searchCriteriaBuilder;

/**
* @param GetPickupLocationIntersectionForSkues $getPickupLocationIntersectionForSkues
* @param StockResolverInterface $stockResolver
* @param GetStockSourceLinksInterface $getStockSourceLinks
* @param SourceRepositoryInterface $sourceRepository
* @param SearchCriteriaBuilder $searchCriteriaBuilder
*/
public function __construct(
GetPickupLocationIntersectionForSkues $getPickupLocationIntersectionForSkues,
StockResolverInterface $stockResolver,
GetStockSourceLinksInterface $getStockSourceLinks,
SourceRepositoryInterface $sourceRepository,
SearchCriteriaBuilder $searchCriteriaBuilder
) {
$this->getPickupLocationIntersectionForSkues = $getPickupLocationIntersectionForSkues;
$this->stockResolver = $stockResolver;
$this->getStockSourceLinks = $getStockSourceLinks;
$this->sourceRepository = $sourceRepository;
$this->searchCriteriaBuilder = $searchCriteriaBuilder;
}

/**
* @inheritdoc
*/
public function execute(RequestInterface $request): array
{
$skues = [];
swnsma marked this conversation as resolved.
Show resolved Hide resolved
foreach ($request->getProductsInfo() as $item) {
$skues[] = $item->getSku();
}
$sourceCodes = $this->getPickupLocationIntersectionForSkues->execute($skues);
$stock = $this->stockResolver->execute($request->getScopeType(), $request->getScopeCode());
$sourceCodesAssignedToStock = $this->getSourceCodesAssignedToStock($stock->getStockId());

return array_intersect($sourceCodes, $sourceCodesAssignedToStock);
}

/**
* Get list of Source Codes assigned to the Stock.
*
* @param int $stockId
*
* @return string[]
*/
private function getSourceCodesAssignedToStock(int $stockId): array
{
$searchCriteriaStockSource = $this->searchCriteriaBuilder
->addFilter(StockSourceLinkInterface::STOCK_ID, $stockId)
->create();
$searchResult = $this->getStockSourceLinks->execute($searchCriteriaStockSource);
$codes = [];
foreach ($searchResult->getItems() as $item) {
$codes[] = $item->getSourceCode();
}

return $codes;
}
}
60 changes: 60 additions & 0 deletions InventoryInStorePickupShipping/Model/ProductInfo.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\InventoryInStorePickupShipping\Model;

use Magento\InventoryInStorePickupShippingApi\Api\Data\ProductInfoExtensionInterface;
use Magento\InventoryInStorePickupShippingApi\Api\Data\ProductInfoInterface;

/**
* @inheritdoc
*/
class ProductInfo implements ProductInfoInterface
{
/**
* @var string
*/
private $sku;
/**
* @var ProductInfoExtensionInterface
*/
private $productInfoExtension;

/**
* @param string $sku
* @param ProductInfoExtensionInterface|null $productInfoExtension
*/
public function __construct(string $sku, ?ProductInfoExtensionInterface $productInfoExtension = null)
{
$this->sku = $sku;
$this->productInfoExtension = $productInfoExtension;
}

/**
* @inheritdoc
*/
public function getSku(): string
{
return $this->sku;
}

/**
* @inheritdoc
*/
public function getExtensionAttributes(): ?ProductInfoExtensionInterface
{
return $this->productInfoExtension;
}

/**
* @inheritdoc
*/
public function setExtensionAttributes(ProductInfoExtensionInterface $productInfoExtension): void
{
$this->productInfoExtension = $productInfoExtension;
}
}
98 changes: 98 additions & 0 deletions InventoryInStorePickupShipping/Model/Request.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\InventoryInStorePickupShipping\Model;

use Magento\InventoryInStorePickupShippingApi\Api\Data\ProductInfoInterface;
use Magento\InventoryInStorePickupShippingApi\Api\Data\RequestExtensionInterface;
use Magento\InventoryInStorePickupShippingApi\Api\Data\RequestInterface;

/**
* @inheritdoc
*/
class Request implements RequestInterface
{
/**
* @var ProductInfoInterface[]
*/
private $productsInfo;

/**
* @var RequestExtensionInterface|null
*/
private $requestExtension;

/**
* @var string
*/
private $scopeType;

/**
* @var string
*/
private $scopeCode;

/**
* @param ProductInfoInterface[] $productsSku
* @param string $scopeType
* @param string $scopeCode
* @param RequestExtensionInterface|null $requestExtension |null
*/
public function __construct(
array $productsInfo,
string $scopeType,
string $scopeCode,
?RequestExtensionInterface $requestExtension = null
) {
$this->productsInfo = $productsInfo;
$this->requestExtension = $requestExtension;
$this->scopeType = $scopeType;
$this->scopeCode = $scopeCode;
}

/**
* @inheritdoc
*/
public function getProductsInfo(): array
{
return $this->productsInfo;
}

/**
* @inheritdoc
*/
public function getExtensionAttributes(): ?RequestExtensionInterface
{
return $this->requestExtension;
}

/**
* @inheritdoc
*/
public function setExtensionAttributes(RequestExtensionInterface $requestExtension): void
{
$this->requestExtension = $requestExtension;
}

/**
* @inheritdoc
*/
public function getScopeType(): string
{
return $this->scopeType;
}

/**
* @inheritdoc
*
* @return string
*/
public function getScopeCode(): string
{
return $this->scopeCode;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\InventoryInStorePickupShipping\Model\ResourceModel;

use Magento\Framework\DB\Select;
use Magento\Framework\DB\Sql\ExpressionFactory;
use Magento\Framework\Exception\LocalizedException;
use Magento\Inventory\Model\ResourceModel\Source;
use Magento\Inventory\Model\ResourceModel\SourceItem;
use Magento\InventoryApi\Api\Data\SourceInterface;
use Magento\InventoryApi\Api\Data\SourceItemInterface;
use Magento\InventoryInStorePickupApi\Api\Data\PickupLocationInterface;

/**
* Provides list of Source Codes which have all requested products assigned.
*/
class GetPickupLocationIntersectionForSkues
swnsma marked this conversation as resolved.
Show resolved Hide resolved
{
/**
* @var SourceItem
*/
private $sourceItemResource;
swnsma marked this conversation as resolved.
Show resolved Hide resolved
/**
* @var Source
*/
private $sourceResource;
/**
* @var ExpressionFactory
*/
private $expressionFactory;

/**
* @param SourceItem $sourceItemResource
* @param Source $sourceResource
* @param ExpressionFactory $expressionFactory
*/
public function __construct(
SourceItem $sourceItemResource,
Source $sourceResource,
ExpressionFactory $expressionFactory
) {
$this->sourceItemResource = $sourceItemResource;
$this->sourceResource = $sourceResource;
$this->expressionFactory = $expressionFactory;
}

/**
* Provide intersection of products availability in sources.
*
* @param string[] $skues
*
* @return array
* @throws LocalizedException
*/
public function execute(array $skues)
{
$select = $this->sourceItemResource->getConnection()->select();
$expression = $this->expressionFactory->create(['expression' => 'COUNT(' . SourceItemInterface::SKU . ')']);
$select->from($this->sourceItemResource->getMainTable())
->joinInner(
$this->sourceResource->getMainTable(),
$this->sourceItemResource->getMainTable() . '.' . SourceItemInterface::SOURCE_CODE . '=' .
$this->sourceResource->getMainTable() . '.' . SourceInterface::SOURCE_CODE
)
->where(SourceItemInterface::SKU . ' in (?) ', $skues)
->where(PickupLocationInterface::IS_PICKUP_LOCATION_ACTIVE . '= 1')
->reset(Select::COLUMNS)
->columns([SourceItemInterface::SOURCE_CODE])
->group($this->sourceItemResource->getMainTable() . '.' . SourceItemInterface::SOURCE_CODE)
->having($expression . ' = ' . count($skues));
$result = $this->sourceItemResource->getConnection()->fetchAssoc($select);
$sourceCodes = [];
foreach ($result as $row) {
$sourceCodes[] = $row[SourceItemInterface::SOURCE_CODE];
}

return $sourceCodes;
}
}
2 changes: 2 additions & 0 deletions InventoryInStorePickupShipping/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
"magento/module-inventory-in-store-pickup-shipping-api": "*",
"magento/module-inventory-in-store-pickup-api": "*",
"magento/module-inventory-sales-api": "*",
"magento/module-inventory-api": "*",
"magento/module-inventory": "*",
"magento/module-quote": "*",
"magento/module-store": "*",
"magento/module-catalog": "*"
Expand Down
3 changes: 3 additions & 0 deletions InventoryInStorePickupShipping/etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
<preference for="Magento\InventoryInStorePickupShippingApi\Model\Carrier\Command\GetShippingPriceInterface" type="Magento\InventoryInStorePickupShipping\Model\Carrier\Command\GetShippingPrice" />
<preference for="Magento\InventoryInStorePickupShippingApi\Model\Carrier\Command\GetShippingPriceRequestInterface" type="Magento\InventoryInStorePickupShipping\Model\Carrier\Command\GetShippingPriceRequest" />
<preference for="Magento\InventoryInStorePickupShippingApi\Model\IsInStorePickupDeliveryCartInterface" type="Magento\InventoryInStorePickupShipping\Model\IsInStorePickupDeliveryCart" />
<preference for="Magento\InventoryInStorePickupShippingApi\Api\Data\RequestInterface" type="Magento\InventoryInStorePickupShipping\Model\Request" />
<preference for="Magento\InventoryInStorePickupShippingApi\Api\GetAvailableLocationsForPickupInterface" type="Magento\InventoryInStorePickupShipping\Model\GetAvailableLocationsForPickup" />
<preference for="Magento\InventoryInStorePickupShippingApi\Api\Data\ProductInfoInterface" type="Magento\InventoryInStorePickupShipping\Model\ProductInfo" />

<type name="Magento\InventoryInStorePickupShippingApi\Model\Carrier\Validation\RequestValidatorChain">
<arguments>
Expand Down
Loading