Copied to clipboard

Flag this post as spam?

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


These support forums are now closed for new topics and comments.
Please head on over to http://eureka.ucommerce.net/ for support.

  • K.Garrein 164 posts 629 karma points
    Apr 02, 2014 @ 10:47
    K.Garrein
    0

    Persisting a custom value/property

    Hey.

    I inherited a uCommerce project, I need a way to persist a couple of values in memory.

    Is there any way I can add custom properties to the Basket or the PurchaseOrder that will then be available through the entire order process?

    Thank you.
    Regards.
    Kris.

  • Nickolaj Lundgreen 233 posts 1132 karma points
    Apr 02, 2014 @ 10:50
    Nickolaj Lundgreen
    0

    Hi K.Garrein

    You can do:

    PurchaseOrder.FirstOrDefault(x => x.Id == 123)["key"] = value;
        OrderLine.FirstOrDefault(x=> x.Id == 123)["key"] = value2;
    
  • K.Garrein 164 posts 629 karma points
    Apr 02, 2014 @ 10:56
    K.Garrein
    0

    This is some of the code I inherited (is an extension method).
    This seems to do about the same you suggest.
    However, after a redirect to another page the value disappears (returns 0)...

    public static int Credits(this PurchaseOrder order, string name)   {
            var credits = 0;
             if (order[name] == null || !int.TryParse(order[name], out credits))      {
                   return 0;            
    }
            return credits;
    }

     

     

  • K.Garrein 164 posts 629 karma points
    Apr 02, 2014 @ 13:01
    K.Garrein
    0

    I really don't get it, there are other values stored the same way and they are being remembered... why not my values :-)

    K.

  • K.Garrein 164 posts 629 karma points
    Apr 02, 2014 @ 14:16
    K.Garrein
    0

    I just added order.Save() after I set the property and that seems to work.

    Is that the correct way to use it?

    Thanks.
    Kris 

  • Martin 181 posts 740 karma points
    Apr 06, 2014 @ 10:55
    Martin
    100

    Hi Garrein,

    If you add your custom property and do a redirect your property will disappear because uCommerce has not saved the property to the database. So if you are going to do changes to basket and need to go to another page and use it there you always have to either run uCommerce basket pipeline or manuel call Save() on your basket. If I remember correct uCommerce will save your basket in the last step of basket pipeline.

    Best Regards Martin

Please Sign in or register to post replies

Write your reply to:

Draft