Skip to content

Commit

Permalink
Fix bug in counting stock
Browse files Browse the repository at this point in the history
  • Loading branch information
loevgaard committed Dec 9, 2024
1 parent 754d3ef commit 2826e4c
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions src/Updater/InventoryUpdater.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use Doctrine\Persistence\ManagerRegistry;
use Setono\Doctrine\ORMTrait;
use Setono\PeakWMS\Client\ClientInterface;
use Setono\PeakWMS\DataTransferObject\Stock\Stock;
use Setono\PeakWMS\DataTransferObject\Product\Product;
use Setono\PeakWMS\Request\Query\KeySetPageQuery;
use Setono\SyliusPeakPlugin\Provider\InventoryUpdateProviderInterface;
use Setono\SyliusPeakPlugin\Workflow\InventoryUpdateWorkflow;
Expand Down Expand Up @@ -41,14 +41,20 @@ public function update(ProductVariantInterface $productVariant): void
));
}

// todo use the product endpoint instead
$collection = $this
->client
->stock()
->getByProductId($productCode, $variantCode)
->product()
->getByProductId($productCode)
->filter(fn (Product $product): bool => $product->variantId === $variantCode)
;

$this->updateOnHand((int) $collection->sum(fn (Stock $stock): int => (int) $stock->quantity), $productVariant);
Assert::count($collection, 1, sprintf(
'Expected to find exactly one product variant with code %s, but found %d',
$variantCode,
count($collection),
));

$this->updateOnHand((int) $collection[0]->availableToSell, $productVariant);

$this->getManager($productVariant)->flush();
}
Expand Down

0 comments on commit 2826e4c

Please sign in to comment.