-
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 pull request #2839 from magento/MSI-2826-Hide-store-pickup-duri…
…ng-order-submissions-if-one-of-the-products-is-not-available-for-pickup MSI-2826-Hide-store-pickup-during-order-submissions-if-one-of-the-products-is-not-available-for-pickup.
- Loading branch information
Showing
14 changed files
with
542 additions
and
9 deletions.
There are no files selected for viewing
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,61 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magento\InventoryInStorePickup\Model; | ||
|
||
use Magento\InventoryInStorePickupApi\Api\Data\SearchRequest\ProductInfoExtensionInterface; | ||
use Magento\InventoryInStorePickupApi\Api\Data\SearchRequest\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 $extension): void | ||
{ | ||
$this->productInfoExtension = $extension; | ||
} | ||
} |
87 changes: 87 additions & 0 deletions
87
InventoryInStorePickup/Model/ResourceModel/GetPickupLocationIntersectionForSkus.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,87 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magento\InventoryInStorePickup\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 GetPickupLocationIntersectionForSkus | ||
{ | ||
/** | ||
* @var SourceItem | ||
*/ | ||
private $sourceItemResource; | ||
|
||
/** | ||
* @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[] $skus | ||
* | ||
* @return array | ||
* @throws LocalizedException | ||
*/ | ||
public function execute(array $skus): array | ||
{ | ||
$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 (?) ', $skus) | ||
->where(SourceInterface::ENABLED . ' = 1') | ||
->where(PickupLocationInterface::IS_PICKUP_LOCATION_ACTIVE . ' = 1') | ||
->reset(Select::COLUMNS) | ||
->columns([SourceItemInterface::SOURCE_CODE]) | ||
->group($this->sourceItemResource->getMainTable() . '.' . SourceItemInterface::SOURCE_CODE) | ||
->having($expression . ' = ' . count($skus)); | ||
$result = $this->sourceItemResource->getConnection()->fetchAssoc($select); | ||
$sourceCodes = []; | ||
foreach ($result as $row) { | ||
$sourceCodes[] = $row[SourceItemInterface::SOURCE_CODE]; | ||
} | ||
|
||
return $sourceCodes; | ||
} | ||
} |
63 changes: 63 additions & 0 deletions
63
InventoryInStorePickup/Model/SearchCriteria/ResolveIntersection.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,63 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magento\InventoryInStorePickup\Model\SearchCriteria; | ||
|
||
use Magento\InventoryApi\Api\Data\SourceInterface; | ||
use Magento\InventoryInStorePickup\Model\ResourceModel\GetPickupLocationIntersectionForSkus; | ||
use Magento\InventoryInStorePickupApi\Api\Data\SearchRequestInterface; | ||
use Magento\InventoryInStorePickupApi\Model\SearchCriteria\BuilderPartsResolverInterface; | ||
use Magento\InventoryInStorePickupApi\Model\SearchCriteria\SearchCriteriaBuilderDecorator; | ||
|
||
/** | ||
* Find intersection of assignments of products between Pickup Locations and filter by codes. | ||
*/ | ||
class ResolveIntersection implements BuilderPartsResolverInterface | ||
{ | ||
/** | ||
* @var GetPickupLocationIntersectionForSkus | ||
*/ | ||
private $getPickupLocationIntersectionForSkus; | ||
|
||
/** | ||
* @param GetPickupLocationIntersectionForSkus $getPickupLocationIntersectionForSkus | ||
*/ | ||
public function __construct( | ||
GetPickupLocationIntersectionForSkus $getPickupLocationIntersectionForSkus | ||
) { | ||
$this->getPickupLocationIntersectionForSkus = $getPickupLocationIntersectionForSkus; | ||
} | ||
|
||
/** | ||
* Search intersection of assignments of products between Pickup Locations. | ||
* | ||
* @param SearchRequestInterface $searchRequest | ||
* @param SearchCriteriaBuilderDecorator $searchCriteriaBuilder | ||
* | ||
* @throws \Magento\Framework\Exception\LocalizedException | ||
*/ | ||
public function resolve( | ||
SearchRequestInterface $searchRequest, | ||
SearchCriteriaBuilderDecorator $searchCriteriaBuilder | ||
): void { | ||
if (!$searchRequest->getExtensionAttributes() | ||
|| !$searchRequest->getExtensionAttributes()->getProductsInfo() | ||
) { | ||
return; | ||
} | ||
|
||
$extensionAttributes = $searchRequest->getExtensionAttributes(); | ||
$skus = []; | ||
foreach ($extensionAttributes->getProductsInfo() as $item) { | ||
$skus[] = $item->getSku(); | ||
} | ||
|
||
$codes = $this->getPickupLocationIntersectionForSkus->execute($skus); | ||
$codes = implode(',', $codes); | ||
$searchCriteriaBuilder->addFilter(SourceInterface::SOURCE_CODE, $codes, 'in'); | ||
} | ||
} |
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
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
40 changes: 40 additions & 0 deletions
40
InventoryInStorePickupApi/Api/Data/SearchRequest/ProductInfoInterface.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,40 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magento\InventoryInStorePickupApi\Api\Data\SearchRequest; | ||
|
||
use Magento\Framework\Api\ExtensibleDataInterface; | ||
use Magento\InventoryInStorePickupApi\Api\Data\SearchRequest\ProductInfoExtensionInterface; | ||
|
||
/** | ||
* Product Info Data Transfer Object. | ||
* @api | ||
*/ | ||
interface ProductInfoInterface extends ExtensibleDataInterface | ||
{ | ||
/** | ||
* Get Product SKU. | ||
* | ||
* @return string | ||
*/ | ||
public function getSku(): string; | ||
|
||
/** | ||
* Get Product Info Extension. | ||
* | ||
* @return \Magento\InventoryInStorePickupApi\Api\Data\SearchRequest\ProductInfoExtensionInterface|null | ||
*/ | ||
public function getExtensionAttributes(): ?ProductInfoExtensionInterface; | ||
|
||
/** | ||
* Set Product Info Extension. | ||
* | ||
* @param \Magento\InventoryInStorePickupApi\Api\Data\SearchRequest\ProductInfoExtensionInterface $extension | ||
* @return void | ||
*/ | ||
public function setExtensionAttributes(ProductInfoExtensionInterface $extension): void; | ||
} |
Oops, something went wrong.