Skip to content

Shipment API won't append comment to email #11207

@JeroenVanLeusden

Description

@JeroenVanLeusden

Duplicate of #4320 but since no activity there I created a new one with more detailed information.

Preconditions

  1. Magento v2.1.9
  2. PHP v7.0.14
  3. MySQL v5.6.33

Steps to reproduce

  1. Enable async email sending.
  2. Place an order via the website.
  3. Create a shipment using the API with "appendComment": true.

Expected result

  1. Shipment email is being send with comment appended.

Actual result

  1. Shipment email is being send without comment appended.

API call used

<domain>/rest/all/V1/order/1/ship

{
  "items": [{
    "order_item_id": 1,
    "qty": 1
  }],
  "notify": true,
  "appendComment": true,
  "comment": {
    "comment": "You order will be delivered between 12.00 and 14.00.",
    "is_visible_on_front": 1
  }
}

Workaround

This workaround will use the first comment found with getIsCustomerNotified which is enough for our use case.

Create an after plugin for the \Magento\Sales\Model\Order\ShipmentDocumentFactory::create

public function afterCreate(ShipmentDocumentFactory $subject, ShipmentInterface $shipment)
    {
        foreach ($shipment->getComments() as $comment) {
            /** @var ShipmentCommentInterface $comment */

            if ($comment->getIsCustomerNotified()) {
                $shipment->setCustomerNote($comment->getComment());
                $shipment->setCustomerNoteNotify(true);

                break;
            }
        }

        return $shipment;
    }

Metadata

Metadata

Labels

Fixed in 2.2.xThe issue has been fixed in 2.2 release lineIssue: Clear DescriptionGate 2 Passed. Manual verification of the issue description passedIssue: ConfirmedGate 3 Passed. Manual verification of the issue completed. Issue is confirmedIssue: Format is validGate 1 Passed. Automatic verification of issue format passedIssue: Ready for WorkGate 4. Acknowledged. Issue is added to backlog and ready for developmentReproduced on 2.1.xThe issue has been reproduced on latest 2.1 releaseReproduced on 2.2.xThe issue has been reproduced on latest 2.2 releaseReproduced on 2.3.xThe issue has been reproduced on latest 2.3 release

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions