shipments = collect([$shipments]); } else { $this->shipments = $shipments; } $this->order = $order; // Adjust subject based on number of shipments if ($this->shipments->count() > 1) { $this->subject = __('email.dhl_tracking_subject_multiple', ['count' => $this->shipments->count()]); } else { $this->subject = __('email.dhl_tracking_subject'); } } public function build() { $shoppingUser = $this->order->shopping_user; $salutation = __('email.hello'); if ($shoppingUser && $shoppingUser->billing_firstname) { $salutation = __('email.hello') . ' ' . $shoppingUser->billing_firstname; } // For backward compatibility, also provide single shipment data $primaryShipment = $this->shipments->first(); return $this->view('emails.dhl_tracking')->with([ 'salutation' => $salutation, 'shipments' => $this->shipments, 'shipment' => $primaryShipment, // Backward compatibility 'order' => $this->order, 'trackingNumber' => $primaryShipment->dhl_shipment_no, // Backward compatibility 'trackingUrl' => $primaryShipment->getTrackingUrl(), // Backward compatibility 'orderNumber' => $this->order->getLastShoppingPayment('reference'), 'greetings' => __('email.greetings'), 'sender' => __('email.sender'), 'url' => Util::getMyMivitaUrl(), ]); } }