ASPX templates
Version 4.x > ASPX templates > Kentico Product Options: enabled backend but hidden frontend View modes: 
User avatar
Member
Member
whiplash - 9/14/2012 4:36:57 AM
   
Kentico Product Options: enabled backend but hidden frontend
I am fairly new to Kentico and I am not 100% sure how to prevent a product option from displaying on the frontend website, but keeping it enabled in the backend so the system admins can still place orders using the option.

For example

CMSDesk > Tools > Ecommerce > Product Options > Edit an option which has child options

Eg, there are three child options, two of which I want displayed to the user on the website, but only one of them I want to hide from the end user and ONLY allow the Administrator to have access to the option...

Has anyone ever had the need for this feature before? If so, how did you accomplish it?

Thanks

User avatar
Kentico Consulting
Kentico Consulting
kentico_borisp - 9/14/2012 10:09:39 AM
   
RE:Kentico Product Options: enabled backend but hidden frontend
Hello,

Regrettably, this can't be achieved right out of the box. you will have to customize the control displaying the options a bit. You need to modify the following method:

LoadProductOptions()

in the file \CMSModules\Ecommerce\Controls\ProductOptions\ShoppingCartItemSelector.ascx.cs. There are the product options loaded and displayed on the live site. you would have to check if the current user is a global administrator and skip the processing of some field, if he is not. A second approach is to change the OptionCategoryInfoProvider.GetSKUOptionCategories method by overriding it with a custom e-commerce handler. More information on this topic can be found under the links below:

Code customizations in 6.0
Code customizations in the e-commerce module
API changes from 5.5R2 to 6.0
E-commerce custom providers
API reference

Here is a sample of an provider object override:
using System;
using System.Collections.Generic;
using System.Web;

using CMS.WorkflowEngine;
using CMS.SettingsProvider;
using CMS.Ecommerce;
using CMS.EcommerceProvider;

/// <summary>
/// Summary description for Class1
/// </summary>
[MyHandlers]
public partial class CMSModuleLoader
{
private class MyHandlers : CMSLoaderAttribute
{

public override void Init()
{
OrderInfoProvider.ProviderObject = new MyEcommerceCustomHandler();

WorkflowEvents.Approve.After += WorkflowEvents_Publish_Handler;
}

private static void WorkflowEvents_Publish_Handler(object sender, EventArgs e)
{
//insert custom code here
}
}

public class MyEcommerceCustomHandler : OrderInfoProvider
{
protected override string GetInvoiceInternal(int orderId)
{
return base.GetInvoiceInternal(orderId);
}
}
}

You could also add a custom field to the product option table to indicate, if the field should be displayed on the live site or not. If you'd like more details on this, please reply to this post.

Best regards,
Boris Pocatko

User avatar
Member
Member
whiplash - 9/17/2012 3:13:36 AM
   
RE:Kentico Product Options: enabled backend but hidden frontend
Thankyou very much for this Boris, much appreciated. I will get back to you after trying some of your suggestions.

Regards

User avatar
Member
Member
whiplash - 9/17/2012 5:45:29 AM
   
RE:Kentico Product Options: enabled backend but hidden frontend
Hi Boris,

Could I ask you for a bit more of an explanation about what you mean by adding the Custom Field to the Products table. Do you mean adding a boolean field to the table? Then checking if the field true and if the user is admin ... show field. It seems logical, though I am still unsure of how to prevent it displaying.

Overriding the method is probably the best solution but I'm not sure if I would be able to code it efficiently

User avatar
Kentico Consulting
Kentico Consulting
kentico_borisp - 9/17/2012 7:18:55 AM
   
RE:Kentico Product Options: enabled backend but hidden frontend
Hello,

To add a custom field to the product table you need to navigate to SiteManager / Development / System tables / Ecommerce - SKU. There is a Field tab where you can add a custom field of type boolean. To prevent displaying the option you will have to override the method, as I mentioned. You can check the CMSContext class for the CurrentUser and if it's not the Administrator, then simply leave it out from the listing.

Best regards,
Boris Pocatko

User avatar
Member
Member
whiplash - 9/18/2012 3:05:27 AM
   
RE:Kentico Product Options: enabled backend but hidden frontend
Got it solved using a custom field :)

User avatar
Member
Member
annaharris170-gmail - 5/6/2013 8:24:24 AM
   
RE:Kentico Product Options: enabled backend but hidden frontend
This functionality may not be available directly within Kentico CMS. You will have to customize your code accordingly.