bleroy / Nwazet.Commerce

Idiomatic commerce module for Orchard CMS.
BSD 3-Clause "New" or "Revised" License
26 stars 21 forks source link

Enhancement/attributes localization #111

Closed MatteoPiovanelli-Laser closed 7 years ago

MatteoPiovanelli-Laser commented 7 years ago

This implements the feature presented in #110

MatteoPiovanelli-Laser commented 7 years ago

In the latest changes:

bleroy commented 7 years ago

Thanks for the changes. I don't understand why you need to do that through a filter and script. Isn't there a template that you could alternate or override instead?

MatteoPiovanelli-Laser commented 7 years ago

My reasoning in favour of the filter injecting the script is a matter of flexibility.

(This is all based on what I know about using alternates, which is admittedly not a lot) Alternates as I understand them seem to be more rigid. With alternates:

WIth the filter, I can just say: "if this ViewModel is there, add this script". This is not perfect of course. I can see that if someone implemented an alternate, the script may fail to do what it's supposed to. But unless I make some significant change, I could stack MVC filters.

Controller overrides, I think, suffer from pretty much the same flexibilty limit that I see in alternates.

Did I make sense?

(Github tells me there is "1 review requesting changes by reviewers with write access." but I cannot see it)

bleroy commented 7 years ago

The person who wants to create an alternate has the choice of creating one or the other, or even add their own based on their own criteria. That's the ultimate flexibility. With alternates, you can add an alternate in exactly the same circumstances where you add your script currently. It seems like you don't like alternates and as a consequence came up with your own feature. Well, alternates are the way it's done in Orchard.

MatteoPiovanelli-Laser commented 7 years ago

I changed that thing. To have the list with the added "(culture)" notation, I override the route to "AttributesAdmin/index" so it goes to "LocalizationAttributesAdmin/Index". THat calls the view where I made that change.

I was not able to simply use a IShapeTableProvider to replace the template here.

bleroy commented 7 years ago

I think if you changed the original controller so it uses a shape as the view model, that should be easy to override without taking over the route. I'm not sure what you tried in a IShapeTableProvider that didn't work. What shape did you add alternates to?

MatteoPiovanelli-Laser commented 7 years ago

My attempt with IShapeTableProvider failed because I was trying to somehow override the View used by the controller. I figured, and Sebastien just confirmed it, that I cannot do it that way.

I haven't played with alternates much, to be honest. Could give a couple snippets to clarify what you mean here? WHat I am thinking is to have the Index method end on

return new ShapeResult(_someServiceProbablyAttributesAdmin.GetIndexShape(vm));

The default implementation there returns the shape it's been using so far. THe implementation from the feature in this branch adds the "(culture)" notation.

bleroy commented 7 years ago

Well, this view started as something super simple, just iterating over a bunch of content items and rendering some links and buttons with the data in there. At this point, it should be clear that we've hit a case where this simplicity is no longer affordable since we have a clear extensibility scenario. What I'd do is that I'd refactor the original view a bit so that it creates custom shapes for each of the attributes, and then you could add alternates to that.

I wrote some blog posts a long time ago on that stuff, but there's also documentation on it now: https://weblogs.asp.net/bleroy/creating-shapes-on-the-fly https://weblogs.asp.net/bleroy/orchard-shapeshifting

MatteoPiovanelli-Laser commented 7 years ago

I think the latest changes are in the right direction, else I completely misunderstood your last few comments.

I changed the Index view so it shows a shape for the list of attributes. The list of attributes, then, for each attribute calls a specialized shape. Using an IShapeTableProvider, the localization feature adds and alternate to this latter specialized shape.

bleroy commented 7 years ago

Yes, that's exactly it :) I love how much red there is in this change ;) Thanks for bearing with me, I hope you agree this is much better than what we started with.

bleroy commented 7 years ago

Thanks a lot. I really appreciate the many contributions you've made recently. I hope my requests for changes are not too annoying :D

MatteoPiovanelli-Laser commented 7 years ago

Not at all. I am learning quite a bit while doing this, and that is ever my goal.