|
3 | 3 | namespace craft\commerce\models\inventory; |
4 | 4 |
|
5 | 5 | use craft\base\Model; |
6 | | -use craft\commerce\base\InventoryItemTrait; |
7 | | -use craft\commerce\base\InventoryLocationTrait; |
8 | 6 | use craft\commerce\enums\InventoryTransactionType; |
9 | | -use craft\commerce\enums\InventoryUpdateQuantityType; |
10 | 7 |
|
11 | 8 | /** |
12 | 9 | * Update (Set and Adjust) Inventory Quantity model |
13 | 10 | * |
14 | 11 | * @since 5.0 |
15 | 12 | */ |
16 | | -class UpdateInventoryLevelInTransfer extends Model |
| 13 | +class UpdateInventoryLevelInTransfer extends UpdateInventoryLevel |
17 | 14 | { |
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; |
| 15 | + protected function defineRules(): array |
| 16 | + { |
| 17 | + $rules = parent::defineRules(); |
36 | 18 |
|
37 | | - /** |
38 | | - * @var int The quantity to update. |
39 | | - */ |
40 | | - public int $quantity; |
| 19 | + // Update the `['type']` rule to online allow incoming |
| 20 | + foreach ($rules as &$item) { |
| 21 | + if ($item[0] !== ['type']) { |
| 22 | + continue; |
| 23 | + } |
41 | 24 |
|
42 | | - /** |
43 | | - * @var string A note about the inventory update. |
44 | | - */ |
45 | | - public string $note = ''; |
| 25 | + $item['range'] = [['type'], 'in', 'range' => [...InventoryTransactionType::incoming(), 'onHand']]; |
| 26 | + } |
46 | 27 |
|
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 | | - ]); |
| 28 | + return $rules; |
55 | 29 | } |
56 | 30 | } |
0 commit comments