View Single Post
Old 11-04-2020, 09:24 AM
  The Knotty Celt's Avatar 
The Knotty Celt The Knotty Celt is offline

Join Date: Jan 2020
Posts: 17

Default Re: Custom e-mail variables

I managed to solve this particular issue. I also opted to add a completely custom field, so that I could still access all the default ones. The issue stemmed from the following call:
In this case, the parent class is actually referencing the original AOrder class which this one is extending. Since the constructor of the original AOrder class expects an argument defining the order, it was a simple matter of passing this argument to the parent constructor.
With my new variable added, the __construct method of my decorated class becomes:
public function __construct(Order $order) { parent::__construct($order); $this->appendData([ 'order' => $order, 'recipient_name' => $order->getProfile()->getName(), ]); $this->populateVariables([ 'order_number' => $order->getOrderNumber(), 'order_total' => AView::formatPrice($order->getTotal()), 'recipient_name' => $order->getProfile()->getName(), 'first_name' => $order->getProfile()->getName(true, true), 'shipping_method_name' => $order->getShippingMethodName(), 'payment_method_name' => $order->getPaymentMethodName(), 'order_reference' => $order->getReference(), ]); $this->setAttachPdfInvoice(Config::getInstance()->NotificationAttachments->attac$ if ($order->getPaymentStatus()) { $order->getPaymentStatus()->explicitlyLoadTranslations(); } if ($order->getShippingStatus()) { $order->getShippingStatus()->explicitlyLoadTranslations(); } }

It is also important to note that I also added the following method to my decorated class in order to define and display the custom variable in the pop-up preview.
protected static function defineVariables() { $prefix = \XLite\Core\Config::getInstance()->LBS->OrderReference->prefix; $separator = \XLite\Core\Config::getInstance()->LBS->OrderReference->separator; return [ 'order_number' => '42', 'order_total' => AView::formatPrice(42), 'recipient_name' => static::t('John Doe'), 'first_name' => static::t('John'), 'shipping_method_name' => static::t('Shipping method'), 'payment_method_name' => static::t('Payment method'), 'order_reference' => $prefix.$'Y').$separator.'0042', ] + parent::defineVariables(); }
X-Cart version

Last edited by The Knotty Celt : 11-04-2020 at 09:31 AM. Reason: Missed Step. Clarified abiguity.
Reply With Quote