AmpersandHQ / magento2-disable-stock-reservation

This module disables the inventory reservation logic introduced as part of MSI in Magento 2.3.3
GNU Lesser General Public License v3.0
215 stars 61 forks source link

[Bugfix] changed product validation for deduction #17

Closed kernstmediarox closed 4 years ago

kernstmediarox commented 4 years ago

Fixes a bug in connection with bundled products. In our case, the "isDummy" method resulted in a "false" for a bundled product. For the associated child products, the method returned a "true". We have modified the check so that the native class "Magento\InventoryConfigurationApi\Model\IsSourceItemManagementAllowedForProductTypeInterface" is now used for the check.

convenient commented 4 years ago

Hello @kernstmediarox

Due to an error on my part travis wasn't automatically running. I've kicked this off for you now and can see a code style issue was detected.

$ ./vendor/bin/php-cs-fixer fix --dry-run --rules=@PSR2 --diff src/
Loaded config default.
   1) src/Model/GetSourceSelectionResultFromOrder.php
      ---------- begin diff ----------
--- Original
+++ New
@@ @@
         foreach ($orderItems as $orderItem) {
-            if(!$this->isSourceItemManagementAllowedForProductType->execute($orderItem->getProductType())) {
+            if (!$this->isSourceItemManagementAllowedForProductType->execute($orderItem->getProductType())) {
                 continue;
             }

             $itemSku = $this->getSkuFromOrderItem->execute($orderItem);
             $qty = $this->castQty($orderItem, $orderItem->getQtyOrdered());

             $selectionRequestItems[] = $this->itemRequestFactory->create([
                 'sku' => $itemSku,
                 'qty' => $qty,
             ]);
         }
         return $selectionRequestItems;
     }

     /**
      * Cast qty value
      *
      * @param OrderItemInterface $item
      * @param string|int|float $qty
      * @return float
      */
     private function castQty(OrderItemInterface $item, $qty): float
     {
         if ($item->getIsQtyDecimal()) {
             $qty = (float) $qty;
         } else {
             $qty = (int) $qty;
         }

         return $qty > 0 ? $qty : 0;
     }
 }

      ----------- end diff -----------

Can you please amend?

Thanks

kernstmediarox commented 4 years ago

done

Am 14.04.20 um 10:39 schrieb Luke Rodgers:

Hello @kernstmediarox https://github.com/kernstmediarox

Due to an error on my part travis wasn't automatically running. I've kicked this off for you now and can see a code style issue was detected.

$ ./vendor/bin/php-cs-fixer fix --dry-run --rules=@PSR2 --diff src/ Loaded config default. 1) src/Model/GetSourceSelectionResultFromOrder.php ---------- begin diff ---------- --- Original +++ New @@ @@ foreach ($orderItems as $orderItem) {

  • if(!$this->isSourceItemManagementAllowedForProductType->execute($orderItem->getProductType())) {

  • if (!$this->isSourceItemManagementAllowedForProductType->execute($orderItem->getProductType())) { continue; }

          $itemSku = $this->getSkuFromOrderItem->execute($orderItem);
          $qty = $this->castQty($orderItem, $orderItem->getQtyOrdered());
    
          $selectionRequestItems[] = $this->itemRequestFactory->create([
              'sku' => $itemSku,
              'qty' => $qty,
          ]);
      }
      return $selectionRequestItems;

    }

    /**

    • Cast qty value
    • @param OrderItemInterface $item
    • @param string|int|float $qty
    • @return float */ private function castQty(OrderItemInterface $item, $qty): float { if ($item->getIsQtyDecimal()) { $qty = (float) $qty; } else { $qty = (int) $qty; }

      return $qty > 0 ? $qty : 0; } }

      ----------- end diff -----------

Can you please amend?

Thanks

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/AmpersandHQ/magento2-disable-stock-reservation/pull/17#issuecomment-613306022, or unsubscribe https://github.com/notifications/unsubscribe-auth/ALP2VJPVVLUYWRU6YZC726DRMQOMPANCNFSM4MHQTTCQ.

--

mediarox UG (haftungsbeschränkt) Otto-von-Guericke-Str. 56b 39104 Magdeburg

Geschäftsführer: Steven Fritzsche

Registergericht: Amtsgericht Stendal Registernummer: HRB 19333

Tel: 0391 / 55 96 90 1 Fax: 0391 / 58 27 45 3 Web: www.mediarox.de

convenient commented 4 years ago

Just a note that my intention was to write a test that covers a configurable / bundle product add to basket like we currently have for simples, but I have been flat out with other stuff.

If you have the time or inclination to pick up writing a test you can look at https://github.com/AmpersandHQ/magento2-disable-stock-reservation/blob/master/dev/codeception.MD

convenient commented 4 years ago

Got feedback from other parties that this is working on production for them.

We tried to implement some tests to capture the issue in #33 but couldn't capture it, i think we may have been missing some prerequisite or configuration.

Either way, I'm happy that this code change makes sense and will merge and tag.

Thank you for your contribution and sorry it took so long to get merged.