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 23 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
61 changes: 61 additions & 0 deletions InventoryInStorePickup/Model/ProductInfo.php
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;
}
}
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)
swnsma marked this conversation as resolved.
Show resolved Hide resolved
{
$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;
}
}
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);
sidolov marked this conversation as resolved.
Show resolved Hide resolved
$searchCriteriaBuilder->addFilter(SourceInterface::SOURCE_CODE, $codes, 'in');
}
}
1 change: 1 addition & 0 deletions InventoryInStorePickup/Model/SearchRequest/Filters.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

use Magento\InventoryInStorePickupApi\Api\Data\SearchRequest\FiltersInterface;
use Magento\InventoryInStorePickupApi\Api\Data\SearchRequest\FilterInterface;
use Magento\InventoryInStorePickupApi\Api\Data\SearchRequest\FiltersExtensionInterface;

/**
* @inheritdoc
Expand Down
3 changes: 2 additions & 1 deletion InventoryInStorePickup/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
"magento/module-inventory-source-selection-api": "*",
"magento/module-inventory-sales-api": "*",
"magento/module-inventory-catalog-api": "*",
"magento/module-directory": "*"
"magento/module-directory": "*",
"magento/module-inventory": "*"
},
"type": "magento2-module",
"license": [
Expand Down
2 changes: 2 additions & 0 deletions InventoryInStorePickup/etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
<item name="resolve-distance-filter" xsi:type="object">Magento\InventoryInStorePickup\Model\SearchCriteria\ResolveArea</item>
<item name="resolve-scope-filter" xsi:type="object">Magento\InventoryInStorePickup\Model\SearchCriteria\ResolveScopeFilter</item>
<item name="resolve-meta" xsi:type="object">Magento\InventoryInStorePickup\Model\SearchCriteria\ResolveMeta</item>
<item name="resolve-products-assignment-intersection" xsi:type="object">Magento\InventoryInStorePickup\Model\SearchCriteria\ResolveIntersection</item>
</argument>
</arguments>
</type>
Expand Down Expand Up @@ -69,4 +70,5 @@
</argument>
</arguments>
</type>
<preference for="Magento\InventoryInStorePickupApi\Api\Data\SearchRequest\ProductInfoInterface" type="Magento\InventoryInStorePickup\Model\ProductInfo" />
</config>
1 change: 1 addition & 0 deletions InventoryInStorePickup/etc/module.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
<module name="Magento_InventorySourceSelectionApi" />
<module name="Magento_InventorySalesApi" />
<module name="Magento_Directory" />
<module name="Magento_Inventory" />
</sequence>
</module>
</config>
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

namespace Magento\InventoryInStorePickupApi\Api\Data\SearchRequest;

use Magento\InventoryInStorePickupApi\Api\Data\SearchRequest\FiltersExtensionInterface;

/**
* Filter to filter by Fields.
* Each field may be filtered with different condition type.
Expand Down
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;
}
Loading