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.

  • Christian Rieß 24 posts 46 karma points
    Oct 28, 2011 @ 17:23
    Christian Rieß
    0

    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?

  • Christian Rieß 24 posts 46 karma points
    Oct 28, 2011 @ 17:25
    Christian Rieß
    0

    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;

  • Christian Rieß 24 posts 46 karma points
    Oct 28, 2011 @ 17:41
    Christian Rieß
    0

    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...

  • Søren Spelling Lund 1797 posts 2786 karma points
    Nov 07, 2011 @ 16:41
    Søren Spelling Lund
    0

    Glad you figured it out. Unfortunately I can't delete topics, but I guess the code you posted will still help others.

Please Sign in or register to post replies

Write your reply to:

Draft