Current Shopping Cart Product(s) URL

Les Girvan asked on March 5, 2021 14:16

As part of a integration, we need to capture details of the current shopping cart. I have been able to get products image URL's by using `{% GetAbsoluteUrl(ECommerceContext.CurrentShoppingCart.ContentTable[0].SKUImagePath) #%}

But I cannot seem to be able to get the product URL, can you advise the Macro method that would allow me to get the product URL, I have gone through the methods (would be great if you could search through methods) but not been able to find a method to resolve the URL.

I am pretty sure its got to be the NodeAliasPath? but have tried this and many alternatives, of which nothing is resolved:

`{% ECommerceContext.CurrentShoppingCart.CartProducts[0].SKU.URLReferrer #%}' or '{% ECommerceContext.CurrentShoppingCart.CartProducts[0].SKU.NodeAliasPath #%}'

Can you advise?

Regards Les

Recent Answers


Brian McKeiver answered on March 5, 2021 17:55

I believe that you can get the SKUID from the ShoppingCartItem in the cart, but then you have to look up the product page (for the URL) based on a document's NodeSkuID (WHERE NodeSKUID = SKUID), a custom macro method might be needed for this.

Reference: https://docs.xperience.io/k11/developing-websites/developing-sites-using-asp-net-mvc/developing-on-line-stores-in-mvc/displaying-product-details-on-mvc-sites#DisplayingproductdetailsonMVCsites-GettingURLsofproducts

0 votesVote for this answer Mark as a Correct answer

Les Girvan answered on March 5, 2021 18:05 (last edited on March 5, 2021 18:07)

Hi Brian, thanks for that, I am using Portal engine in V11x, is this the same method I would use? I don't really want to go do the route of making a custom macro, as this is the only item we cannot get from the methods available, I am pretty sure there is a way to get this without resorting to a custom macro?

Regards Les

0 votesVote for this answer Mark as a Correct answer

Brian McKeiver answered on March 5, 2021 18:17

There is, but it is not great from a performance standpoint. You could access the CMSContext.Current.SiteObjects.Documents["NodeSkuID = 1"] and replace the 1 with your skuid. To be honest I did not fully test that though. Again not performant at scale.

0 votesVote for this answer Mark as a Correct answer

David te Kloese answered on March 5, 2021 21:42

I believe you could just use the following macro

{% GetProductUrl(SKUID) %}

See the macro methods available in K11 in the docs here:

docs.xperience.io/k11/macro-expressions/reference-macro-methods

0 votesVote for this answer Mark as a Correct answer

Brian McKeiver answered on March 6, 2021 15:44 (last edited on March 6, 2021 15:47)

@DTK - yeah nice find, looks like it is in there just like that. So it would be:

{% GetProductUrl(ECommerceContext.CurrentShoppingCart.ShoppingCartItems[0].SKUID) %}

0 votesVote for this answer Mark as a Correct answer

Les Girvan answered on March 11, 2021 01:14

Hi Guys, Thanks for that feedback, however, trying the suggestions, they only resolve the CMS page path of the path with the SKUID:

A {% GetProductUrl(SKUID) %} = /CMSPages/Ecommerce/GetProduct.aspx?productId=

B {% GetProductUrl(ECommerceContext.CurrentShoppingCart.ShoppingCartItems[0].SKUID) %}  = /CMSPages/Ecommerce/GetProduct.aspx?productId=7232

However, it did give me an idea to create variables to get the URL path, first getting the SKUID, the a second variable to get the URL based on the SKUID value, but cannot figure out how I structure the 2nd variable, I have currently got:

{% prodID = (ECommerceContext.CurrentShoppingCart.ShoppingCartItems[0].SKUID) #%}
{% produURL = GetAbsoluteUrl(Documents.FieldsAsObjects.NodeSKUID(prodID) #%}`

which is resolving only the SKUID:

"URL" : [""]
"ID" : ["7232"]

just cannot figure out the way to now use the SKUID to pull back the absoluteURL!

Regards Les

0 votesVote for this answer Mark as a Correct answer

Les Girvan answered on March 11, 2021 01:33

Sorry, I have also tried on it's own:

{% GetAbsoluteUrl(ECommerceContext.CurrentShoppingCart.ShoppingCartItems[0].SKU.SKUName) #%}

However, this resolves as:

"https://bch.dgsnet.co.uk/CMSPages/Bhutan GTX MFS: 12"

Whilst the correct product, its not he correct URL :(

Regards Les

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.