Skip to content

Commit

Permalink
Fix bug in inventory updater
Browse files Browse the repository at this point in the history
  • Loading branch information
loevgaard committed Dec 6, 2024
1 parent df0f18c commit 754d3ef
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"psr/log": "^1.0 || ^2.0 || ^3.0",
"setono/composite-compiler-pass": "^1.1",
"setono/doctrine-orm-trait": "^1.1",
"setono/peak-wms-php-sdk": "^1.2",
"setono/peak-wms-php-sdk": "^1.2.1",
"sylius/admin-bundle": "^1.0",
"sylius/core": "^1.0",
"sylius/core-bundle": "^1.0",
Expand Down
21 changes: 11 additions & 10 deletions src/Updater/InventoryUpdater.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public function update(ProductVariantInterface $productVariant): void
));
}

// todo use the product endpoint instead
$collection = $this
->client
->stock()
Expand All @@ -66,8 +67,8 @@ public function updateAll(bool $onlyUpdated = true): void
$productVariantRepository = $this->getRepository(ProductVariant::class);

$i = 0;
$stock = $this->client->stock()->iterate(KeySetPageQuery::create());
foreach ($stock as $item) {
$products = $this->client->product()->iterate(KeySetPageQuery::create());
foreach ($products as $product) {
++$i;

if ($i % 100 === 0) {
Expand All @@ -81,27 +82,27 @@ public function updateAll(bool $onlyUpdated = true): void
}

try {
Assert::notNull($item->variantId, sprintf(
Assert::notNull($product->variantId, sprintf(
'Stock with id %d does not have a variant id.',
(int) $item->id,
(int) $product->id,
));

$productVariant = $productVariantRepository->findOneBy(['code' => $item->variantId]);
$productVariant = $productVariantRepository->findOneBy(['code' => $product->variantId]);
Assert::notNull(
$productVariant,
sprintf('Product variant with code %s does not exist', $item->variantId),
sprintf('Product variant with code %s does not exist', $product->variantId),
);

if ($item->reservedQuantity !== $productVariant->getOnHold()) {
if ($product->orderedByCustomers !== $productVariant->getOnHold()) {
$inventoryUpdate->addWarning(sprintf(
'Product variant with code %s has %d on hold in Sylius and %d on hold in Peak WMS',
$item->variantId,
$product->variantId,
(int) $productVariant->getOnHold(),
(int) $item->reservedQuantity,
(int) $product->orderedByCustomers,
));
}

$this->updateOnHand((int) $item->quantity, $productVariant);
$this->updateOnHand((int) $product->availableToSell, $productVariant);
} catch (\Throwable $e) {
$inventoryUpdate->addError($e->getMessage());
}
Expand Down

0 comments on commit 754d3ef

Please sign in to comment.