0

I am creating shipments programmatically for an order. The order has 3 shipments, I need each shipment to go to a different address.

The order has same product in qty 3. So each item(qty:1) needs to go to a different address but I am unable to change the address for the shipment. Here's what I've tried so far -

    $shippingAddressId = $this->order->getShippingAddress()->getId();

    $address = $this->addressRepository->get($shippingAddressId);

    $anotherAddress = $this->addressRepository->get(6);

    $address->setCountryId($anotherAddress->getCountryId());
    $address->setRegion($anotherAddress->getRegion());
    $address->setPostcode($anotherAddress->getPostcode());
    $address->setStreet($anotherAddress->getStreet());
    $address->setCity($anotherAddress->getCity());
    $address->save();

    $shipment->setShippingAddressId($shippingAddressId);
    return;

Thanks!

  • We should use the multi address shipping checkout logic. For your case, we should create separate orders for each shipping address. – Khoa TruongDinh Jul 10 at 6:01
0

Step 1: Go to Stores => Configuration (under Settings)

Step 2: Expand Sales tab from the left sidebar on the Configuration page. Click on Multishipping Settings.

Step 3: Uncheck the Use System Value box and configure the following settings:

Allow Shipping to Multiple Addresses: Set this option to “Yes” to enable multishipping on your store.

Maximum Qty Allowed for Shipping to Multiple Addresses: Specify a limit to the number of products you want to ship when a customer uses multishipping option.

Step 4: Click on Save Config button.

You’ll be prompted to refresh invalidated cache types through a system pop-up message.

Your customers can now choose different shipping addresses in an order during the checkout process.

When a customer clicks on Check Out with Multiple Addresses button, they are requested to select the shipping address for each item in the cart.

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.