NVision-Commerce-Solutions / module-customer-price

Commerce 365 for Magento - Magento 2 Extension - Customer Price Module
https://n.vision/products/commerce-365-for-magento-b2b/
2 stars 4 forks source link

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

Closed hostep closed 7 months ago

hostep commented 11 months ago

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 commented 11 months ago

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 commented 11 months ago

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 commented 11 months ago

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 commented 11 months ago

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

hostep commented 11 months ago

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 commented 7 months ago

Solved in version 1.7.3

hostep commented 7 months ago

Thanks!