我有以下方法可以在采购订单上保存订单属性:
public void SetOrderProperty(string orderPropertyName, string value)
{
PurchaseOrder purchaseOrder = TransactionLibrary.GetBasket().PurchaseOrder;
OrderProperty orderProperty = purchaseOrder.OrderProperties.FirstOrDefault(x => x.Key == orderPropertyName);
if (orderProperty != null)
{
orderProperty.Value = value;
orderProperty.Save();
}
else
{
OrderProperty op = new OrderProperty
{
Key = orderPropertyName,
Value = value,
Order = purchaseOrder
};
op.Save();
}
purchaseOrder.Save();
TransactionLibrary.ExecuteBasketPipeline();
}
当我使用它保存一个值时,我可以看到它出现在uCommerce_OrderProperty
表中的顺序上。
但是,对于某些属性,当我尝试将它们读回时,它们会丢失:
public string GetOrderProperty(string orderPropertyName)
{
PurchaseOrder purchaseOrder;
using (new CacheDisabler())
{
purchaseOrder = TransactionLibrary.GetBasket().PurchaseOrder;
}
OrderProperty orderProperty = purchaseOrder.OrderProperties.FirstOrDefault(x => x.Key == orderPropertyName);
if (orderProperty != null)
{
return orderProperty.Value;
}
return string.Empty;
}
我还尝试了 uCommerce 网站上的这段代码:
public string GetOrderProperty(string orderPropertyName)
{
PurchaseOrder purchaseOrder = SiteContext.Current.OrderContext.GetBasket().PurchaseOrder;
return purchaseOrder[orderPropertyName];
}
如果我检查purchaseOrder
,我可以看到OrderProperties
丢失了。我在任何时候都有 7 个属性,但purchaseOrder
似乎最多只有 5 个,即使表中有 7 个。
这些是订单属性,而不是订单行属性。谁能告诉我为什么我会看到这种行为?
编辑
这条线确实得到了我正在寻找的价值:
OrderProperty op = OrderProperty.FirstOrDefault(x => x.Order.OrderId == purchaseOrder.OrderId && x.Key == orderPropertyName);
即使此行(称为后行)返回 null:
OrderProperty orderProperty = purchaseOrder.OrderProperties.FirstOrDefault(x => x.Key == orderPropertyName);
(两者都在寻找相同的订单属性)
谁能告诉我为什么?