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

Hard dependency on MSI modules returned in versions 1.4.1 and 1.5.0 #31

Closed
hostep opened this issue Sep 29, 2023 · 7 comments
Closed

Hard dependency on MSI modules returned in versions 1.4.1 and 1.5.0 #31

hostep opened this issue Sep 29, 2023 · 7 comments

Comments

@hostep
Copy link

hostep commented Sep 29, 2023

Similar situation as reported in #3

We've chosen to not install magento/inventory-metapackage and all dependencies.

However, when updating commerce365/module-customer-price from 1.2.4 to 1.5.0 we get this error during bin/magento setup:di:compile:

$ bin/magento setup:di:compile
Compilation was started.
Area configuration aggregation... 5/9 [===============>------------]  55% 37 secs 168.0 MiB
In ClassReader.php line 57:

  Impossible to process constructor argument Parameter #0 [ <required> Magento\InventoryConfiguration\Model\GetLegacyStockItem $getLegacyStockItem ] of Commerce365\CustomerPrice\Service\GetMinimalSalableQty class


In GetParameterClassTrait.php line 34:

  Class "Magento\InventoryConfiguration\Model\GetLegacyStockItem" does not exist


setup:di:compile

We can work around it by requiring that one module and disabling it:

$ composer require magento/module-inventory-configuration
...
$ bin/magento module:disable Magento_InventoryConfiguration

But it would be appreciated if you can figure out something so this isn't needed like you did in #3

@hostep
Copy link
Author

hostep commented Sep 29, 2023

Hmm not fully solved, we get crashes on the frontend due to various MSI dependencies not being installed, I'm thus currently blocked in updating this module to the latest version :(

If it's too difficult to solve this for non-MSI installations, maybe we should give in and install the full suite, but I'm still hopeful that it's not needed 🤞?

@soloma88
Copy link
Collaborator

soloma88 commented Oct 2, 2023

Hi @hostep but module-catalog-inventory is fully deprecated and changed to MSI. Try to override my class in preference and use StockRegistry to get StockItem there. And I also will remove dependency in module.xml
Later I will take a look at how it could be done better.

@hostep
Copy link
Author

hostep commented Oct 2, 2023

I understand its deprecated, but in practice we've found it to be a lot more stable than the MSI modules. We've always ran into very strange issues with wrong stock qty's and statusses after a few weeks when we attempt to use MSI modules in production webshops. So much so that our clients asked us to remove the MSI modules again.

We haven't tried the very latest versions of MSI modules yet, but we have lost our confidence in those modules.
We can always give it a try again for this one project, but I'm afraid we might loose a lot of time and effort again in figuring out strange bugs caused by the MSI modules.

Also, once the fully open source Mage-OS fork finally kicks of in the future, they'll most likely have a package without MSI modules I think (but I'm not sure). So looking forward in the future, it might be a good idea to have a module that works both with and without MSI modules.

@soloma88
Copy link
Collaborator

soloma88 commented Oct 2, 2023

Thanks for the information, let me know if my suggestion works for you

@hostep
Copy link
Author

hostep commented Oct 2, 2023

Okay thanks for the hint around StockRegistry, I was able to get it working using this patch:

diff --git a/Service/GetMinimalSalableQty.php b/Service/GetMinimalSalableQty.php
index 4ec79d2..9e4953b 100644
--- a/Service/GetMinimalSalableQty.php
+++ b/Service/GetMinimalSalableQty.php
@@ -5,15 +5,15 @@ declare(strict_types=1);
 namespace Commerce365\CustomerPrice\Service;
 
 use Magento\Catalog\Api\Data\ProductInterface;
-use Magento\InventoryConfiguration\Model\GetLegacyStockItem;
+use Magento\CatalogInventory\Api\StockRegistryInterface;
 
 class GetMinimalSalableQty
 {
-    private GetLegacyStockItem $getLegacyStockItem;
+    private StockRegistryInterface $stockRegistry;
 
-    public function __construct(GetLegacyStockItem $getLegacyStockItem)
+    public function __construct(StockRegistryInterface $stockRegistry)
     {
-        $this->getLegacyStockItem = $getLegacyStockItem;
+        $this->stockRegistry = $stockRegistry;
     }
 
     /**
@@ -23,7 +23,7 @@ class GetMinimalSalableQty
      */
     public function execute(ProductInterface $product): ?float
     {
-        $stockItem = $this->getLegacyStockItem->execute($product->getSku());
+        $stockItem = $this->stockRegistry->getStockItemBySku($product->getSku());
         $minSaleQty = $stockItem->getMinSaleQty();
         return $minSaleQty > 0 ? $minSaleQty : null;
     }

@soloma88 soloma88 closed this as completed Oct 2, 2023
@soloma88 soloma88 reopened this Oct 2, 2023
@soloma88
Copy link
Collaborator

Solved in version 1.7.3

@hostep
Copy link
Author

hostep commented Jan 22, 2024

Thanks!

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

No branches or pull requests

2 participants