Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Josué González 17 posts 110 karma points
    Sep 25, 2017 @ 15:54
    Josué González
    0

    Merchello Inventory Product CreateDate

    Hi everyone.

    I have a brief question, it is probably a simple thing to do but I really need a little guidance about it.

    I have a list of products in Merchello on an umbraco-based website. The customer wants to know how many days each product takes in the inventory. Or in other words since a product was added to "merchello" until today, how many days have passed?

    I have tried to do it in theory there are two properties UpdateDate and CreateDate but when inspecting the element. Both dates are the same.

    enter image description here

    But using the product key and reviewing the database in the "merchProduct" table, these dates really are different and can be used for the required purpose.

    enter image description here

    Some help on how to get that data "Days on Inventory". Beforehand, thanks for any help.

  • Martin Aguirre 42 posts 210 karma points
    Sep 25, 2017 @ 18:17
    Martin Aguirre
    1

    Hi.

    Maybe these dates are the dates of the model. check inside de PK element to verify if exist another properties.

    then use this

    https://msdn.microsoft.com/es-ar/library/cc437579(v=vs.71).aspx

    to get the days between dates.

    Update!!! check these previous response

    https://our.umbraco.org/projects/collaboration/merchello/merchello/76967-programmatically-retrieve-products-collection

  • Josué González 17 posts 110 karma points
    Oct 13, 2017 @ 21:15
    Josué González
    100

    Hi... Sorry for my late response...

    Thanks to you Martin Aguirre i found the solution.... And here's is my custom code to get the correct Product Create Date...

    /* This is a direct query to the database to get real product create date*/
    var Database = ApplicationContext.Current.DatabaseContext.Database;
    var sqlSyntax = ApplicationContext.Current.DatabaseContext.SqlSyntax;
    
    //Create a poco Object
    @functions{
        [TableName("merchProduct")]
        private class merchProduct
        {
            [Column("pk")]
            public Guid pk { get; set; }
            [Column("updateDate")]
            public DateTime updateDate { get; set; }
            [Column("createDate")]
            public DateTime createDate { get; set; }
        }
    }
    
    //Make the query 
    var sql = new Sql();
    
    sql.Select("*")
    .From<merchProduct>(sqlSyntax)
    .Append("WHERE pk = '" + Model.Key + "'");
    var productDates = Database.Fetch<merchProduct>(sql).FirstOrDefault();
    
    //You can change System.DateTime.Now for any other date of your convenience
    DateTime createDate = (productDates != null) ? productDates.createDate : System.DateTime.Now;
    
    //Calculate how many days has this product on the inventory
    double daysOnInventory = Math.Round((DateTime.Now - createDate).TotalDays);
    
    //Print daysOnInventory
    <div class="text-muted text-center">Days On Inventory: @daysOnInventory</div>
    

    This worked for me... I hope that can be usefull for some one else...

    Regards

Please Sign in or register to post replies

Write your reply to:

Draft