Giter Site home page Giter Site logo

Comments (6)

tobiasfabian avatar tobiasfabian commented on May 30, 2024 2

Hi @jimkrutor,

thank you so much for your detailed bug report and sorry for the late replay.
I think there is already a fix for this problem in the develop branch (commit 99b92e9).

I will have take a closer look at this. If this is a solution for your problem I will merge it into the main branch and create a new release.

from merx.

christinegotth avatar christinegotth commented on May 30, 2024 1

I have the exact same problem and would love a fix in the next release.

from merx.

el-schneider avatar el-schneider commented on May 30, 2024 1

I ran into the same problem today. Any news?

from merx.

tobiasfabian avatar tobiasfabian commented on May 30, 2024 1

Hello everyone!

thanks for your patience and sorry for the late fix of this issue.

This issue should be fixed with 1.7.0-beta.1. Please report back if you still have problems with validation on multilingual pages.

from merx.

jimkrutor avatar jimkrutor commented on May 30, 2024 1

Confirmed - this solved my original issue, thank you!

from merx.

jimkrutor avatar jimkrutor commented on May 30, 2024

Hi all!
I tried solution from commit 99b92e9 and here's my feedback:

Said fix is taking place in completePayment() method which is happening later in the process. In my case, saving order page (creating content file) works without problem.

Original issue starts earlier in initializePayment() method. In this step, $virtualOrderPage is created and validated. Validation fails because virtual page have its translation created empty by default. I tried to use same approach with $kirby->setCurrentLanguage() before creating $virtualOrderPage, but translation is still created empty.

I still see forcing of the default translation as a viable option. I think I found better way to do it, that can work even without multi-lang option and hopefully for multi-lang sites with more than one language. I didn't do any deep testing of different language configurations though.

Merx.php starting from line 215 (v1.6.1)

// create virtual order page
$virtualOrderPage = new OrderPage([
    'slug' => Str::random(16),
    'template' => 'order',
    'model' => 'order',
    'content' => $data
]);

//modification start
$kirby = kirby();

if ($kirby->multilang()) {
    $languageCode = $kirby->defaultLanguage()->code();
    $virtualOrderPage->translation($languageCode)->update($data);
}
//modification end

// check for validation errors
$errors = $virtualOrderPage->errors();
if (sizeof($errors) > 0) {
    throw new Exception([
        'key' => 'merx.fieldsvalidation',
        'httpCode' => 400,
        'details' => $errors,
    ]);
}

I also found another workaround in OrderPage model that fills empty translation on request. It works, but i think fix on merx level will be more effecient (not having to fetch and convert content object)

site/models/order.php

public function translation(?string $languageCode = null) {

    if($translation = parent::translation($languageCode)) { //language exists

        if($translation->content()) { 
            //this should happen most of the time
            return $translation; 
        } else { 
            //this should happen only once in initializePayment()
            parent::translation($languageCode)->update($this->content()->toArray());
            return parent::translation($languageCode);
        }

    } else { //language do not exist
        return null;
    }
}

from merx.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.