Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

複数配送時に在庫数が減らない不具合を修正 #4588

Merged
merged 2 commits into from
Jun 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,12 @@ private function eachProductOrderItems(ItemHolderInterface $itemHolder, callable
// 在庫チェックあり
/* @var ProductStock $productStock */
$productStock = $item->getProductClass()->getProductStock();
// 在庫に対してロックを実行
$this->entityManager->lock($productStock, LockMode::PESSIMISTIC_WRITE);
$this->entityManager->refresh($productStock);
if ($productStock->getProductClassId() === null) {
// 在庫に対してロックを実行
$this->entityManager->lock($productStock, LockMode::PESSIMISTIC_WRITE);
$this->entityManager->refresh($productStock);
$productStock->setProductClassId($item->getProductClass()->getId());
}
$ProductClass = $item->getProductClass();
$stock = $callback($productStock->getStock(), $item->getQuantity());
if ($stock < 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,32 @@ public function testRollback()
$ProductClass = $this->entityManager->find(ProductClass::class, $ProductClass->getId());
self::assertEquals(10, $ProductClass->getStock());
}

public function testMultiShipping()
{
// 在庫10の商品
/* @var ProductClass $ProductClass */
$ProductClass = $this->createProduct('test', 1)->getProductClasses()[0];
$ProductClass->setStockUnlimited(false);
$ProductClass->setStock(10);
$ProductClass->getProductStock()->setStock(10);

// 数量3の受注
$Customer = $this->createCustomer();
$Order = $this->createOrderWithProductClasses($Customer, [$ProductClass,$ProductClass]);
$OrderItem = $Order->getProductOrderItems()[0];
$OrderItem->setQuantity(3);
// 数量7の受注
$OrderItem = $Order->getProductOrderItems()[1];
$OrderItem->setQuantity(7);

$this->entityManager->persist($ProductClass);
$this->entityManager->flush();

$this->processor->prepare($Order, new PurchaseContext());

// 複数のOrderItemで同じProductClassの場合、合算した在庫数が減っている
$ProductClass = $this->entityManager->find(ProductClass::class, $ProductClass->getId());
self::assertEquals(0, $ProductClass->getStock());
}
}