Blog Archive doesn't use the culture specific year and month

10 anos atrás
the blogmonths doesn't show culture specific month and year values.
it should use calendar methods to get month and year.
(this doesn't work for persian culture when using jalali calendar.)
10 anos atrás
Thanks for info. I'm not familiar with Persian calendar. Could you please clarify what exactly should be changed
10 anos atrás
unfortunately I've not yet learned asp.net MVC and entity framework. I'm changing
NopCommerceStore\Modules\BlogMonths.ascx.cs of nop 1.9
and after it's complete I'll post the new file, describing the changes.
regards.
10 anos atrás
Ok these are the changes I see are needed, by now.

I tried to comment the original code, and put the new code instead of it. I wish I haven't forgotten any
in blogmonth BindData() and RenderMonths() need change:

private void BindData()
        {
            var blogPosts = this.BlogService.GetAllBlogPosts(NopContext.Current.WorkingLanguage.LanguageId);
            if (blogPosts.Count > 0)
            {
                var months = new SortedDictionary<DateTime, int>();
              
                DateTime first =  blogPosts[blogPosts.Count-1].CreatedOn;

                while (DateTime.SpecifyKind(first, DateTimeKind.Utc) <= DateTime.UtcNow.AddMonths(1))
                {
                    var list = blogPosts.GetPostsByDate(new DateTime(first.Year, first.Month, 1), new DateTime(first.Year, first.Month, 1).AddMonths(1).AddSeconds(-1));
                    if (list.Count > 0)
                    {
                        System.Globalization.Calendar currentCalendar = Thread.CurrentThread.CurrentCulture.Calendar;
                        //DateTime date = new DateTime(first.Year, first.Month, 1);
                        DateTime date = new DateTime(currentCalendar.GetYear(first),currentCalendar.GetMonth(first), 1,currentCalendar);

                        months.Add(date, list.Count);
                    }

                    first = first.AddMonths(1);
                }

                string html = RenderMonths(months);
                lMonths.Text = html;
            }
            else
            {
                this.Visible = false;
            }
        }

        private string RenderMonths(SortedDictionary<DateTime, int> Months)
        {
            System.Globalization.Calendar currentCalendar = Thread.CurrentThread.CurrentCulture.Calendar;

            if (Months.Keys.Count == 0)
                return string.Empty;

            HtmlGenericControl ul = new HtmlGenericControl("ul");
            ul.Attributes.Add("id", "blogMonthList");
            HtmlGenericControl year = null;
            HtmlGenericControl list = null;
            int current = 0;

            foreach (DateTime date in Months.Keys)
            {
                if (current == 0)
                    current = currentCalendar.GetYear(date);
                    //current = date.Year;

                //if (date.Year > current || ul.Controls.Count == 0)
                if (currentCalendar.GetYear(date) > current || ul.Controls.Count == 0)
                {
                    list = new HtmlGenericControl("ul");
                    //list.ID = "year" + date.Year.ToString();
                    list.ID = "year" + currentCalendar.GetYear(date);

                    year = new HtmlGenericControl("li");
                    year.Attributes.Add("class", "year");
                    //year.InnerHtml = date.Year.ToString();
                    year.InnerHtml = currentCalendar.GetYear(date).ToString();
                    year.Controls.Add(list);

                    ul.Controls.AddAt(0, year);
                }

                HtmlGenericControl li = new HtmlGenericControl("li");

                HtmlAnchor anc = new HtmlAnchor();
                string url = SEOHelper.GetBlogUrlByMonth(date);
                anc.HRef = url;
                //anc.InnerHtml = new DateTime(date.Year, date.Month, 1).ToString("MMMM") + " (" + Months[date] + ")";
                anc.InnerHtml = new DateTime(currentCalendar.GetYear(date), currentCalendar.GetMonth(date), 1, currentCalendar).ToString("MMMM")
                    + " (" + Months[date] + ")";
                

                li.Controls.Add(anc);
                list.Controls.AddAt(0, li);
                //current = date.Year;
                current = currentCalendar.GetYear(date);
            }

            StringWriter sw = new StringWriter();
            ul.RenderControl(new HtmlTextWriter(sw));
            return sw.ToString();
        }

-------and in SEOHelper GetBlogUrlByMonth needs to change like this:

public static string GetBlogUrlByMonth(DateTime month)
        {
            System.Globalization.Calendar currentCalendar = System.Threading.Thread.CurrentThread.CurrentCulture.Calendar;
            string url = string.Format("{0}blog.aspx?month={1}-{2}", CommonHelper.GetStoreLocation(),
                currentCalendar.GetYear(month),currentCalendar.GetMonth(month));
            return url.ToLowerInvariant();
        }

--------and in blog.ascx.cs where lTitle.Text is set, code needs to change like this
int filterYear = System.Threading.Thread.CurrentThread.CurrentCulture.Calendar.GetYear(this.FilterByMonth.Value);
                    lTitle.Text = string.Format(GetLocaleResourceString("Blog.FilteredByMonth"), filterYear, this.FilterByMonth.Value.ToString("MMMM"));
                    //lTitle.Text = string.Format(GetLocaleResourceString("Blog.FilteredByMonth"), this.FilterByMonth.Value.Year, this.FilterByMonth.Value.ToString("MMMM"));

---------- and also code for FilterByMonth

public DateTime? FilterByMonth
        {
            get
            {
                DateTime? result = null;
                string dateStr = CommonHelper.QueryString("month");
                if (!String.IsNullOrEmpty(dateStr))
                {
                    string[] tempDate = dateStr.Split(new char[] { '-' });
                    if (tempDate.Length == 2)
                    {
                        //result = new DateTime(Convert.ToInt32(tempDate[0]), Convert.ToInt32(tempDate[1]), 1);
                        result = new DateTime(Convert.ToInt32(tempDate[0]), Convert.ToInt32(tempDate[1]), 1,
                            System.Threading.Thread.CurrentThread.CurrentCulture.Calendar);
                    }
                }
                return result;
            }
        }
10 anos atrás
will it be fixed in the next version?
10 anos atrás
I've just created a work item. Thanks for solution. I'll have a look at it a bit later. And if it's OK, I'll integrate it in v2.20
10 anos atrás
It is important to edit date/time of news or blogposts.
At this there is no option for  manually settings date/time of post in blog (and news too).
Maybe you can implement this in new edition :-)
5 anos atrás
hi
one thing that is essential in blog ... is ability to change the sequence of showing blogs
and now in version 3.8 , there isn't.
2 meses atrás
Hello
The date is displayed incorrectly in the archive section of the blog.
I am using version 4.50 and the glorious Iranian calendar.
Please tell me which code I can edit to display the date correctly.
Thank You!