GithubHelp home page GithubHelp logo

Comments (3)

dinistavares avatar dinistavares commented on August 16, 2024 1

Hey!

I added two new helper functions:

  • GetDefaultLanguageValue
  • GetLanguageValueByID

to get languages by ID or the default language text

from go-prestashop-api.

nikkofu avatar nikkofu commented on August 16, 2024

I'm now using for+range func to get the text with one language,

I think this is a simple way to do,

type ProductLanguageData struct {
Language *[]ProductLanguage xml:"language,omitempty" json:"language,omitempty"
//Text string, add for language hooks
}

// utils
func StrToInt(s string) int {
val, err := strconv.Atoi(s)
if err != nil {
return 0
}
return val
}

func GetLanguageText(idLang int, Language *[]prestashop.ProductLanguage) string {
if Language != nil {
for _, v := range *Language {
if utils.StrToInt(v.ID) == idLang {
return v.Text
}
}
}
return ""
}

If I put some id lang value in the query params, then the response will add hook to return what I need,

then I can get this in everywhere

p.Name.Language for range .Text ==> p.Name.Text

from go-prestashop-api.

dinistavares avatar dinistavares commented on August 16, 2024

Hello!

Thanks! I will add some helper functions like this to get product names by language ID + default languages. (I will consider the first language as the default language)

from go-prestashop-api.

Related Issues (4)

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.