Developer forum

Forum » Development » Problem assigning OrderLine to a cart DW8

Problem assigning OrderLine to a cart DW8

Dmitrij Jazel
Reply
Hello DW guys,
I have a question here, And I am not sure what can cause the problem...
I am trying to add a product to a shopping cart, eventually I am receiving this (null pointer exception)

ErrorAssigningOrderLine System.NullReferenceException: Object reference not set to an instance of an object. at Dynamicweb.eCommerce.Orders.Order.CreateOrderLine(Product product, Double quantity, StockUnit unit) at Dynamicweb.eCommerce.Orders.Order.CreateOrderLine(Product product) at SkabelonModule.loadTheCart(String userName, String templateName) in C:\Projects\dw8CM1\CustomModules\SkabelonModule\SkabelonModule.cs:line 1127

I am trying to see if I am getting the exception while retrieving the product itself with:
Product myproduct = Product.GetProductByID(prod.getProdID());
But it works fine, Product is not null, it is loaded, and I can retrieve other values through that Product and they correspond to real values. 
So I am really surprised why there is a problem to assign a product to cart order line.

Eventually in the frontend, I can see it re-initiated the cart, as it should, but the cart is simply empty.

Here is the implementation of the method:
(see the attachment)

Any suggestions?

Kind regards,
Dmitrij


Replies

 
Jeppe Eriksson Agger Dynamicweb Employee
Jeppe Eriksson Agger
Reply

Hi Dmitrij

If you read the thread conversation we had about new prefilled cart for users here: http://developer.dynamicweb-cms.com/forum/development/initiate-new-cart/order-and-full-it-products.aspx
you'll see that I mention a bug in CreateOrderLine. This is that bug. Either wait until the next release of DW8.0 or create your own CreateOrderLine method, which I also included the code for in that thread.

- Jeppe

 
Dmitrij Jazel
Reply
Naaahhh... so that was it? Ahh, what a pity.
Yes, I was trying to get the most of the that post, but now I got it :-)
Did not expect to get the bug just like that...

Oh well... thanks atleast for that :-)
Than could I know when the next release is coming?

I hope you do not mind if I would continue to discuss the issues related with this specific method in this thread, if any of the issues associated with it would arrise?

Thanks again,
Dmitrij
 
Jeppe Eriksson Agger Dynamicweb Employee
Jeppe Eriksson Agger
Reply

Currently we haven't slated the next release of DW8.0 but DW8.1--where it's also fixed--will be released on May 29th.

 
Dmitrij Jazel
Reply
Hi Jeppe,
I wish I could bring some good news but instead...
I Wanted to know if all is fine with this method 
var newcart = Dynamicweb.eCommerce.Orders.Order()
newCart.CreateOrderLine(myproduct);


Not sure is it am I doing something wrong here, or is it still a buggy method?

I will reference A - a product I add with this function that I must use in custom module. and B - is normal standard product I add with normal product catalog (This one works fine - absolutely no problem what's so ever).

The problem is that when I am using this method newCart.CreateOrderLine(myproduct);, the product A is added to the cart (in my own special way that I am trying to implement here)...
It looks like it that it is added. but...
It can be seen in the initial little cart at the sidebar.
But strangely enough A cannot be seen in Show cart step of the cart module.

Than I go back and add product B to the cart in normal product catalog - than I see both A and B in the little cart. But only B in the show cart step.
Than if I continue to information - A shows up again there together with B as it should be. Only thing is that A has no orderline controll buttons like Add remove or delete... 

Than eventually if I continue with process and send order - than I see both B and A with products just purchased.
But than Dynamicweb.Notifications.eCommerce.Cart.OrderIsPassedToCheckoutHandlerArgs myArgs = (Dynamicweb.Notifications.eCommerce.Cart.OrderIsPassedToCheckoutHandlerArgs)args;  cannot see A among products Dynamicweb.eCommerce.Products.ProductCollection productCollection  from myArgs.Order.Products and or  that this args are supposed to contain.
Instead B is found but A is not.

Any idea what can be wrong? this is how I am using it... I am attaching my Checkout handler code - that registers the content of cart at checkout
and I also send my method that adds product to the cart...

And even if I add a product with  var myProduct = Dynamicweb.eCommerce.Products.Product.GetAllProducts()[0];
newCart.CreateOrderLine(myProduct); It is still the same...

Any suggestions? 
So it indicates that something might still be wrong with .CreateOrderLine(myProduct); method.

I attach my implementation of add to cart method... and also checkout handler (the args that cannot see the product) etc...

Hope this helps.
Kind regards,
Dmitrij

 
Jeppe Eriksson Agger Dynamicweb Employee
Jeppe Eriksson Agger
Reply

Hi Dmitrij

The reason that A does not work properly for you is that the product you add does not exist in the database. You have to call the Save method on the product before creating the OrderLine. That way the product is persisted to the database the Cart Load subsystem will be able to persist the OrderLine and retrieve it again.


- Jeppe
 
Dmitrij Jazel
Reply
Hej Jeppe,

And thanks for quick response ;-)
Well the issue still remains...

I call the .Save(); method right after I request the item from the Database, So it should persist.
I attach the implementation...

At the same time maybe some basic example could could do the trick...
All I need to do is add a product to the new cart. Persist Cart and product in it. So it would be seen in all steps of the cart...
Now with this new method, it should be easy as Pi to do it...

Regards,
Dmitrij

 
Jeppe Eriksson Agger Dynamicweb Employee
Jeppe Eriksson Agger
Reply

Hi Dmitrij

I've taken a closer look at the code and there is indeed an issue with the CreateOrderLine. It will be fixed in the next release (DW 8.1.1) but it's also very easy for you to fix temporarily until the fix is out. Note that this workaround does not have any impact once our fix is released.

 var ol = newCart.CreateOrderLine(myproduct);
 ol.Type = ((int)Dynamicweb.eCommerce.Orders.OrderLine.OrderLineType.Product).ToString();

If you wanted to pass in your own price, ie. using the CreateOrderLine overload that takes a UnitPrice, then you'd probably want to use this instead.
 var ol = newCart.CreateOrderLine(myproduct, 1.0, null, myPrice);
 ol.Type = ((int)Dynamicweb.eCommerce.Orders.OrderLine.OrderLineType.Fixed).ToString();

Hope this helps :)

- Jeppe

 

You must be logged in to post in the forum