@@ -503,7 +503,6 @@ public function actionUpdateLevels(): Response
503503 $ note = Craft::$ app ->getRequest ()->getRequiredParam ('note ' );
504504 $ inventoryLocationId = (int )Craft::$ app ->getRequest ()->getRequiredParam ('inventoryLocationId ' );
505505 $ inventoryItemIds = Craft::$ app ->getRequest ()->getRequiredParam ('ids ' );
506- $ inventoryLocation = Plugin::getInstance ()->getInventoryLocations ()->getInventoryLocationById ($ inventoryLocationId );
507506 $ type = Craft::$ app ->getRequest ()->getRequiredParam ('type ' );
508507
509508 // We don't add zero amounts as transactions movements
@@ -514,17 +513,16 @@ public function actionUpdateLevels(): Response
514513 $ errors = [];
515514 $ updateInventoryLevels = UpdateInventoryLevelCollection::make ();
516515 foreach ($ inventoryItemIds as $ inventoryItemId ) {
517- $ inventoryItem = Plugin::getInstance ()->getInventory ()->getInventoryItemById ($ inventoryItemId );
518-
519- $ updateInventoryLevels ->push (new UpdateInventoryLevel ([
520- 'type ' => $ type ,
521- 'updateAction ' => $ updateAction ,
522- 'inventoryItem ' => $ inventoryItem ,
523- 'inventoryLocation ' => $ inventoryLocation ,
524- 'quantity ' => $ quantity ,
525- 'note ' => $ note ,
526- ])
527- );
516+ // Verbosely set property to show usages
517+ $ updateInventoryLevel = new UpdateInventoryLevel ();
518+ $ updateInventoryLevel ->type = $ type ;
519+ $ updateInventoryLevel ->updateAction = $ updateAction ;
520+ $ updateInventoryLevel ->inventoryItemId = $ inventoryItemId ;
521+ $ updateInventoryLevel ->inventoryLocationId = $ inventoryLocationId ;
522+ $ updateInventoryLevel ->quantity = $ quantity ;
523+ $ updateInventoryLevel ->note = $ note ;
524+
525+ $ updateInventoryLevels ->push ($ updateInventoryLevel );
528526 }
529527
530528
@@ -540,7 +538,8 @@ public function actionUpdateLevels(): Response
540538
541539 $ resultingInventoryLevels = [];
542540 foreach ($ updateInventoryLevels as $ updateInventoryLevel ) {
543- $ resultingInventoryLevels [] = Plugin::getInstance ()->getInventory ()->getInventoryLevel ($ updateInventoryLevel ->inventoryItem , $ updateInventoryLevel ->inventoryLocation );
541+ /** @var UpdateInventoryLevel $updateInventoryLevel */
542+ $ resultingInventoryLevels [] = Plugin::getInstance ()->getInventory ()->getInventoryLevel ($ updateInventoryLevel ->inventoryItemId , $ updateInventoryLevel ->inventoryLocationId );
544543 }
545544
546545 return $ this ->asSuccess (Craft::t ('commerce ' , 'Inventory updated. ' ), [
@@ -565,12 +564,9 @@ public function actionEditUpdateLevelsModal(): Response
565564 $ quantity = (int )$ this ->request ->getParam ('quantity ' , 0 );
566565 $ type = $ this ->request ->getRequiredParam ('type ' );
567566
568- $ inventoryLocation = Plugin::getInstance ()->getInventoryLocations ()->getInventoryLocationById ($ inventoryLocationId );
569-
570567 $ inventoryLevels = [];
571568 foreach ($ inventoryItemIds as $ inventoryItemId ) {
572- $ item = Plugin::getInstance ()->getInventory ()->getInventoryItemById ((int )$ inventoryItemId );
573- $ inventoryLevels [] = Plugin::getInstance ()->getInventory ()->getInventoryLevel ($ item , $ inventoryLocation );
569+ $ inventoryLevels [] = Plugin::getInstance ()->getInventory ()->getInventoryLevel ((int )$ inventoryItemId , $ inventoryLocationId );
574570 }
575571
576572 $ params = [
@@ -614,17 +610,14 @@ public function actionSaveInventoryMovement(): Response
614610 return $ this ->asSuccess (Craft::t ('commerce ' , 'No inventory movements made. ' ));
615611 }
616612
617- $ inventoryMovement = new InventoryManualMovement (
618- [
619- 'inventoryItem ' => Plugin::getInstance ()->getInventory ()->getInventoryItemById ($ inventoryItemId ),
620- 'fromInventoryLocation ' => Plugin::getInstance ()->getInventoryLocations ()->getInventoryLocationById ($ fromInventoryLocationId ),
621- 'toInventoryLocation ' => Plugin::getInstance ()->getInventoryLocations ()->getInventoryLocationById ($ toInventoryLocationId ),
622- 'fromInventoryTransactionType ' => InventoryTransactionType::from ($ fromInventoryTransactionType ),
623- 'toInventoryTransactionType ' => InventoryTransactionType::from ($ toInventoryTransactionType ),
624- 'quantity ' => $ quantity ,
625- 'note ' => $ note ,
626- ]
627- );
613+ $ inventoryMovement = new InventoryManualMovement ();
614+ $ inventoryMovement ->inventoryItemId = $ inventoryItemId ;
615+ $ inventoryMovement ->fromInventoryLocation = Plugin::getInstance ()->getInventoryLocations ()->getInventoryLocationById ($ fromInventoryLocationId );
616+ $ inventoryMovement ->toInventoryLocation = Plugin::getInstance ()->getInventoryLocations ()->getInventoryLocationById ($ toInventoryLocationId );
617+ $ inventoryMovement ->fromInventoryTransactionType = InventoryTransactionType::from ($ fromInventoryTransactionType );
618+ $ inventoryMovement ->toInventoryTransactionType = InventoryTransactionType::from ($ toInventoryTransactionType );
619+ $ inventoryMovement ->quantity = $ quantity ;
620+ $ inventoryMovement ->note = $ note ;
628621
629622 if ($ inventoryMovement ->validate ()) {
630623 /** @var InventoryMovementCollection $inventoryMovementCollection */
@@ -665,19 +658,16 @@ public function actionEditMovementModal(): Response
665658 $ toInventoryTransactionType = $ toInventoryTransactionType ->value ;
666659 }
667660
668- $ inventoryMovement = new InventoryManualMovement (
669- [
670- 'inventoryItem ' => Plugin::getInstance ()->getInventory ()->getInventoryItemById ($ inventoryItemId ),
671- 'fromInventoryLocation ' => Plugin::getInstance ()->getInventoryLocations ()->getInventoryLocationById ($ fromInventoryLocationId ),
672- 'toInventoryLocation ' => Plugin::getInstance ()->getInventoryLocations ()->getInventoryLocationById ($ toInventoryLocationId ),
673- 'fromInventoryTransactionType ' => InventoryTransactionType::from ($ fromInventoryTransactionType ),
674- 'toInventoryTransactionType ' => InventoryTransactionType::from ($ toInventoryTransactionType ),
675- 'quantity ' => $ quantity ,
676- 'note ' => $ note ,
677- ]
678- );
679-
680- $ fromLevel = Plugin::getInstance ()->getInventory ()->getInventoryLevel ($ inventoryMovement ->inventoryItem , $ inventoryMovement ->fromInventoryLocation );
661+ $ inventoryMovement = new InventoryManualMovement ();
662+ $ inventoryMovement ->inventoryItemId = $ inventoryItemId ;
663+ $ inventoryMovement ->fromInventoryLocation = Plugin::getInstance ()->getInventoryLocations ()->getInventoryLocationById ($ fromInventoryLocationId );
664+ $ inventoryMovement ->toInventoryLocation = Plugin::getInstance ()->getInventoryLocations ()->getInventoryLocationById ($ toInventoryLocationId );
665+ $ inventoryMovement ->fromInventoryTransactionType = InventoryTransactionType::from ($ fromInventoryTransactionType );
666+ $ inventoryMovement ->toInventoryTransactionType = InventoryTransactionType::from ($ toInventoryTransactionType );
667+ $ inventoryMovement ->quantity = $ quantity ;
668+ $ inventoryMovement ->note = $ note ;
669+
670+ $ fromLevel = Plugin::getInstance ()->getInventory ()->getInventoryLevel ($ inventoryMovement ->inventoryItemId , $ inventoryMovement ->fromInventoryLocation );
681671 $ fromTotal = $ fromLevel ->{$ fromInventoryTransactionType . 'Total ' };
682672
683673 $ movableTo = $ movableTo ->toArray ();
@@ -705,10 +695,7 @@ public function actionUnfulfilledOrders(): Response
705695 $ inventoryLocationId = Craft::$ app ->getRequest ()->getParam ('inventoryLocationId ' );
706696 $ inventoryItemId = Craft::$ app ->getRequest ()->getParam ('inventoryItemId ' );
707697
708- $ inventoryLocation = Plugin::getInstance ()->getInventoryLocations ()->getInventoryLocationById ($ inventoryLocationId );
709- $ inventoryItem = Plugin::getInstance ()->getInventory ()->getInventoryItemById ($ inventoryItemId );
710-
711- $ orders = Plugin::getInstance ()->getInventory ()->getUnfulfilledOrders ($ inventoryItem , $ inventoryLocation );
698+ $ orders = Plugin::getInstance ()->getInventory ()->getUnfulfilledOrders ($ inventoryItemId , $ inventoryLocationId );
712699
713700 $ title = Craft::t ('commerce ' , '{count} Unfulfilled Orders ' , [
714701 'count ' => count ($ orders ),
0 commit comments