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.
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.
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=¤cy=EUR&lang=nl-BE
These are the methods you requested:
public static void AddToBasket( int qty, Product product ) { var hadBasket = HasBasket;
// Set Addresses on creation (if user is logged in) if( !hadBasket && CustomerService.Current() != null ) { var billing = CustomerService.GetBillingAddress(); var shipping = CustomerService.GetShippingAddress();
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.
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
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=¤cy=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();
}
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
is working on a reply...