Try our conversational search powered by Generative AI!

How to determin product is active or not using content loader

Vote:
 

Hi,

Example:
I store an item in recently viewied block(cookies involved)
Product has been disabled But still vcan be retrived in recently viewed block.
UrlResolver.Current.GetUrl(contentLink, language) will throw an exception if prodct is not active.

IN CMS 7.5 without involving DB how can I check product is active or NOT.
[product.LoadEntry().IsActive return me is-active but involves a db trip]

var productContent = (ProductContent)contentLoader.Get(contentLink)
productConten.Status is coming as "CheckedOut"

any idea?

Regards
/K

#113399
Nov 19, 2014 16:50
Vote:
 

Versions are
CMS 7.14
Commerce 8.1

#113400
Nov 19, 2014 16:51
Vote:
 

Hi,

When implement Catalog content provider, we used some hacks as follow:

- If an entry is active (IsAvailable = true), then it's published. Otherwise it's not.

- The StartDate = Start publishing, EndDate = Stop publishing.

Yes, it's not optimal and a bit confusing, but for now you can check if status of a entry content is published or not to see if it's active or not.

Regards.

/Q

#113418
Nov 20, 2014 1:17
Vote:
 

I appriciate for this quick solution.
Regards
/K

#113434
Nov 20, 2014 11:44
Vote:
 

HI Khurram

Hope you are doing well. I had a quick favour to ask. I have just started working in depth on the latest version of EPiserver commerce.. 

On a CMS page I want to be able to link to a product. 

For this I am using the "Url to Page" property. 

This works fine and retrieves the url to the product page. However I do not want to redirect to that page but actually just get the product name out. Am I using the correct CMS property.

In general if I want to get a fashion product out using the product code I use something like below

var contentLink = ExtensionMethods.ReferenceConverter.Service.GetContentLink("Tops-Tunics-CowlNeck", CatalogContentType.CatalogEntry);

var fashionProductContent = (FashionProductContent)ExtensionMethods.ContentLoader.Service.Get<IContent>(contentLink);

But I only have a link. Am I using the correct property.

Regards

Sandeep

#115013
Jan 07, 2015 23:34
Vote:
 

Hi,

Sandeep, Glad to see you again, btw congratulations on the birth of your newborn son.

If i am not understanding wrong, this can help you

var urlResolver = ServiceLocator.Current.GetInstance<UrlResolver>(); [Editted]
var content = urlResolver.Route(url);

Regards
Khurram

#115034
Edited, Jan 08, 2015 11:34
Vote:
 

HI Khurram

Thanks for your wishes. Have you got some code to create a product using content provider in code.

Regards

Sandeep

#115063
Jan 08, 2015 16:54
Vote:
 

var contentRepository = ServiceLocator.Current.GetInstance<IContentRepository>();

    //Create a new instance of CatalogContentTypeSample that will be a child to the specified parentNode.

    var newSku = contentRepository.GetDefault<CatalogContentTypeSample>(linkToParentNode);

    //Set some required properties.

    newSku.Description = "Great";

    //Publish the new content and return its ContentReference.

    return contentRepository.Save(newSku, SaveAction.Publish, AccessLevel.NoAccess);

/K

#115064
Jan 08, 2015 16:59
Vote:
 

Hi Khurram Bhai

Thanks once again. Works perfectly. Used the same logic to create catalog, products and variants. All works like a charm.

Kind Regards

Sandeep

#115076
Jan 09, 2015 0:59
Vote:
 

Hi Khurram

Could you please let me know how to creare a catalog from code too. The same method does not seem to work. It seems to complain we need an implementation of "ICatalogContentCommitter".

Kind Regards

#115170
Jan 12, 2015 13:14
Vote:
 

Hi Khurram

Found a solution. Aparently this was not supported in version 7.5. In Episerver Version 7.9 and above you can do it using the following. Please note the default properties below are mandatory -

var repository = ServiceLocator.Current.GetInstance<IContentRepository>();
            var referenceConverter = ServiceLocator.Current.GetInstance<Mediachase.Commerce.Catalog.ReferenceConverter>();
            var root = referenceConverter.GetRootLink();
            var catalog = repository.GetDefault<CatalogContent>(root);
            catalog.Name = "My catalog2";
            catalog.DefaultCurrency = "USD";
            catalog.DefaultLanguage = "en";
            catalog.WeightBase = "Pounds";
            repository.Save(catalog, SaveAction.Publish, EPiServer.Security.AccessLevel.NoAccess);


Kind Regards

Sandeep

#115275
Jan 12, 2015 22:32
Vote:
 

Yes, CatalogContent wasn't supported until recently - IIRC it was added in 7.9 as you pointed out.

Please note that for your own question, you should create another thread to keep all discussions focused.

Thanks.

/Q

#115277
Edited, Jan 13, 2015 3:34
Vote:
 

Hi Quan

Thanks for your reply. Had realised that and hence  I deleted the question from your post and created a new thread for it. Have posted the solution on here also just in case some one read this and wondered if we got to the solution.

Regards

Sandeep

#115285
Jan 13, 2015 10:22
Vote:
 

My current ecommerce solution needs to support multiple market, i'd like to implement some business rule to prevent commerce editor publishing the product in the selected market without having price configured correctly. 

What will be the best way to check the product availability? 

P. s. I am using the latest commerce 9.10

#146902
Mar 30, 2016 12:53
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.