Skip to content

Commit e687137

Browse files
authored
FFWEB-3159: Support MSI - checking all inventory sources during export feed
Support MSI - checking all inventory sources during export feed
1 parent fb0de59 commit e687137

8 files changed

Lines changed: 53 additions & 49 deletions

File tree

CHANGELOG.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
# Changelog
2+
## Unreleased
3+
### Fix
4+
- Support MSI - checking all inventory sources during export feed
5+
- Fix feed path for UI export type
6+
27
## [v5.0.0] - 2024.07.08
38
### BREAKING
49
- Upgrade FACT-Finder Web-Components to version 5.0.0-pre.1
@@ -45,7 +50,7 @@
4550
### Fix
4651
- Fix problems in factfinder_feed_export cron job by casting `storeid` to int.
4752

48-
## [v4.1.6] - 2023.07.19
53+
## [v4.1.6] - 2023.07.19
4954
### Fix
5055
- Set default value for $pushImportResult to prevent initialization exception
5156

src/Controller/Adminhtml/Export/Feed.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public function execute()
9090
$path = $this->feedFileService->getExportPath($filename);
9191

9292
$this->feedGeneratorFactory->create($this->feedType)->generate($stream);
93-
$messages[] = __('<li>Feed file for channel %1 has been generated under %2</li>', $channel, "$path/$filename");
93+
$messages[] = __('<li>Feed file for channel %1 has been generated under %2</li>', $channel, $path);
9494

9595
try {
9696
$this->ftpUploader->upload($filename, $stream);

src/Model/Export/Catalog/Entity/ProductVariation.php

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
namespace Omikron\Factfinder\Model\Export\Catalog\Entity;
66

77
use Magento\Catalog\Model\Product;
8-
use Magento\CatalogInventory\Model\Stock\StockItemRepository as StockItem;
8+
use Magento\Inventory\Model\SourceItem\Command\GetSourceItemsBySku;
99
use Omikron\Factfinder\Api\Export\ExportEntityInterface;
1010
use Omikron\Factfinder\Api\Export\FieldInterface;
1111
use Omikron\Factfinder\Model\Export\Catalog\FieldProvider;
@@ -20,22 +20,22 @@ class ProductVariation implements ExportEntityInterface
2020

2121
/** @var string[] */
2222
private array $configurableData;
23-
private StockItem $stockItem;
23+
private GetSourceItemsBySku $getSourceItemsBySku;
2424

2525
public function __construct(
2626
Product $product,
2727
Product $configurable,
2828
NumberFormatter $numberFormatter,
2929
FieldProvider $variantFieldProvider,
30-
StockItem $stockItem,
30+
GetSourceItemsBySku $getSourceItemsBySku,
3131
array $data = []
3232
) {
3333
$this->product = $product;
3434
$this->configurable = $configurable;
3535
$this->numberFormatter = $numberFormatter;
3636
$this->configurableData = $data;
3737
$this->fieldprovider = $variantFieldProvider;
38-
$this->stockItem = $stockItem;
38+
$this->getSourceItemsBySku = $getSourceItemsBySku;
3939
}
4040

4141
public function getId(): int
@@ -91,8 +91,14 @@ private function getAvailability(): bool
9191
return $this->product->isAvailable();
9292
}
9393

94-
$quantity = $this->stockItem->get($this->product->getId());
94+
$sourceItems = $this->getSourceItemsBySku->execute($this->product->getSku());
9595

96-
return $quantity->getIsInStock();
96+
foreach ($sourceItems as $sourceItem) {
97+
if ($sourceItem->getStatus()) {
98+
return true;
99+
}
100+
}
101+
102+
return false;
97103
}
98104
}

src/Model/Export/Catalog/ProductType/BundleDataProvider.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,21 @@
66

77
use Magento\Bundle\Model\Product\CatalogPrice;
88
use Magento\Catalog\Model\Product;
9-
use Magento\CatalogInventory\Model\Stock\StockItemRepository as StockItem;
9+
use Magento\Inventory\Model\SourceItem\Command\GetSourceItemsBySku;
1010
use Magento\Directory\Model\PriceCurrency;
1111
use Omikron\Factfinder\Model\Formatter\NumberFormatter;
1212

