private function reserveProductsFromInventory(Order $order) { foreach ($order->getOrderItems() as $orderItem) { $this->inventoryService->reserveProduct($orderItem->getProduct(), $orderItem->getQuantity()); foreach ($orderItem->getOrderItemOptionProducts() as $orderItemOptionProduct) { $this->inventoryService->reserveProduct($orderItemOptionProduct->getOptionProduct()->getProduct(), $orderItem->getQuantity()); } } }
public function testReduceProductForShrinkage() { $product = $this->dummyData->getProduct(); $inventoryLocation = $this->dummyData->getInventoryLocation($this->warehouse); $initialTransaction = $this->dummyData->getInventoryTransaction($inventoryLocation, $product); $this->entityManager->persist($product); $this->entityManager->persist($inventoryLocation); $this->entityManager->persist($initialTransaction); $this->entityManager->flush(); $this->inventoryService->reduceProductForShrinkage($product, 1, $inventoryLocation->getId()); $transactions = $this->inventoryTransactionRepository->findAllByProduct($product); $transactions = $this->getDebitCreditTransactions($transactions); $debitTransaction = $transactions[0]; $creditTransaction = $transactions[1]; $this->assertTrue($debitTransaction->getInventoryLocation() instanceof InventoryLocation); $this->assertTrue($debitTransaction->getType()->isShrinkage()); $this->assertSame(-1, $debitTransaction->getQuantity()); $this->assertSame('Adjusting inventory: Shrinkage', $debitTransaction->getMemo()); $this->assertSame(null, $creditTransaction->getInventoryLocation()); $this->assertTrue($creditTransaction->getType()->isShrinkage()); $this->assertSame(1, $creditTransaction->getQuantity()); $this->assertSame('Adjusting inventory: Shrinkage', $creditTransaction->getMemo()); }
public function handle(AdjustInventoryCommand $command) { $product = $this->productService->findOneById($command->getProductId()); $this->inventoryService->adjustInventory($product, $command->getQuantity(), $command->getInventoryLocationId(), InventoryTransactionType::createById($command->getTransactionTypeId())); }