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.

0

A bit of a simpler solution that worked perfectly for me:

$shipmentItems = [
    $this->shipmentItemCreation->setOrderItemId(1234)->setQty(1)
];

$this->shipOrder->execute($orderId, $shipmentItems, $notify, $appendComment, $comment, $tracks, $packages, $arguments);

Where $this->shipItemCreation is an instance of \Magento\Sales\Api\ShipOrderInterface and $this->shipOrder is an instance of \Magento\Sales\Api\ShipOrderInterface.

The above example creates a shipment with 1 unit of the order item ID 1234.

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.