Question

I made a custom module that creates a model which can be associated to products. There are 2 tables:

  • Model (for simplify, it only has an id, name and img)
  • ModelProduct (id, id_model, id_product)

I have this, and it works fine for my purposes.


Now it has to be multilingual, in particular I only need that the name of the Model be in every storeView. So how can I do it?

The first thought is add another column in model store_id but then I will have to save the same association for every storeView, because the same Model translated for every storeView will have differents id.

So I didn't know how to do next, these solutions came to me:

  • I can add another column on the Model like model_id and save the same if for every storeView, and in ModelProduct save that model_id instead of id.

  • Add storeView on ModelProduct and add a row for every storeView with the same association.

But I don't know if there is a better way to do these kind of things. I think is a recurring problem, working with storeViews.

Était-ce utile?

La solution

You can create your custom EAV model so you can scope name to storeview. Look that module as example of how to create custom EAV models in magento 2 https://github.com/ksz2013/m2-foggyline-office

Licencié sous: CC-BY-SA avec attribution
Non affilié à magento.stackexchange
scroll top