2

I can successfully create the shipment for the entire order but if I want to create partial shipment then it will also create the full quantity can someone tell me how can I create the partial shipment.

2

Boe,

Here is the way to create partial shipment.

you have to pass orderItemId and Qty to ship

Class ShipmentAPI{

    protected $_shipOrderInterface;

    public function __construct(
     \Magento\Sales\Api\ShipOrderInterface $shipOrderInterface
    ){
        $this->_shipOrderInterface = $shipOrderInterface;
    }

    public function createShipment($orderId){

        $shipmentItems = [ "29" => 2 ];
        $shipmentId = 0;    
        if(count($shipmentItems) > 0){

            foreach($shipmentItems as $orderItemId => $qty){
                $itemCreation = $this->_shipmentItemCreationInterface;
                $itemCreation->setOrderItemId($orderItemId)->setQty($qty); 

                $shipItem[] = clone $itemCreation;              

            }
            $shipmentItem = $this->_shipmentInteface->setItems($shipItem);

            $_items = [];
            if(count($shipmentItem->getItems()) > 0 ){
                $_items = $shipmentItem->getItems();    
            }

            $shipmentId = $this->_shipOrderInterface->execute( 
                $orderId, 
                $_items, 
                $notify = false,
                $appendComment = false,
                $comment = null,  
                $shipmentTracks
            );  
        }

        return $shipmentId;
    }
}

this function will give you shipmentId after passing the items properly. Hope this will help you.

|improve this answer|||||

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.