0

I'm trying to remove a product from an order, but my code is not working

$backOrdersIds = array();
        foreach ($this->getQuote()->getAllVisibleItems() as $item) {
            $oldQty = (int)$item->getProduct()->getStockItem()->getQty();
            $qtyOrdered = (int)$item->getQty();
            $differenceQty = $oldQty - $qtyOrdered;

            //remove backorder items from Quote
            if($differenceQty <= 0 ){
                $backOrdersIds[] = array(
                    'productId' => $item->getProductId(),
                    'qty' => $qtyOrdered
                );

                $item->delete();
                $this->getQuote()->save();
            }
        }

        foreach ($this->getQuote()->getAllVisibleItems() as $item) {
            var_dump($item->getProductId());
        }
 var_dump($item->getProductId());

still returns me all the products, even those that I deleted

How to remove the product from the order?

3

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.