The price is set to 2, if any of the objects is NULL. This always happens. The set item is added correctly to the shopping cart, but the price is always 2.
False Alert, I just failed to safe my variables properly from a combo box -.- I am still embracing the delicacies of programming with a Page Life Cycle ;-)
I humbly ask for the deletion of this thread to minimize my disgrace...
Dynamic Order Properties not Working in C#
I tried to create a Set Item consisting of several Sub-Items. To achieve this, I saved the Item-Skus in the Orderline of the Set Item:
[code]
ProductCatalog catalog =
ProductCatalog.All().SingleOrDefault(x => x.Name == catalogName);
var basket = SiteContext.Current.OrderContext.GetBasket().PurchaseOrder;
Product setProduct = Product.All().Single(x => x.Sku == setProductSKU && x.ParentProduct == null);
OrderLine setOrderLine = basket.AddProduct(catalog, setProduct, 1, false);
setOrderLine["setSku1"] = setSku1;
setOrderLine["setSku2"] = setSku2;
setOrderLine["setSku3"] = setSku3;
setOrderLine.Save();
basket.Save();
Library.ExecuteBasketPipeline();
[/code]
I then try to read out the products to update the price of the Set Product:
[code]
var setProduct1 = Product.All().SingleOrDefault(p => p.Sku == item.GetOrderProperty("setSku1").Value);
var setProduct2 = Product.All().SingleOrDefault(p => p.Sku == item.GetOrderProperty("setSku2").Value);
var setProduct3 = Product.All().SingleOrDefault(p => p.Sku == item.GetOrderProperty("setSku3").Value);
var priceGroup = PriceGroup.All().SingleOrDefault(pg => pg.Name == "EUR 19%");
if(setProduct1 != null && setProduct2 != null && setProduct3 != null) {
item.Price = setProduct1.GetPrice(priceGroup).Price.Value + setProduct2.GetPrice(priceGroup).Price.Value +
setProduct3.GetPrice(priceGroup).Price.Value;
}
else
item.Price = 2;
[/code]
The price is set to 2, if any of the objects is NULL. This always happens. The set item is added correctly to the shopping cart, but the price is always 2.
What am I doing wrong?
Ok, it seems like I screwed up the code examples, and I get an XSLT parser Error, if I try to edit my post...
So here again the code examples:
ProductCatalog catalog =
ProductCatalog.All().SingleOrDefault(x => x.Name == "Scout Retail");
var basket = SiteContext.Current.OrderContext.GetBasket().PurchaseOrder;
Product setProduct = Product.All().Single(x => x.Sku == "SchulranzenSetAktion" && x.ParentProduct == null);
OrderLine setOrderLine = basket.AddProduct(catalog, setProduct, 1, false);
setOrderLine["setSku1"] = setSku1;
setOrderLine["setSku2"] = setSku2;
setOrderLine["setSku3"] = setSku3;
setOrderLine.Save();
basket.Save();
Library.ExecuteBasketPipeline();
And
var setProduct1 = Product.All().SingleOrDefault(p => p.Sku == item.GetOrderProperty("setSku1").Value);
var setProduct2 = Product.All().SingleOrDefault(p => p.Sku == item.GetOrderProperty("setSku2").Value);
var setProduct3 = Product.All().SingleOrDefault(p => p.Sku == item.GetOrderProperty("setSku3").Value);
var priceGroup = PriceGroup.All().SingleOrDefault(pg => pg.Name == "EUR 19%");
if(setProduct1 != null && setProduct2 != null && setProduct3 != null) {
item.Price = setProduct1.GetPrice(priceGroup).Price.Value + setProduct2.GetPrice(priceGroup).Price.Value +
setProduct3.GetPrice(priceGroup).Price.Value;
}
else
item.Price = 2;
False Alert, I just failed to safe my variables properly from a combo box -.- I am still embracing the delicacies of programming with a Page Life Cycle ;-)
I humbly ask for the deletion of this thread to minimize my disgrace...
Glad you figured it out. Unfortunately I can't delete topics, but I guess the code you posted will still help others.
is working on a reply...