umbraco-community / Our.Umbraco.OpeningHours

An Umbraco property editor for handling opening hours
MIT License
9 stars 13 forks source link

OpeningHoursTimeSlot Object is empty #25

Closed wiedikerli closed 7 years ago

wiedikerli commented 7 years ago

If installed the project via nuget and filled up the property. But when I want to render it on the frontend the OpeningHoursTimeSlot object is empty.

image

abjerner commented 7 years ago

@ninjaonsafari Do you perhaps have an example of your code?

wiedikerli commented 7 years ago

I just copied the code from the example.

var opening = Model.Content.GetOpeningHours();

abjerner commented 7 years ago

@ninjaonsafari When using that extension method without any parameters, the method assumes the alias of your property is openingHours. If this doesn't match your document type, you can specify the alias explicitly instead - eg. Model.Content.GetOpeningHours("shopOpeningHours").

wiedikerli commented 7 years ago

@abjerner i now have this code:

var asdf = Model.Content.GetPropertyValue<OpeningHoursModel>("openingHours");
var opening = Model.Content.GetOpeningHours("openingHours");

but it still doesnt return anything.

abjerner commented 7 years ago

@ninjaonsafari what does it say if you try something like:

var property = Model.Content.GetProperty("openingHours");

if (property == null) {
    <pre>Property no found</pre>
} else {
    <pre>@property.PropertyTypeAlias => @property.DataValue</pre>
}

This should write out the raw JSON.

wiedikerli commented 7 years ago

I see the values in the raw JSON. So maybe there is something wrong in the ValueConverter?

openingHours => {
  "weekdays": {
    "0": {
      "label": "Sunday",
      "items": []
    },
    "1": {
      "label": "Monday",
      "items": [
        {
          "opens": "09:00",
          "closes": "18:30"
        }
      ]
    },
    "2": {
      "label": "Tuesday",
      "items": [
        {
          "opens": "09:00",
          "closes": "18:30"
        }
      ]
    },
    "3": {
      "label": "Wednesday",
      "items": [
        {
          "opens": "09:00",
          "closes": "18:30"
        }
      ]
    },
    "4": {
      "label": "Thursday",
      "items": [
        {
          "opens": "09:00",
          "closes": "20:00"
        }
      ]
    },
    "5": {
      "label": "Friday",
      "items": [
        {
          "opens": "09:00",
          "closes": "20:00"
        }
      ]
    },
    "6": {
      "label": "Saturday",
      "items": [
        {
          "opens": "08:00",
          "closes": "17:00"
        }
      ]
    }
  },
  "holidays": [
    {
      "label": "",
      "date": "",
      "items": []
    }
  ]
}
abjerner commented 7 years ago

@ninjaonsafari Ok. I will do some testing with the JSON ;)

abjerner commented 7 years ago

@ninjaonsafari At the end of the JSON, you have an empty holiday. So the internal parsing will fail (silently) because the empty string can't be parsed to a valid date.

So the simple answer is that fails because the entered data is invalid. But this might not be the best result when looking at user experience, so I'll see what I can to to improve the error handling ;)

abjerner commented 7 years ago

I have pushed a new release where the date parsing has been changed a bit. Now, the invalid holiday item will simply be ignored instead of making the entire model fail ;)