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.

  • Alex Skrypnyk 6147 posts 24056 karma points MVP 8x admin c-trib
    Sep 24, 2012 @ 13:12
    Alex Skrypnyk
    0

    System.NullReferenceException

    Hi,

    I can't create simple order.

    int catalogId = 0;
                    string catalogName = "whiteport.com";
                    ProductCatalog catalog;
                    SiteContext.Current.OrderContext.NewBasket(Currency.SingleOrDefault(x => x.ExchangeRate == 100));
                    if (int.TryParse(SiteContext.Current.CatalogContext.CurrentCatalogName, out catalogId))
                        catalog = ProductCatalog.Get(catalogId);
                    else
                        catalog = ProductCatalog.SingleOrDefault(x => x.Name == catalogName);
                    // Then load the product to add
                    Product product = Product.All().Single(x => x.Sku == "Small Subscription");
                    Basket basket = SiteContext.Current.OrderContext.GetBasket();
                    PurchaseOrder purchaseOrder = basket.PurchaseOrder;
                    purchaseOrder.AddProduct(catalog, product, 1, true);
    purchaseOrder.AddProduct(catalog, product, 1, true);

     

    this line allways crashed, I don't understand why.
    Please, help.
    Thanks.

  • Søren Spelling Lund 1797 posts 2786 karma points
    Sep 24, 2012 @ 13:36
    Søren Spelling Lund
    0

    Hi Alex,

    Could you post the exception you're seeing?

  • Søren Spelling Lund 1797 posts 2786 karma points
    Sep 24, 2012 @ 13:37
    Søren Spelling Lund
    0

    Doh. Just noticed the topic :)

    Which version are you using?

  • Alex Skrypnyk 6147 posts 24056 karma points MVP 8x admin c-trib
    Sep 24, 2012 @ 13:40
    Alex Skrypnyk
    0

    Object reference not set to an instance of an object.

    
                  Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

    Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

    Source Error:

    Line 68:                 PurchaseOrder purchaseOrder = basket.PurchaseOrder;
    Line 69: 
    Line 70: purchaseOrder.AddProduct(catalog, product, 1, true); Line 71: 
    Line 72:                 // Exec basket pipeline to update totals

    Stack Trace:

    [NullReferenceException: Object reference not set to an instance of an object.]
       UCommerce.EntitiesV2.PurchaseOrder.AddProduct(ProductCatalog catalog, Product product, Int32 quantity, Boolean addToExistingLine) +206
       Whitebox.WebSiteCard.usercontrols.ProductsCatalog.btnBuySmall_Click(Object sender, EventArgs e) in c:\work\Angner Marten\WhiteBox\trunk\WebSiteCard\usercontrols\ProductsCatalog.ascx.cs:70
       System.Web.UI.WebControls.LinkButton.RaisePostBackEvent(String eventArgument) +152
       System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3803
    
  • Alex Skrypnyk 6147 posts 24056 karma points MVP 8x admin c-trib
    Sep 24, 2012 @ 13:48
    Alex Skrypnyk
    0

    umbraco v 4.7.2

    uCommerce 2.6.1.0

  • Alex Skrypnyk 6147 posts 24056 karma points MVP 8x admin c-trib
    Sep 24, 2012 @ 15:42
    Alex Skrypnyk
    0

    Please, help I'm at a dead end. )

  • Alex Skrypnyk 6147 posts 24056 karma points MVP 8x admin c-trib
    Sep 24, 2012 @ 15:50
    Alex Skrypnyk
    0

    Object Customer allways is null. 

  • Søren Spelling Lund 1797 posts 2786 karma points
    Sep 26, 2012 @ 09:31
    Søren Spelling Lund
    1

    Could you zip up the site + DB and send it to me so I can take a closer look?

    ssl AT ucommerce DOT dk

    Thanks.

  • Alex Skrypnyk 6147 posts 24056 karma points MVP 8x admin c-trib
    Sep 26, 2012 @ 15:42
    Alex Skrypnyk
    0

    Hi Soren,

    We solve problem with crash, now we have worked PayPal payment. But,

    Orders doesn't appears in ucommerce admin part,

    Code of order creation : 

     

                    catalog = ProductCatalog.Get(catalogId);
    
                    SiteContext.Current.CatalogContext.CurrentCatalogName = catalog.Name;
    
                    Product product = Product.Get(Convert.ToInt32(e.CommandArgument));
    
                    Basket basket = SiteContext.Current.OrderContext.NewBasket(Currency.FirstOrDefault(x => x.ExchangeRate == 100));
    
                    PurchaseOrder purchaseOrder = basket.PurchaseOrder;
    
                    purchaseOrder.AddProduct(catalog, product, 1);
    
                    var userService = new UserService();
                    var profile = userService.GetCurrentUserProfile();
    
                    Library.ExecuteBasketPipeline();
    
                    var address = purchaseOrder.BillingAddress ?? new OrderAddress();
                    address.AddressName = "Billing";
                    address.FirstName = profile.FirstName;
                    address.LastName = profile.LastName;
                    address.EmailAddress = profile.UserName;
                    address.PhoneNumber = profile.PhoneNumber;
                    address.MobilePhoneNumber = "mobilePhoneNumber";
                    address.CompanyName = "company";
                    address.Line1 = "line1";
                    address.Line2 = "line2";
                    address.PostalCode = profile.Zip;
                    address.City = profile.City;
                    address.State = profile.State;
                    address.Country = Country.FirstOrDefault(x => x.Name == "Great Britain");
                    address.PurchaseOrder = purchaseOrder;
    
                    Customer customer = Customer.Create(address);
    
                    purchaseOrder.Customer = customer;
                    purchaseOrder.BillingAddress = address;
                    purchaseOrder.Save(); // Saves cascade to children, so the address is saved as well
    
                    var paymentMethod = PaymentMethod.All().Single(x => x.Name == "PayPal");
    
                    var service = paymentMethod.GetPaymentMethodService();
    
                    var paymentFactory = paymentMethod.GetPaymentMethodService() as IPaymentFactory;
                    Payment payment = paymentFactory.CreatePayment(new PaymentRequest(purchaseOrder, paymentMethod,
                      new Money(purchaseOrder.OrderTotal.Value, purchaseOrder.BillingCurrency)));
    
                    payment.Save();
    
                    payment = service.RequestPayment(new PaymentRequest(purchaseOrder, paymentMethod,
                      new Money(purchaseOrder.OrderTotal.Value, purchaseOrder.BillingCurrency)));
    

    Please help us ))

     

    Thanks,

    Alexandr

  • Søren Spelling Lund 1797 posts 2786 karma points
    Oct 01, 2012 @ 11:39
    Søren Spelling Lund
    0

    Do you have the Checkout pipeline configured on the PayPal payment method?

    Is the server the store is running on accessible from the internet (PayPal needs this to perform callback when the payment is approved).

Please Sign in or register to post replies

Write your reply to:

Draft