wagnerwagner / merx

Merx is a plugin to create online shops with Kirby.
https://merx.wagnerwagner.de
102 stars 10 forks source link

Custom invoice numbers break multi-language website #75

Open jan-herman opened 6 months ago

jan-herman commented 6 months ago

Hi there, I have a multi-language website (default language: czech, secondary: english) and I followed this cookbook recipe to add custom invoice numbers to orders: https://merx.wagnerwagner.de/cookbooks/custom-invoice-numbers.

In czech everything works as expected, but every time order is submitted in english, order.en.txt is created with following content:

Note: 

----

Invoicedate: 2024-03-12T23:11:34+00:00

----

Invoicenumber: 202400001

While in order.cs.txt the Invoicenumber is missing.

I tried specifying locale like this, but that didn't work either.

$orderPage->update([
    'invoiceNumber' => (string) $invoice_number,
], 'cs');

Am I missing something or is this a bug related to #62?

tobiasfabian commented 6 months ago

Hi @jan-herman,

thanks for your question.

You are right. In multi-language sites such things as custom invoice numbers should always be stored in the default language. So I’m wondering why your approach of setting the languageCode in the update method doesn’t work.

Can you please double-check if the code value stored in languages/cs.php is cs.

To make sure you always use the default language, you can do the following:

        'ww.merx.completePayment:after' => function (OrderPage $orderPage) {
            $customInvoiceNumber = 'Lorem Ipsum';
            $orderPage->update([
                'invoiceNumber' => $customInvoiceNumber,
            ], $orderPage->kirby()->defaultLanguage()?->code());
        },
jan-herman commented 4 months ago

Hi, sorry for the late reply. For some reason I missed the notification.

Anyway cs is definitely the default language code. All the other orders are saved as order.cs.txt.