Skip to content

Commit

Permalink
FFWEB-3032: Support MSI - checking all inventory sources during expor…
Browse files Browse the repository at this point in the history
…t feed
  • Loading branch information
Rayn93 committed Apr 15, 2024
1 parent de9fc6c commit 83e831a
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 23 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
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 $sourceItemId => $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 $sourceItemId => $sourceItem) {
if ($sourceItem->getStatus()) {
return true;
}
}

return false;
}
}

0 comments on commit 83e831a

Please sign in to comment.