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.

  • K.Garrein 164 posts 629 karma points
    Mar 18, 2014 @ 11:19
    K.Garrein
    0

    Shopping basket always empty after postback

    Hey.

    I inherited a uCommerce project from a company that stopped it's collaboration with another developer.

    I copied the entire website from the live environment to my workstation to create a development/staging setup.
    (This included the production uCommerce license)

    The webshop catalog seems to be running fine that way.

    The shopping basket however is not working on my local setup (it works fine on the production site).
    If I click "add to cart", then in the code that executes, a product is indeed added to a shopping basket.
    However, after navigating to another page, the shopping basket is empty again...

    I can't imagine for the life of me what's wrong.
    I figured it must have had something to do with the production license, but after replacing it with a developer license the problem remains.

    Anybody has any suggestions or experience?

    Thank you very much.
    Regards.
    Kris


    *edit 18/03/2014 13:05*
    Extra info: when looking in the database, it seems like a new shopping basket is created every time I add a product to a shopping basket.

  • Morten Skjoldager 440 posts 1499 karma points
    Mar 18, 2014 @ 13:37
    Morten Skjoldager
    0

    Hello K :) 

    It has nothing to do with the license. When working with a local setup, just remove the license file and you're good to go.

    Baskets are persisted as a cookie on your computer with a link to the order in the dabase. You need to find out which PurchaseOrder belongs to your basket (try clearing your cookies and start over). A new order in uCommerce_PurchaseOrder should appear in the database. Take a look at those OrderLines.

    If you get a new basket every time the answer must be that some where in your code you forces a new basket somehow. Can you show me some code related to AddToBasket.

    Best regards

    Morten

  • K.Garrein 164 posts 629 karma points
    Mar 18, 2014 @ 14:12
    K.Garrein
    0

    Remember, in the production environment the shopping basket works fine (identical code).
    On my workstation I can't get it to work.

    The cookie gets a "viewed list", but the basket remains empty:
    viewedProductsList=b99440f3-a9e1-4c2b-9318-7745c1d6bcef&basket=&country=&currency=EUR&lang=nl-BE 

    These are the methods you requested: 

    public static void AddToBasket( int qty, Product product )
           {
               var hadBasket = HasBasket;

                // Add to basket
               TransactionLibrary.AddToBasket( qty, product.Sku, product.VariantSku, true, false );

                // Set Addresses on creation (if user is logged in)
               if( !hadBasket && CustomerService.Current() != null )
               {
                   var billing = CustomerService.GetBillingAddress();
                   var shipping = CustomerService.GetShippingAddress();

                    if( billing != null )
                       SetBilling( billing, false );

                    if( shipping != null )
                       SetShipping( shipping, false );

                    if( shipping == null && billing != null )
                       SetShipping( billing, false );
               }

                // Update OrderLine
               var orderLine = Basket.PurchaseOrder.OrderLines.First( x => x.VariantSku == product.VariantSku );
               orderLine.ProductName = product.Name;

                var options = new List();
               for( var i = 1; i < 5; i++ )
               {
                   if( product.GetProperty( "Option" + i + "Value", System.Threading.Thread.CurrentThread.CurrentCulture.Name ) != null && !string.IsNullOrWhiteSpace( product.GetProperty( "Option" + i + "Value", System.Threading.Thread.CurrentThread.CurrentCulture.Name ).GetValue().ToString() ) )
                   {
                       options.Add( product.GetProperty( "Option" + i + "Value", System.Threading.Thread.CurrentThread.CurrentCulture.Name ).GetValue().ToString() );
                   }
               }

                orderLine[ "description" ] = string.Join( ", ", options );
               orderLine.Save();

                Update();
           }

    public static void Update()
           {
               var basket = Basket;
               if( basket == null )
                   return;

                var order = basket.PurchaseOrder;
     
               // Billing
               if( order.BillingAddress == null )
               {
                   var cAddress = CustomerService.GetBillingAddress();
                   if( cAddress == null )
                   {
                       order.BillingAddress = new OrderAddress()
                       {
                           PurchaseOrder = order,
                           Country = PreferencesServices.Country,
                           AddressName = "",
                           Attention = "",
                           City = "",
                           CompanyName = "",
                           EmailAddress = "",
                           FirstName = "",
                           LastName = "",
                           Line1 = "",
                           Line2 = "",
                           PostalCode = "",
                           MobilePhoneNumber = "",
                           PhoneNumber = ""
                       };
                   }
                   else
                   {
                       SetBilling( cAddress, false );
                   }
               }

                // Mark professional
               order.IsProfessional( CustomerService.IsProfessional );

                // Ensure Shipping
               UpdateShipping(); 

                // Update Payment
               UpdatePayment();

                TransactionLibrary.ExecuteBasketPipeline();
           }

     

  • K.Garrein 164 posts 629 karma points
    Mar 18, 2014 @ 14:52
    K.Garrein
    100

    Finally solved it :'(

    Apparently the site expected SSL (which I don't have on my local version).
    I changed a web.config application setting and it is working now :-)

    <add key="HOL.Cookies.Secure" value="false" />

    Thank you for your help.
    Kind regards.
    Kris 

Please Sign in or register to post replies

Write your reply to:

Draft