Skip to content

Commit 3e953bd

Browse files
authored
Merge pull request #4272 from craftcms/nathaniel/com-548-5x-error-thrown-when-marking-inventory-transfer-as-pending
[5.x] Error when marking inventory transfer as pending
2 parents c6f67e1 + 8eef705 commit 3e953bd

2 files changed

Lines changed: 16 additions & 39 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Release Notes for Craft Commerce
22

3+
## Unreleased
4+
5+
- Fixed a PHP error that occurred when marking an inventory transfer as pending. ([#4267](https://github.com/craftcms/commerce/issues/4267))
6+
37
## 5.6.1.1 - 2026-03-27
48

59
- Fixed a bug where PDF Link Duration didn’t save. ([#4265](https://github.com/craftcms/commerce/issues/4265))

src/models/inventory/UpdateInventoryLevelInTransfer.php

Lines changed: 12 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -2,55 +2,28 @@
22

33
namespace craft\commerce\models\inventory;
44

5-
use craft\base\Model;
6-
use craft\commerce\base\InventoryItemTrait;
7-
use craft\commerce\base\InventoryLocationTrait;
85
use craft\commerce\enums\InventoryTransactionType;
9-
use craft\commerce\enums\InventoryUpdateQuantityType;
106

117
/**
128
* Update (Set and Adjust) Inventory Quantity model
139
*
1410
* @since 5.0
1511
*/
16-
class UpdateInventoryLevelInTransfer extends Model
12+
class UpdateInventoryLevelInTransfer extends UpdateInventoryLevel
1713
{
18-
use InventoryItemTrait, InventoryLocationTrait;
19-
20-
/**
21-
* The type is the set of InventoryTransactionType values, plus the `onHand` type.
22-
* @var string The inventory update type.
23-
*/
24-
public string $type;
25-
26-
/**
27-
* Whether the update should be associated with a transfer.
28-
* @var int|null
29-
*/
30-
public ?int $transferId = null;
31-
32-
/**
33-
* @var InventoryUpdateQuantityType The action to perform on the inventory.
34-
*/
35-
public InventoryUpdateQuantityType $updateAction;
14+
protected function defineRules(): array
15+
{
16+
$rules = parent::defineRules();
3617

37-
/**
38-
* @var int The quantity to update.
39-
*/
40-
public int $quantity;
18+
// Update the `['type']` rule to only allow incoming
19+
foreach ($rules as &$item) {
20+
if ($item[0] !== ['type']) {
21+
continue;
22+
}
4123

42-
/**
43-
* @var string A note about the inventory update.
44-
*/
45-
public string $note = '';
24+
$item['range'] = [...InventoryTransactionType::incoming(), 'onHand'];
25+
}
4626

47-
protected function defineRules(): array
48-
{
49-
return array_merge(parent::defineRules(), [
50-
[['updateAction', 'quantity', 'inventoryLocationId', 'inventoryId', 'type'], 'required'],
51-
[['note'], 'string'],
52-
[['type'], 'in', 'range' => [...InventoryTransactionType::incoming(), 'onHand']],
53-
[['updateAction'], 'in', 'range' => InventoryUpdateQuantityType::values()],
54-
]);
27+
return $rules;
5528
}
5629
}

0 commit comments

Comments
 (0)