1313
class BundleDataProvider extends SimpleDataProvider
1414
{
1515
public function __construct(
16-
protected Product $product,
17-
protected NumberFormatter $numberFormatter,
18-
private readonly PriceCurrency $priceCurrency,
19-
private readonly CatalogPrice $priceModel,
20-
StockItem $stockItem,
21-
protected array $productFields = []
16+
protected Product $product,
17+
protected NumberFormatter $numberFormatter,
18+
private readonly PriceCurrency $priceCurrency,
19+
private readonly CatalogPrice $priceModel,
20+
protected GetSourceItemsBySku $getSourceItemsBySku,
21+
protected array $productFields = []
2222
) {
23-
parent::__construct($product, $numberFormatter, $stockItem, $productFields);
23+
parent::__construct($product, $numberFormatter, $getSourceItemsBySku, $productFields);
2424
}
2525

2626
public function toArray(): array

src/Model/Export/Catalog/ProductType/ConfigurableDataProvider.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
use Magento\Catalog\Api\Data\ProductInterface;
88
use Magento\Catalog\Api\ProductRepositoryInterface;
99
use Magento\Catalog\Model\Product;
10-
use Magento\CatalogInventory\Model\Stock\StockItemRepository as StockItem;
1110
use Magento\ConfigurableProduct\Model\Product\Type\Configurable as ConfigurableProductType;
1211
use Magento\Framework\Api\SearchCriteriaBuilder;
12+
use Magento\Inventory\Model\SourceItem\Command\GetSourceItemsBySku;
1313
use Omikron\Factfinder\Api\Export\ExportEntityInterface;
1414
use Omikron\Factfinder\Api\Filter\FilterInterface;
1515
use Omikron\Factfinder\Model\Export\Catalog\Entity\ProductVariationFactory;
@@ -18,17 +18,17 @@
1818
class ConfigurableDataProvider extends SimpleDataProvider
1919
{
2020
public function __construct(
21-
protected Product $product,
22-
protected NumberFormatter $numberFormatter,
21+
protected Product $product,
22+
protected NumberFormatter $numberFormatter,
2323
private readonly ConfigurableProductType $productType,
2424
private readonly FilterInterface $filter,
2525
private readonly ProductVariationFactory $variationFactory,
2626
private readonly ProductRepositoryInterface $productRepository,
2727
private readonly SearchCriteriaBuilder $builder,
28-
StockItem $stockItem,
29-
protected array $productFields = []
28+
protected GetSourceItemsBySku $getSourceItemsBySku,
29+
protected array $productFields = []
3030
) {
31-
parent::__construct($product, $numberFormatter, $stockItem, $productFields);
31+
parent::__construct($product, $numberFormatter, $getSourceItemsBySku, $productFields);
3232
}
3333

3434
public function getEntities(): iterable

src/Model/Export/Catalog/ProductType/SimpleDataProvider.php

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
namespace Omikron\Factfinder\Model\Export\Catalog\ProductType;
66

77
use Magento\Catalog\Model\Product;
8-
use Magento\CatalogInventory\Model\Stock\StockItemRepository as StockItem;
8+
use Magento\Inventory\Model\SourceItem\Command\GetSourceItemsBySku;
99
use Omikron\Factfinder\Api\Export\FieldInterface;
1010
use Omikron\Factfinder\Api\Export\DataProviderInterface;
1111
use Omikron\Factfinder\Api\Export\ExportEntityInterface;
@@ -16,7 +16,7 @@ class SimpleDataProvider implements DataProviderInterface, ExportEntityInterface
1616
public function __construct(
1717
protected Product $product,
1818
protected NumberFormatter $numberFormatter,
19-
protected StockItem $stockItem,
19+
protected GetSourceItemsBySku $getSourceItemsBySku,
2020
protected array $productFields = [],
2121
) {
2222
}
@@ -70,8 +70,14 @@ private function getAvailability(): bool
7070
return $this->product->isAvailable();
7171
}
7272

73-
$quantity = $this->stockItem->get($this->product->getId());
73+
$sourceItems = $this->getSourceItemsBySku->execute($this->product->getSku());
7474

75-
return $quantity->getIsInStock();
75+
foreach ($sourceItems as $sourceItem) {
76+
if ($sourceItem->getStatus()) {
77+
return true;
78+
}
79+
}
80+
81+
return false;
7682
}
7783
}

