Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
languagephp
class BookingReminder extends \Maileon\WooCommerce\Emails\OrderStatusChanged {
    /**
     * Trigger a transaction based on the given object
     *
     * @param mixed $object
     * @param string $to          The email address to send message.
	     * @param string       $subject     Optional. Email subject
	     * @param string       $message     Optional. Message contents
 	    * @param string|array $headers     Optional. Additional headers.
    	 * @param string|array $attachments Optional. Files to attach.
   	  * @return bool Whether the email contents were sent successfully.
     */
    public function trigger($object, $to, $subject = '', $message = '', $headers = '', $attachments = array()) {
        $booking = get_wc_booking($object);

        if (is_a($booking, \WC_Booking::class)) {
            $content = $this->map_maileon_booking_transaction_content($booking);

            $order = $booking->get_order();
            if(!is_object($order)) {
                return;
            }

            $customer_id = $order->get_customer_id();

            return $this->trigger_maileon_transaction($to, $content, $customer_id, $object, $this->id);
        } else {
            throw new \Exception("Booking not found for id: " . $object);
        }
    }

    /**
     * Sets the default value for the Maileon transaction name
     *
     * @return void
     */
    public function init_form_fields()
    {
        parent::init_form_fields();
        $this->form_fields['maileon_transaction_name']['default'] = 'wc_booking_reminder';
    }

    /**
     * Returns the maileon transaction type definition
     *
     * @return array
     */
    public function get_transaction_attributes() {
        return [
            new AttributeType(null, 'booking.id', DataType::$STRING, false),
            new AttributeType(null, 'booking.start_date', DataType::$TIMESTAMP, false),
            new AttributeType(null, 'booking.end_date', DataType::$TIMESTAMP, false),
            new AttributeType(null, 'booking.zoom.link', DataType::$STRING, false),
        ];
    }

    /**
     * Maps the underlying booking to the transaction
     *
     * @param \WC_Booking $booking
     * @return array
     */
    public function map_maileon_booking_transaction_content($booking) {
        return [
            'booking.id' => (string)$booking->get_id(),
            'booking.start_date' => $booking->get_start_date(),
            'booking.end_date' => $booking->get_end_date(),
            'booking.zoom.link' => WC_Bookings_Maileon()->get_zoom_browser_join_link($booking->get_id())
        ];
    }
}

...