Skip to content

Conversation

@stefanpoensgen
Copy link

No description provided.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds an available_stock field update to the stock update operation in StockUpdateService. The change sets available_stock to the same value as the new stock level during stock updates.

Key Changes:

  • Added available_stock field to the database update array, setting it equal to newStock

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

'product',
[
'stock' => $newStock,
'available_stock' => $newStock,
Copy link

Copilot AI Nov 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Setting available_stock to the same value as stock may be incorrect. In Shopware 6, available_stock typically represents the stock available for purchase (stock minus reserved/allocated stock from pending orders). By setting it directly to newStock, this change ignores any reserved stock that should be subtracted.

Consider either:

  1. Fetching the current available_stock value in the query at line 62-76 and calculating the new available_stock based on the difference between old and new stock values: current_available_stock + ($newStock - $oldStock)
  2. Removing this field from the update and letting Shopware's core mechanisms handle available_stock calculation
  3. If the intention is to reset reserved stock, this should be documented and potentially require an explicit parameter
Suggested change
'available_stock' => $newStock,

Copilot uses AI. Check for mistakes.
'product',
[
'stock' => $newStock,
'available_stock' => $newStock,
Copy link

Copilot AI Nov 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new available_stock update behavior is not covered by any tests. Consider adding test cases that verify:

  1. The available_stock field is updated correctly when stock changes
  2. The relationship between stock and available_stock is maintained properly
  3. Edge cases such as when there might be reserved stock

This is particularly important given the semantic difference between stock and available_stock in Shopware.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant