Skip to content

Commit

Permalink
FFWEB-3032: Support MSI - checking all inventory sources for export
Browse files Browse the repository at this point in the history
 Support MSI - checking all inventory sources during export feed
  • Loading branch information
Rayn93 authored Apr 17, 2024
1 parent de9fc6c commit d8bc14d
Show file tree
Hide file tree
Showing 9 changed files with 43 additions and 42 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
# Changelog
## Unreleased
### Fix
- Support MSI - checking all inventory sources during export feed
- Fix feed path for UI export type

## [v4.3.2] - 2024.04.12
### Fix
- Handle export problem for Multi Source Inventory module
Expand Down
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"magento/module-configurable-product": "~100.4.4",
"magento/module-directory": "~100.4.4",
"magento/module-store": "~101.1.4",
"magento/module-inventory": "1.2.*",
"mustache/mustache": "^2.13",
"ext-json": "*"
},
Expand Down
2 changes: 1 addition & 1 deletion src/Controller/Adminhtml/Export/Feed.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public function execute()
$path = $this->feedFileService->getExportPath($filename);

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

try {
$this->ftpUploader->upload($filename, $stream);
Expand Down
20 changes: 11 additions & 9 deletions src/Model/Export/Catalog/Entity/ProductVariation.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
namespace Omikron\Factfinder\Model\Export\Catalog\Entity;

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

/** @var string[] */
private array $configurableData;
private StockItem $stockItem;
private GetSourceItemsBySku $getSourceItemsBySku;

public function __construct(
Product $product,
Product $configurable,
NumberFormatter $numberFormatter,
FieldProvider $variantFieldProvider,
StockItem $stockItem,
GetSourceItemsBySku $getSourceItemsBySku,
array $data = []
) {
$this->product = $product;
$this->configurable = $configurable;
$this->numberFormatter = $numberFormatter;
$this->configurableData = $data;
$this->fieldprovider = $variantFieldProvider;
$this->stockItem = $stockItem;
$this->getSourceItemsBySku = $getSourceItemsBySku;
}

public function getId(): int
Expand Down Expand Up @@ -91,12 +91,14 @@ private function getAvailability(): bool
return $this->product->isAvailable();
}

try {
$quantity = $this->stockItem->get($this->product->getId());
$sourceItems = $this->getSourceItemsBySku->execute($this->product->getSku());

return (bool) $quantity->getIsInStock();
} catch (\Exception $e) {
return $this->product->isAvailable();
foreach ($sourceItems as $sourceItem) {
if ($sourceItem->getStatus()) {
return true;
}
}

return false;
}
}
6 changes: 3 additions & 3 deletions src/Model/Export/Catalog/ProductType/BundleDataProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

use Magento\Bundle\Model\Product\CatalogPrice;
use Magento\Catalog\Model\Product;
use Magento\CatalogInventory\Model\Stock\StockItemRepository as StockItem;
use Magento\Directory\Model\PriceCurrency;
use Magento\Inventory\Model\SourceItem\Command\GetSourceItemsBySku;
use Omikron\Factfinder\Model\Formatter\NumberFormatter;

class BundleDataProvider extends SimpleDataProvider
Expand All @@ -17,10 +17,10 @@ public function __construct(
protected NumberFormatter $numberFormatter,
private readonly PriceCurrency $priceCurrency,
private readonly CatalogPrice $priceModel,
StockItem $stockItem,
protected GetSourceItemsBySku $getSourceItemsBySku,
protected array $productFields = []
) {
parent::__construct($product, $numberFormatter, $stockItem, $productFields);
parent::__construct($product, $numberFormatter, $getSourceItemsBySku, $productFields);
}

public function toArray(): array
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
use Magento\Catalog\Api\Data\ProductInterface;
use Magento\Catalog\Api\ProductRepositoryInterface;
use Magento\Catalog\Model\Product;
use Magento\CatalogInventory\Model\Stock\StockItemRepository as StockItem;
use Magento\ConfigurableProduct\Model\Product\Type\Configurable as ConfigurableProductType;
use Magento\Framework\Api\SearchCriteriaBuilder;
use Magento\Inventory\Model\SourceItem\Command\GetSourceItemsBySku;
use Omikron\Factfinder\Api\Export\ExportEntityInterface;
use Omikron\Factfinder\Api\Filter\FilterInterface;
use Omikron\Factfinder\Model\Export\Catalog\Entity\ProductVariationFactory;
Expand All @@ -25,10 +25,10 @@ public function __construct(
private readonly ProductVariationFactory $variationFactory,
private readonly ProductRepositoryInterface $productRepository,
private readonly SearchCriteriaBuilder $builder,
StockItem $stockItem,
protected GetSourceItemsBySku $getSourceItemsBySku,
protected array $productFields = []
) {
parent::__construct($product, $numberFormatter, $stockItem, $productFields);
parent::__construct($product, $numberFormatter, $getSourceItemsBySku, $productFields);
}

