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

Advanced Member
  
Join Date: Jan 2020
Posts: 32
 

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:
Code:
parent::__construct();
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.
Code:
parent::__construct($order);
With my new variable added, the __construct method of my decorated class becomes:
Code:
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.
Code:
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.$separator.date('Y').$separator.'0042', ] + parent::defineVariables(); }
__________________
X-Cart version 5.4.1.46
PHP version 7.4.33
MySQL version 15.1
Apache version 2.4.56
cURL version 7.74.0

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