src/Test/Unit/Model/Export/Catalog/Entity/ProductVariationTest.php

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
namespace Omikron\Factfinder\Model\Export\Catalog\Entity;
66

77
use Magento\Catalog\Model\Product;
8-
use Magento\CatalogInventory\Api\Data\StockItemInterface;
9-
use Magento\CatalogInventory\Model\Stock\StockItemRepository;
108
use Magento\Framework\Model\AbstractModel;
9+
use Magento\Inventory\Model\SourceItem;
10+
use Magento\Inventory\Model\SourceItem\Command\GetSourceItemsBySku;
1111
use Omikron\Factfinder\Model\Export\Catalog\FieldProvider;
1212
use Omikron\Factfinder\Model\Export\Catalog\ProductField\FilterAttributes;
1313
use Omikron\Factfinder\Model\Export\Catalog\ProductField\ProductImage;
@@ -53,13 +53,8 @@ public function test_variant_data_will_override_the_parent()
5353
$this->createMock(Product::class),
5454
new NumberFormatter(),
5555
$fieldProviderMock,
56-
$this->createConfiguredMock(StockItemRepository::class, [
57-
'get' => $this->createConfiguredMock(
58-
StockItemInterface::class,
59-
[
60-
'getIsInStock' => true
61-
]
62-
)
56+
$this->createConfiguredMock(GetSourceItemsBySku::class, [
57+
'execute' => [$this->createConfiguredMock(SourceItem::class, ['getStatus' => 1])]
6358
]),
6459
$this->configurableProductData
6560
);
@@ -99,13 +94,8 @@ public function test_configurable_attributes_should_be_merged_with_filter_attrib
9994
$this->createMock(Product::class),
10095
new NumberFormatter(),
10196
$fieldProviderMock,
102-
$this->createConfiguredMock(StockItemRepository::class, [
103-
'get' => $this->createConfiguredMock(
104-
StockItemInterface::class,
105-
[
106-
'getIsInStock' => true
107-
]
108-
)
97+
$this->createConfiguredMock(GetSourceItemsBySku::class, [
98+
'execute' => [$this->createConfiguredMock(SourceItem::class, ['getStatus' => 1])]
10999
]),
110100
['FilterAttributes' => '|Color=Red|Size=XS|'] + $this->configurableProductData
111101
);

src/Test/Unit/Model/Export/Catalog/ProductType/ConfigurableDataProviderTest.php

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66

77
use Magento\Catalog\Api\ProductRepositoryInterface;
88
use Magento\Catalog\Model\Product;
9-
use Magento\CatalogInventory\Api\Data\StockItemInterface;
10-
use Magento\CatalogInventory\Model\Stock\StockItemRepository;
119
use Magento\ConfigurableProduct\Model\Product\Type\Configurable as ConfigurableProductType;
1210
use Magento\Framework\Api\SearchCriteriaBuilder;
11+
use Magento\Inventory\Model\SourceItem;
12+
use Magento\Inventory\Model\SourceItem\Command\GetSourceItemsBySku;
1313
use Omikron\Factfinder\Api\Filter\FilterInterface;
1414
use Omikron\Factfinder\Model\Export\Catalog\Entity\ProductVariationFactory;
1515
use Omikron\Factfinder\Model\Formatter\NumberFormatter;
@@ -114,11 +114,8 @@ protected function setUp(): void
114114
$this->variantFactoryMock,
115115
$this->repositoryMock,
116116
$this->builderMock,
117-
$this->createConfiguredMock(StockItemRepository::class, [
118-
'get' => $this->createConfiguredMock(
119-
StockItemInterface::class,
120-
['getIsInStock' => true]
121-
)
117+
$this->createConfiguredMock(GetSourceItemsBySku::class, [
118+
'execute' => [$this->createConfiguredMock(SourceItem::class, ['getStatus' => 1])]
122119
]),
123120
);
124121
}

0 commit comments

Comments
 (0)