public function getEntities(): iterable
Expand Down
16 changes: 9 additions & 7 deletions src/Model/Export/Catalog/ProductType/SimpleDataProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
namespace Omikron\Factfinder\Model\Export\Catalog\ProductType;

use Magento\Catalog\Model\Product;
use Magento\CatalogInventory\Model\Stock\StockItemRepository as StockItem;
use Magento\Inventory\Model\SourceItem\Command\GetSourceItemsBySku;
use Omikron\Factfinder\Api\Export\FieldInterface;
use Omikron\Factfinder\Api\Export\DataProviderInterface;
use Omikron\Factfinder\Api\Export\ExportEntityInterface;
Expand All @@ -16,7 +16,7 @@ class SimpleDataProvider implements DataProviderInterface, ExportEntityInterface
public function __construct(
protected Product $product,
protected NumberFormatter $numberFormatter,
protected StockItem $stockItem,
protected GetSourceItemsBySku $getSourceItemsBySku,
protected array $productFields = [],
) {
}
Expand Down Expand Up @@ -70,12 +70,14 @@ private function getAvailability(): bool
return $this->product->isAvailable();
}

try {
$quantity = $this->stockItem->get($this->product->getId());
$sourceItems = $this->getSourceItemsBySku->execute($this->product->getSku());

return (bool) $quantity->getIsInStock();
} catch (\Exception $e) {
return $this->product->isAvailable();
foreach ($sourceItems as $sourceItem) {
if ($sourceItem->getStatus()) {
return true;
}
}

return false;
}
}
18 changes: 6 additions & 12 deletions src/Test/Unit/Model/Export/Catalog/Entity/ProductVariationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
namespace Omikron\Factfinder\Model\Export\Catalog\Entity;

use Magento\Catalog\Model\Product;
use Magento\CatalogInventory\Api\Data\StockItemInterface;
use Magento\CatalogInventory\Model\Stock\StockItemRepository;
use Magento\Framework\Model\AbstractModel;
use Magento\Inventory\Model\SourceItem;
use Magento\Inventory\Model\SourceItem\Command\GetSourceItemsBySku;
use Omikron\Factfinder\Model\Export\Catalog\FieldProvider;
use Omikron\Factfinder\Model\Export\Catalog\ProductField\FilterAttributes;
use Omikron\Factfinder\Model\Export\Catalog\ProductField\ProductImage;
Expand Down Expand Up @@ -53,11 +53,8 @@ public function test_variant_data_will_override_the_parent()
$this->createMock(Product::class),
new NumberFormatter(),
$fieldProviderMock,
$this->createConfiguredMock(StockItemRepository::class, [
'get' => $this->createConfiguredMock(
StockItemInterface::class, [
'getIsInStock' => true
])
$this->createConfiguredMock(GetSourceItemsBySku::class, [
'execute' => [$this->createConfiguredMock(SourceItem::class, ['getStatus' => 1])]
]),
$this->configurableProductData
);
Expand Down Expand Up @@ -97,11 +94,8 @@ public function test_configurable_attributes_should_be_merged_with_filter_attrib
$this->createMock(Product::class),
new NumberFormatter(),
$fieldProviderMock,
$this->createConfiguredMock(StockItemRepository::class, [
'get' => $this->createConfiguredMock(
StockItemInterface::class, [
'getIsInStock' => true
])
$this->createConfiguredMock(GetSourceItemsBySku::class, [
'execute' => [$this->createConfiguredMock(SourceItem::class, ['getStatus' => 1])]
]),
['FilterAttributes' => '|Color=Red|Size=XS|'] + $this->configurableProductData
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@

use Magento\Catalog\Api\ProductRepositoryInterface;
use Magento\Catalog\Model\Product;
use Magento\CatalogInventory\Api\Data\StockItemInterface;
use Magento\CatalogInventory\Model\Stock\StockItemRepository;
use Magento\ConfigurableProduct\Model\Product\Type\Configurable as ConfigurableProductType;
use Magento\Framework\Api\SearchCriteriaBuilder;
use Magento\Inventory\Model\SourceItem;
use Magento\Inventory\Model\SourceItem\Command\GetSourceItemsBySku;
use Omikron\Factfinder\Api\Filter\FilterInterface;
use Omikron\Factfinder\Model\Export\Catalog\Entity\ProductVariationFactory;
use Omikron\Factfinder\Model\Formatter\NumberFormatter;
Expand Down Expand Up @@ -114,11 +114,8 @@ protected function setUp(): void
$this->variantFactoryMock,
$this->repositoryMock,
$this->builderMock,
$this->createConfiguredMock(StockItemRepository::class, [
'get' => $this->createConfiguredMock(
StockItemInterface::class, [
'getIsInStock' => true
])
$this->createConfiguredMock(GetSourceItemsBySku::class, [
'execute' => [$this->createConfiguredMock(SourceItem::class, ['getStatus' => 1])]
]),
);
}
Expand Down

0 comments on commit d8bc14d

Please sign in to comment.