storeSettings = new StoreSettings(); $this->order = Arr::get($data, 'order'); $config = Arr::wrap( Arr::get($this->order, 'config') ); $rawTz = Arr::get($config, 'user_tz', 'UTC'); $this->orderTz = (@timezone_open($rawTz) !== false) ? $rawTz : 'UTC'; $orderId = Arr::get($this->order, 'id'); parent::__construct($data); } // protected array $methodMap = [ // 'customer_dashboard_link' => 'getCustomerDashboardLink', // 'payment_summary' => 'getPaymentSummary', // 'payment_receipt' => 'getPaymentReceipt', // ]; protected array $methodMap = [ 'item_count' => 'getItemCount', 'is_digital' => 'getIsDigital', ]; protected array $attributeMap = [ 'id' => 'order.id', 'status' => 'order.status', 'created_at' => 'order.created_at', 'updated_at' => 'order.updated_at', ]; protected array $centColumns = [ 'total_amount', 'subtotal', 'discount_tax', 'manual_discount_total', 'coupon_discount_total', 'shipping_tax', 'shipping_total', 'fee_total', 'tax_total', 'total_paid', 'total_refund' ]; public function parse($accessor = '', $code = '', $transformer = null): ?string { if ($this->shouldParseAddress($accessor)) { return $this->parseAddressFields($accessor); } if (in_array($accessor, ['updated_at', 'created_at'])) { $date = Arr::get($this->data, $this->attributeMap[$accessor]); $timestamp = DateTime::anyTimeToGmt($date)->getTimestamp(); $date = wp_date( get_option('date_format'), $timestamp, new \DateTimeZone($this->orderTz) ); return Helper::translateNumber($date); } // Handle _formatted suffix for cent columns (e.g. total_amount_formatted) $formattedSuffix = '_formatted'; if (Str::endsWith($accessor, $formattedSuffix)) { $baseAccessor = substr($accessor, 0, -strlen($formattedSuffix)); if (in_array($baseAccessor, $this->centColumns)) { $amount = Arr::get($this->order, $baseAccessor); if (!is_numeric($amount)) { return (string) $amount; } return CurrencySettings::getPriceHtml($amount, $this->order['currency']); } } if (in_array($accessor, $this->centColumns)) { $amount = Arr::get($this->order, $accessor); if (!is_numeric($amount)) { return (string) $amount; } return (string) ($amount / 100); } // $html parsers $htmlParsers = [ 'order.download_details', 'order.items_table', 'order.payment_summary', 'order.payment_receipt', 'order.subscription_details', 'order.license_details', 'order.address_details', ]; if (in_array($code, $htmlParsers)) { $order = $this->order; if ($code == 'order.items_table') { return \FluentCart\App\App::make('view')->make('emails.parts.items_table', [ 'order' => $order, 'formattedItems' => $order->order_items, 'heading' => __('Order Summary', 'fluent-cart'), ]); } if ($code === 'order.subscription_details') { if ($order->subscriptions && $order->subscriptions->count() > 0) { return \FluentCart\App\App::make('view')->make('invoice.parts.subscription_items', [ 'subscriptions' => $order->subscriptions, 'order' => $order ]); } return ''; } if ($code === 'order.license_details') { $licenses = $order->getLicenses(); if ($licenses && $licenses->count() > 0) { return \FluentCart\App\App::make('view')->make('emails.parts.licenses', [ 'licenses' => $licenses, 'heading' => _n('License', 'Licenses', $licenses->count(), 'fluent-cart'), 'show_notice' => false ]); } return ''; } if ($code === 'order.download_details') { $downloads = $order->getDownloads(); if ($downloads) { return \FluentCart\App\App::make('view')->make('emails.parts.downloads', [ 'order' => $order, 'heading' => _n('Download', 'Downloads', count($downloads), 'fluent-cart'), 'downloadItems' => $downloads, ]); } return ''; } if ($code === 'order.address_details') { return \FluentCart\App\App::make('view')->make('emails.parts.addresses', [ 'order' => $order, ]); } if ($code == 'order.payment_summary') { return $this->getPaymentSummary(); } if ($code == 'order.payment_receipt') { return $this->getPaymentReceipt(); } } return $this->get($accessor, $code); } public function shouldParseAddress($accessor): bool { return Str::startsWith($accessor, 'billing.') || Str::startsWith($accessor, 'shipping.'); } public function parseAddressFields($accessor) { list($addressType, $accessorsKey) = $this->resolveAddressFieldKeys($accessor); return $this->getAddressData($addressType, $accessorsKey); } public function resolveAddressFieldKeys($accessor): array { $exploded = explode('.', $accessor); $addressType = $exploded[0]; $accessorsKey = implode('.', array_slice($exploded, 1)); return [$addressType, $accessorsKey]; } public function getAddressData($addressAccessor, $accessor = null) { $address = Arr::get($this->order, $addressAccessor . '_address'); if (empty($address)) { return ""; } $formattedFields = ['city', 'state', 'country']; if (in_array($accessor, $formattedFields) && method_exists($address, 'getFormattedAddress')) { $formatted = $address->getFormattedAddress(); return Arr::get($formatted, $accessor) ?: ''; } return Arr::get($address, $accessor) ?: ''; } public function getPaymentSummary() { $order = $this->order; return \FluentCart\App\App::make('view')->make('emails.parts.items_table', [ 'order' => $order, 'formattedItems' => $order->order_items, 'heading' => '', ]); } public function getPaymentReceipt() { $order = $this->order; ob_start(); \FluentCart\App\App::make('view')->render('emails.parts.items_table', [ 'order' => $order, 'formattedItems' => $order->order_items, 'heading' => __('Order Summary', 'fluent-cart'), ]); if ($order->subscriptions && $order->subscriptions->count() > 0) { \FluentCart\App\App::make('view')->render('invoice.parts.subscription_items', [ 'subscriptions' => $order->subscriptions, 'order' => $order ]); } $licenses = $order->getLicenses(); if ($licenses && $licenses->count() > 0) { \FluentCart\App\App::make('view')->render('emails.parts.licenses', [ 'licenses' => $licenses, 'heading' => __('Licenses', 'fluent-cart'), 'show_notice' => false ]); } $downloads = $order->getDownloads(); if ($downloads) { \FluentCart\App\App::make('view')->render('emails.parts.downloads', [ 'order' => $order, 'heading' => __('Downloads', 'fluent-cart'), 'downloadItems' => $downloads, ]); } echo '