Skip to content
This repository was archived by the owner on Aug 2, 2022. It is now read-only.
This repository was archived by the owner on Aug 2, 2022. It is now read-only.

Split quote item for Backorder quantity #41

Open
@m-canziani

Description

@m-canziani

I am trying to use your Module to separate the products that are ordered in backorders mode.
I ask you if you know the most correct method to separate the same Item Quote into two different orders, with the quantities divided by backorders.
Ex:
Product 1 -> Stock = Qty: 3, Min_Qty: -10(Out-of-Stock Threshold)
Custumer Cart: Product 1 -> Qty: 8
So 3 real Stock and 5 Backorders

i want 2 orders:
Order 1: Product 1 -> Qty: 3
Order 2: Product 1 -> Qty: 5

Now i've modified (in Magestat/SplitOrder/Model/ExtensionAttributes.php) your function quantityAndStockStatus
if ($this->helperData->getBackorder() && ($attributes->getStockItem()->getQty() - $item->getQty() < 0) ) { return 'out'; }
So i can get if Quote Item have Backorders.
Then in normalizeQuote function:

        if($attribute === 'out'){
            $qtyIn = $product->getExtensionAttributes()->getStockItem()->getQty();
            $qtyOut = $item->getQty() - $qtyIn;

            $itemCopy = clone $item;

            $groups["in"][] = $item->setQty($qtyIn);
            $this->writeLog("getQty() before > " . $item->getQty() );
            $groups[$attribute][] = $itemCopy->setQty($qtyOut);
            $this->writeLog("itemCopy() after > " . $itemCopy->getQty() );
            $item->save();
            $itemCopy->save();
        } else {
            $groups[$attribute][] = $item;
        }

Additional context
Now the order is split correctly but tax_amount for the 2 Quotes isn't changed and the Stock statud of Product 1 is set -8 quantity so the stockInventory decurted 3 more quantity than the orders placed.

I did a lot of research and found nothing about dividing the same Item into two orders.
Have you any suggestion or feature to implement?

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions