diff --git a/composer.json b/composer.json index c5daea3..13e2d34 100644 --- a/composer.json +++ b/composer.json @@ -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", diff --git a/src/Updater/InventoryUpdater.php b/src/Updater/InventoryUpdater.php index ddccf8b..60815d9 100644 --- a/src/Updater/InventoryUpdater.php +++ b/src/Updater/InventoryUpdater.php @@ -41,6 +41,7 @@ public function update(ProductVariantInterface $productVariant): void )); } + // todo use the product endpoint instead $collection = $this ->client ->stock() @@ -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) { @@ -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()); }