1

I am trying to insert multiple items on Db. It inserts successfully but when it comes to multiple items it duplicates it looks like am replacing on this array.

Here is the code:

$orderitems=$order->getAllItems();

    if(!empty($orderitems)){

        foreach($orderitems as $item){

            $aProduct = new OrderDetail;
            $aProduct->SkuId                        = $item->getSku();
            $aProduct->Quantity                     = number_format($item->getQtyOrdered(),0);
            $aProduct->Sellprice                    = number_format($item->getPrice(),2);
            $aProduct->LineNote                     = '';
            $aWebOrder->ProductDetailList[]         = $aProduct;
        }
    }
1

For those who will experience the same issue. In this case works like this:

Don't call getAllItems();

$orderitems=$order->getAllItems();

Replace it with:

$orderitems=$order->getAllVisibleItems();

This worked for me hoe it helps someone else. Thank you

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.