duncanmcclean / simple-commerce

A simple, yet powerful e-commerce addon for Statamic.
https://statamic.com/addons/duncanmcclean/simple-commerce
Other
143 stars 36 forks source link

Order confirmation mail is sent in English instead of Dutch #905

Closed itsmesaskovic closed 12 months ago

itsmesaskovic commented 1 year ago

Description

I have upgraded our (acceptance) site from ^v4.5.3 to ^v5.0. When I access my Dutch shop and fulfill an order I receive an order confirmation but instead of it being in Dutch (like previously) it is in English now.

Steps to reproduce

Settings in my Statamic conf:

    'sites' => [

        'default' => [
            'name' => 'My acceptance site',
            'locale' => 'nl_NL',
            'short_locale' => 'nl',
            'url' => '/',
            'attributes' => [
                'prefix' => '',
            ],
        ],

Language files in /resources/lang/nl/strings.php (it retrieves in now from /resources/lang/en/strings.php)

Environment

Environment Laravel Version: 10.20.0 PHP Version: 8.2.9 Composer Version: 2.2.6 Environment: acceptance Debug Mode: OFF Maintenance Mode: OFF

Cache Config: CACHED Events: NOT CACHED Routes: CACHED Views: CACHED

Drivers Broadcasting: log Cache: statamic Database: mysql Logs: stack / single Mail: smtp Queue: sync Session: file

Simple Commerce Currencies: EUR Gateways: Mollie Repository: Customer: DoubleThreeDigital\SimpleCommerce\Customers\EloquentCustomerRepository Repository: Order: DoubleThreeDigital\SimpleCommerce\Orders\EloquentOrderRepository Repository: Product: DoubleThreeDigital\SimpleCommerce\Products\EntryProductRepository Shipping Methods: Package shipping method Tax Engine: DoubleThreeDigital\SimpleCommerce\Tax\BasicTaxEngine

Statamic Addons: 6 Antlers: regex Stache Watcher: Disabled Static Caching: half Version: 4.19.0 PRO

Statamic Addons doublethreedigital/runway: 5.2.0 doublethreedigital/simple-commerce: 5.3.6 joetannenbaum/antlers-stack-tags: 0.1.0 mitydigital/sitemapamic: 2.3.8 roorda-ict/statamic-entries-export: 2.1.0 stoffelio/statamic-turnstile: 1.1.0

duncanmcclean commented 1 year ago

Can you provide the notifications array in your Simple Commerce config file?

itsmesaskovic commented 1 year ago
    'notifications' => [
        'order_paid' => [
            \App\Notifications\BackOfficeOrderPaidNotification::class   => ['to' => config('nofam.admin-address')],
            \App\Notifications\OrderPaidNotification::class   => ['to' => 'customer'],
        ],
    ],
itsmesaskovic commented 1 year ago

I do see a difference in my own OrderPaidNotification versus yours.

This is mine:


        return (new MailMessage)
            ->markdown('emails.orders.paid', $data)
            ->subject(trans('strings.order_confirmation_subject'));

And yours:

        return (new MailMessage)
            ->subject(__(':siteName: Order Confirmation', ['siteName' => config('app.name')]))
            ->markdown('simple-commerce::emails.customer_order_paid', [
                'order' => $this->order,
                'site' => $this->order->site(),
            ]);

Can it be related to the set site?

duncanmcclean commented 1 year ago

Can it be related to the set site?

Maybe? If you add it to your $data, does it change anything?

itsmesaskovic commented 1 year ago

Checking the default customer_order_paid.blade.php I don't think that will have an impact. It looks like it's used for setting the currency symbol based on the site: {{ \DoubleThreeDigital\SimpleCommerce\Currency::parse($order->shippingTotal(), $site) }}

duncanmcclean commented 12 months ago

Just to be sure, I've tested the default Simple Commerce order emails and they're being localized correctly so it probably has something to do with your custom notifications.

Can you share the email view you're using for that email (emails.orders.paid)?

itsmesaskovic commented 12 months ago
@component('mail::message')

@if ($forAdmin)
@component('mail::panel')
Er is een boekbestelling geplaatst. Zie onderstaande details.
@endcomponent
@endif

@if ($holiday)
@component('mail::panel')
{{ __('strings.shipping_attention_holiday_mail') }}
@endcomponent
@endif

# {{ __('strings.book_order_confirmation_title') }}

{{ __('strings.book_order_confirmation_desc') }}

# {{ __('strings.book_order_cart') }}
@component('mail::table')
|  {{ __('strings.book') }}  | {{ __('strings.quantity') }} | {{ __('strings.price') }}  |
| ------------- |:-------------:| --------:|
@foreach ($items as $item)
| {{ $item['author'] }}{{ $item['title'] }} | {{ $item['quantity'] }} | € {{ $item['total'] }},- |
@endforeach
| *{{ __('strings.shipping_type') }}* *{{ $shippingType }}* | | *{{ $shippingTotal }}* |
@if ($hasDonation)
| *{{ __('strings.donation') }}* | | *{{ $donation }}* |
@endif
| {{ __('strings.quantity_total') }} | {{ $quantityTotal }} | |
| **{{ __('strings.total_costs') }}** | | **{{ $grandTotal }}** |
@endcomponent

# {{ __('strings.address_information') }}
@component('mail::table')
|       |          |
| ------------- |:-------------|
| {{ __('strings.name') }}:      | {{ $name }} |
| {{ __('strings.email') }}:      | {{ $email }} |
| {{ __('strings.shipping_country') }}:      | {{ $shippingCountry }} |
| {{ __('strings.shipping_address') }}:      | {{ $shippingAddress }} {{ $shippingHousenumber }} |
| {{ __('strings.shipping_city') }}:   | {{ $shippingCity }} |
| {{ __('strings.shipping_postal_code') }}:   | {{ $shippingZipCode }} |
@endcomponent

@if ($hasDonation)
{{ __('strings.donation_thanks') }}
@endif

{{ __('strings.book_order_desc_end') }}

{{ __('strings.best_regards') }},<br>
{{ __('strings.team_nofam') }}
@endcomponent
itsmesaskovic commented 12 months ago
class OrderPaidNotification extends Notification
{
    use Queueable;

    protected Order $order;

    /**
     * Create a new notification instance.
     *
     * @return void
     */
    public function __construct(Order $order)
    {
        $this->order = $order;
    }

    /**
     * Get the notification's delivery channels.
     *
     * @param mixed $notifiable
     * @return array
     */
    public function via($notifiable)
    {
        return ['mail'];
    }

    /**
     * Get the mail representation of the notification.
     *
     * @param mixed $notifiable
     * @return MailMessage
     */
    public function toMail($notifiable): MailMessage
    {
        $data = array_merge(
            $this->data(),
            [
                'forAdmin' => false,
            ]
        );

        return (new MailMessage)
            ->markdown('emails.orders.paid', $data)
            ->subject(trans('strings.order_confirmation_subject'));
    }

    /**
     * @return array Array containing all the necessary order fields for the mail
     */
    protected function data(): array
    { .... }
....
}
duncanmcclean commented 12 months ago

For orders showing in the wrong language, which site are they being created under? The default site or the site the order relates to?

itsmesaskovic commented 12 months ago

The default site. For now I would say, let's put it to rest and see if any other users come up with the same issue. I have changed the text in my English translations file to Dutch since the shop is only in Dutch.

That way you only have to spend time on it if someone else has the same issue as well

duncanmcclean commented 12 months ago

Ah, that's why it's happening. It'll use the locale of the site the order was created in.

Are you on the very latest version? I've recently fixed an issue where it was creating orders/customers in the default site, rather than the user's current site.

itsmesaskovic commented 12 months ago

I'm on the latest version now. When I ran into the issue I was on version 5.3.6. And my default site is Dutch. I'm not using EN for the shop at all. I am for the rest of the site.

duncanmcclean commented 12 months ago

Oh weird, v5.3.5 was the release that was meant to fix that issue.

Are you definitely in the Dutch site when you add a product to the cart?

itsmesaskovic commented 12 months ago

Let me check it again.

itsmesaskovic commented 12 months ago

I've tested various releases and with all 5.x releases tested (also 5.3.4) I have this issue. One thing I thought of, I've moved from v4 to v5 and while testing v5.3.6 I ran in to this issue. Maybe I've missed an upgrade step?

duncanmcclean commented 12 months ago

Very weird - was this happening on v4 too or just an issue on v5?

itsmesaskovic commented 12 months ago

Just on v5. As said, maybe best to put it to rest in the case it's just an issue for me.

duncanmcclean commented 12 months ago

Weird! Okay, let's close it then. If someone else has this issue, I can re-open and take another look.

itsmesaskovic commented 12 months ago

Thank you for your support to check this issue.