Developer forum

Forum » Development » Access to the current Cart context

Access to the current Cart context

Anders Ebdrup
Reply

Hi Dynamicweb,

 

In our solution we rely on a lot of information on the current cart which depends on the OrderContext, but we have an issue getting access to the different carts based on the OrderContext.

The only way to get access to the ordercontext (as I see it) is by setting the CartContext property in context.vb. The set-part in the property is however not public...

        Public Shared Property CartContext As OrderContext
            Get
                'Get context if it has been set explicitly
                Dim contextCandidate As Object = HttpContext.Current.Items(_customCartContextSessionKey)
                If contextCandidate IsNot Nothing Then
                    Return DirectCast(contextCandidate, OrderContext)
                End If

                'Get context from Request
                Dim context As OrderContext = Nothing
                Try
                    'Try-catch because of the unpredictable behavior of HttpContext.Current.Request
                    context = OrderContext.GetOrderContextById(Input.Request(OrderContext.OrderContextRequestName))
                Catch ex As Exception
                End Try

                'Get default context for the current shop
                If context Is Nothing Then
                    Dim pageview As Dynamicweb.Frontend.PageView = Dynamicweb.Frontend.PageView.Current
                    If pageview IsNot Nothing AndAlso pageview.Area IsNot Nothing Then
                        Dim area As Dynamicweb.Content.Area = If(Dynamicweb.Content.Area.GetAreaById(pageview.Area.ID), New Content.Area())
                        Dim shop As Shops.Shop = Application.Shop(area.EcomShopID)
                        If shop IsNot Nothing Then
                            context = OrderContext.GetOrderContextById(shop.OrderContextID)
                        End If
                    End If
                End If

                'Return the context. If no context was found, Nothing is returned indicating that we fall back to the global cart.
                Return context
            End Get
            Friend Set(value As OrderContext)
                HttpContext.Current.Items(_customCartContextSessionKey) = value
            End Set
        End Property

 

So what to do? :-)

 

Best regards, Anders

 


Replies

 
Nicolai Høeg Pedersen
Reply

We will make it public!

BR Nicolai

 
Anders Ebdrup
Reply

Great, thank you. Can this be in the next hotfix to 8.8.1?

 
Nicolai Høeg Pedersen
Reply

TFS#25251, ready with next hotfix.

 
Kristian Kirkholt Dynamicweb Employee
Kristian Kirkholt
Reply

Hi Anders

The problem TFS#25230 "CartContext should be public"  has now been fixed in version 8.8.1.15

You are able to find this build in the download section:

http://doc.dynamicweb.com/releases-and-downloads/latest-releases

Please contact Dynamicweb Support if you need any additional help regarding this.

Kind Regards

Dynamicweb Support

Kristian Kirkholt

 

You must be logged in to post in the forum