Tried everything but still getting error message: "The product doesn't have a store id associated with it"
Hello, anyone or everyone who could please help me out here.
I have asked this question on an old post but was not sure if it would be seen as it is already answered. Please forgive me if this is doubling up. I'm just quite desperate for a solution:
When I run the following code I get the error: "The product doesn't have a store id associated with it - remember to add the Tea Commerce store picker to your Umbraco content tree":
The values in the parameters are correct. I've executed this exact same line of code on earlier version of Umbraco/Tea Commerce and not had this problem.
I've seen other similar issues reported and have seen the suggestion to check all Store settings especially the defaults. I have done this, it hasn't helped.
Umbraco V 7.12.4 (installed via nuget)
Tea Commerce V 3.2.5
My site structure is slightly different to usual. However, I've also tested this with the more normal structure. In both cases I get that same error message.
Current Site Structure
Content
Home (With store picker (testing)
Category 1
Category 2
Data
Products (With store picker (testing)
Product 1 (Assigned to categories via multi tree picker)
Product 2
Both store pickers have the alias "store".
Products are assigned to categories via a multiple tree picker. Products are indexed into a custom index.
I am then using a IContentFinder that sets the request.PublishedContent to the appropriate product based on a search of the index using the request url.
This all works perfectly. If Product 1 is assigned to Category 1 Umbraco behaves as expected. For example: If browsing to: SiteDomain/Category-1/Product-1/ Umbraco renders the correct layout populated with all the correct data from the product doc type. Including Tea Commerce Variations that have a custom doctype set with extra data. All this is working. This very similar call works without a problem:
I thought something may be going wrong due to the product nodes being outside the main site content tree, that is why I placed the store picker on both the Home and Data>Products nodes. Didn't help. Ideally I would like only one store picker being on the Products node.
I then tested adding one of my Product docTypes/pages directly beneath a category page under the main site tree. I expected this to work. But it didn't. I get the same error. (This is not really an option, I just tried it for testing purposes)
I'm at a complete loss as to where the problem is and I'm pretty stressed about it to be honest.
If you comment out the line TC.GetStock(...); does the page start to work? I have the feeling you might have some other code some place looking up a StoreId as that error should only come from that call
Out of interest, how is SiteContext.Current.WebStoreGlobalSettings.StoreId populated? Is this a hard coded constant? Or does a lookup occur? as if it's the later, that could be your culprit.
Yes, if I comment out that line, the page does work. Including retrieving variant information for the product via the TC API.
I tried replacing that line with a call to TC.GetStore() passing in that same storeid stored in that same property and that call didn't crash!
With regards to your other query : yes I do look it up. I have a StoreSettings node that sits beneath content in umbraco (not beneath home). It has a store picker property on it. I retrieve the value along with a whole lot of other stuff and put it into a request scoped variable.
I will hard code this and see if it makes a difference. If it does, do you think could still retrieve the storeid with a store picker but give it a different alias?
I am in New Zealand and it is after mid night so I'll get back to you in a few hours with some results.
Thanks again Matt, I really appreciate the assistance.
I'd try with a hard coded ID just to try and rule that one out.
In terms of the store property for TC to pick it up, the alias needs to be "store" so it's probably worth checking that. If you are fetching it yourself, it might be ok to name it something different, but it just depends if any internal code does it's own lookup assuming the "store" alias.
Give the error comes from a GetStore call, I'd try and rule out that coming from any other location first (ie, remove any other calls from your request untill the only TC call being made is the TC.GetStock) and see if you can pinpoint the call that is having the problem.
If you are creating SiteContext yourself, you might want to put a breakpoint in there somewhere too to make sure the SiteId is being fetched / set correctly.
So I've gone into my code base to make these changes and have kind of hit a snag because I'm really already doing that.
SiteContext.Current.WebStoreGlobalSettings.StoreId is set at the start of each request by normal umbraco getproperty methods. The alias is "store".
The value is set to "1". Which is correct. I only have one Store set up in TC.
The only other call that uses the TC API is in an object that wraps a product content node. I have a property that gets all assigned variants. It calls:
TC.GetVariants(SiteContext.Current.WebStoreGlobalSettings.StoreId, UmbracoContent, true)
This works. TC gets me the correct list of VariantPublishedContent.
It is on items in this list of variant content i'm trying to get the stock for.
On a variant I can call: variantContent.Combination and TC gives me the correct specifications with the correct attribute groups and values. variantContent also has all the properties populated correctly that come from my variant doctype.
But, when I call: TC.GetStock(SiteContext.Current.WebStoreGlobalSettings.StoreId, variantContent.VariantIdentifier);
I get the error described in intial post.
I had a look at the code you referenced: PublishedContentProductInformationExtractor.cs#L102
It looks like that is recursively looking up the tree from the product node looking for a store picker. In my situation I do have that. Data>Products does have a store picker with the alias "store". I don't kno why it doesn't pick it up.
As seen in the source code Matt linked to, the GetStoreId method will also throw the same ArgumentException ("The product doesn't have a store id associated with it") if the product parameter is null or is referencing something that is not a "product". So that could be something to look into.
But, as far as I can see/understand, there's no call from inside GetStock to GetStoreId (you already have the Id), so that's confusing. Are you sure the exception is thrown from inside the GetStock call, and not from code executed after the return from GetStock?
Crisis averted, I have just got it to work and was popping on here to let you and Matt know.
I think you were on to something with your most recent comment.
I have changed it to use this overload:
var stock = TC.GetStock(SiteContext.Current.WebStoreGlobalSettings.StoreId, Product.UmbracoContent, VariantPublishedContent);
That worked perfectly.
On my previous projects I've simply passed in StoreId and VariantPublishedContent.ProductIdentifier to the GetStock method.
But with this project I'm working on now (most recent TC package) there doesn't seem to be a property for "ProductIdentifier" on the VariantPublishedContent object. The name spaces seem slightly different too. I might be missing something though...
There is now a "VariantIdentifier" property on that object. I tried passing that in, I tried passing the sku value in, I tried passing in the Id property all from the VariantPublishedContent. None worked and all failed with that same error about the store.
Anyway, it is sorted now. Thank you very much for trying to help me out! It really is nice to know that with umbraco you aren't all on your lonesome when things go wrong!
No problem. I think by the looks of it, Tor and I helped, but I think it's your own post around using the GetStock method with the additional VariantPublishedContent paramter which is the real answer. If you can mark your own post as answer, I'd probably be tempted to do that rather marking either mine or Tors as I think that's the information others with the same problem would be looking for.
If marking your own post as answer isn't possible, then I'd probably leave it open.
Tried everything but still getting error message: "The product doesn't have a store id associated with it"
Hello, anyone or everyone who could please help me out here.
I have asked this question on an old post but was not sure if it would be seen as it is already answered. Please forgive me if this is doubling up. I'm just quite desperate for a solution:
When I run the following code I get the error: "The product doesn't have a store id associated with it - remember to add the Tea Commerce store picker to your Umbraco content tree":
TC.GetStock(SiteContext.Current.WebStoreGlobalSettings.StoreId, ProductVariantId);
The values in the parameters are correct. I've executed this exact same line of code on earlier version of Umbraco/Tea Commerce and not had this problem.
I've seen other similar issues reported and have seen the suggestion to check all Store settings especially the defaults. I have done this, it hasn't helped.
Umbraco V 7.12.4 (installed via nuget) Tea Commerce V 3.2.5
My site structure is slightly different to usual. However, I've also tested this with the more normal structure. In both cases I get that same error message.
Current Site Structure
Both store pickers have the alias "store".
Products are assigned to categories via a multiple tree picker. Products are indexed into a custom index.
I am then using a IContentFinder that sets the request.PublishedContent to the appropriate product based on a search of the index using the request url.
This all works perfectly. If Product 1 is assigned to Category 1 Umbraco behaves as expected. For example: If browsing to: SiteDomain/Category-1/Product-1/ Umbraco renders the correct layout populated with all the correct data from the product doc type. Including Tea Commerce Variations that have a custom doctype set with extra data. All this is working. This very similar call works without a problem:
TC.GetVariants(SiteContext.Current.WebStoreGlobalSettings.StoreId, UmbracoContent, true)
I thought something may be going wrong due to the product nodes being outside the main site content tree, that is why I placed the store picker on both the Home and Data>Products nodes. Didn't help. Ideally I would like only one store picker being on the Products node.
I then tested adding one of my Product docTypes/pages directly beneath a category page under the main site tree. I expected this to work. But it didn't. I get the same error. (This is not really an option, I just tried it for testing purposes)
I'm at a complete loss as to where the problem is and I'm pretty stressed about it to be honest.
Any assistance would be hugely appreciated!!!
Thank you in advance. Dean
Hi Dean,
Hmm, that's an interesting one.
If you comment out the line TC.GetStock(...); does the page start to work? I have the feeling you might have some other code some place looking up a StoreId as that error should only come from that call
https://github.com/TeaCommerce/Tea-Commerce-for-Umbraco/blob/770705bdea8f20fd9e146c27724c9a830454c8e0/Source/TeaCommerce.Umbraco.Configuration/InformationExtractors/PublishedContentProductInformationExtractor.cs#L102
Out of interest, how is SiteContext.Current.WebStoreGlobalSettings.StoreId populated? Is this a hard coded constant? Or does a lookup occur? as if it's the later, that could be your culprit.
Hope this helps.
Matt
Hello Matt Thanks for your response.
Yes, if I comment out that line, the page does work. Including retrieving variant information for the product via the TC API.
I tried replacing that line with a call to TC.GetStore() passing in that same storeid stored in that same property and that call didn't crash!
With regards to your other query : yes I do look it up. I have a StoreSettings node that sits beneath content in umbraco (not beneath home). It has a store picker property on it. I retrieve the value along with a whole lot of other stuff and put it into a request scoped variable.
I will hard code this and see if it makes a difference. If it does, do you think could still retrieve the storeid with a store picker but give it a different alias?
I am in New Zealand and it is after mid night so I'll get back to you in a few hours with some results.
Thanks again Matt, I really appreciate the assistance.
Hi Dean,
I'd try with a hard coded ID just to try and rule that one out.
In terms of the store property for TC to pick it up, the alias needs to be "store" so it's probably worth checking that. If you are fetching it yourself, it might be ok to name it something different, but it just depends if any internal code does it's own lookup assuming the "store" alias.
Give the error comes from a GetStore call, I'd try and rule out that coming from any other location first (ie, remove any other calls from your request untill the only TC call being made is the TC.GetStock) and see if you can pinpoint the call that is having the problem.
If you are creating SiteContext yourself, you might want to put a breakpoint in there somewhere too to make sure the SiteId is being fetched / set correctly.
Hope these help.
Matt
Hi Matt,
So I've gone into my code base to make these changes and have kind of hit a snag because I'm really already doing that.
SiteContext.Current.WebStoreGlobalSettings.StoreId is set at the start of each request by normal umbraco getproperty methods. The alias is "store".
The value is set to "1". Which is correct. I only have one Store set up in TC.
The only other call that uses the TC API is in an object that wraps a product content node. I have a property that gets all assigned variants. It calls: TC.GetVariants(SiteContext.Current.WebStoreGlobalSettings.StoreId, UmbracoContent, true)
This works. TC gets me the correct list of VariantPublishedContent.
It is on items in this list of variant content i'm trying to get the stock for.
On a variant I can call: variantContent.Combination and TC gives me the correct specifications with the correct attribute groups and values. variantContent also has all the properties populated correctly that come from my variant doctype.
But, when I call: TC.GetStock(SiteContext.Current.WebStoreGlobalSettings.StoreId, variantContent.VariantIdentifier);
I get the error described in intial post.
I had a look at the code you referenced: PublishedContentProductInformationExtractor.cs#L102
It looks like that is recursively looking up the tree from the product node looking for a store picker. In my situation I do have that. Data>Products does have a store picker with the alias "store". I don't kno why it doesn't pick it up.
This is the other post I thought might be related. Could this be the same issue: https://our.umbraco.com/packages/website-utilities/tea-commerce/tea-commerce-support/90441-issue-with-teacommerce-on-umbraco-cloud-version-7710
Thanks again!
Hi Matt, New important discovery.
I removed the TC.GetStock call from the Variant. Page started working.
I then added TC.GetStock call for the product itself and attempted to render this on the page. This worked!!!
So the product knows about the store. But not it's variants.
My variant doc type has a sku field, and a stock field. Both have values set.
Now I'm really lost!
As seen in the source code Matt linked to, the GetStoreId method will also throw the same ArgumentException ("The product doesn't have a store id associated with it") if the product parameter is null or is referencing something that is not a "product". So that could be something to look into.
But, as far as I can see/understand, there's no call from inside GetStock to GetStoreId (you already have the Id), so that's confusing. Are you sure the exception is thrown from inside the GetStock call, and not from code executed after the return from GetStock?
Hello Tor,
Crisis averted, I have just got it to work and was popping on here to let you and Matt know.
I think you were on to something with your most recent comment.
I have changed it to use this overload: var stock = TC.GetStock(SiteContext.Current.WebStoreGlobalSettings.StoreId, Product.UmbracoContent, VariantPublishedContent);
That worked perfectly.
On my previous projects I've simply passed in StoreId and VariantPublishedContent.ProductIdentifier to the GetStock method.
But with this project I'm working on now (most recent TC package) there doesn't seem to be a property for "ProductIdentifier" on the VariantPublishedContent object. The name spaces seem slightly different too. I might be missing something though...
There is now a "VariantIdentifier" property on that object. I tried passing that in, I tried passing the sku value in, I tried passing in the Id property all from the VariantPublishedContent. None worked and all failed with that same error about the store.
Anyway, it is sorted now. Thank you very much for trying to help me out! It really is nice to know that with umbraco you aren't all on your lonesome when things go wrong!
Cheers Dean
Good to hear you got it working! :)
-Tor
Good morning folks!
Ahh, that's excellent. Glad your were able to figure out 👍
Hello Matt,
Had to rush away yesterday and sort the kids out.
Just wanted to say thanks for your help on this also!
Should I mark any response as accepted? I'm a noob here so don't want to get that wrong.
Hi Dean,
No problem. I think by the looks of it, Tor and I helped, but I think it's your own post around using the GetStock method with the additional VariantPublishedContent paramter which is the real answer. If you can mark your own post as answer, I'd probably be tempted to do that rather marking either mine or Tors as I think that's the information others with the same problem would be looking for.
If marking your own post as answer isn't possible, then I'd probably leave it open.
Either way, I'm glad you got it working.
Matt
is working on a reply...