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; }
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.
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.
Hi K.Garrein
You can do:
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;
}
I really don't get it, there are other values stored the same way and they are being remembered... why not my values :-)
K.
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
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
is working on a reply...