Non-Public Information in each Product

For general questions and discussions specific to the AbleCommerce 7.0 Asp.Net product.
Post Reply
Robbie@FireFold
Commodore (COMO)
Commodore (COMO)
Posts: 433
Joined: Wed May 28, 2008 9:42 am
Location: Concord, NC
Contact:

Non-Public Information in each Product

Post by Robbie@FireFold » Wed Oct 22, 2008 3:39 pm

Hey Guys,

I need a box in each product that would not be visible to the public/customers. Something the size of the summary box where my employee's could write information such as 'changed to xxxx, not coming back, etc.'

I think this is a pretty easy one. Hopefully someone can cook something up!
Robbie Hodge
General Manager
Robbie@FireFold.com
http://www.FireFold.com

User avatar
mazhar
Master Yoda
Master Yoda
Posts: 5084
Joined: Wed Jul 09, 2008 8:21 am
Contact:

Re: Non-Public Information in each Product

Post by mazhar » Thu Oct 23, 2008 4:58 am

First Approach

One possibility is to use the the Product Templates, create a new merchant field of type text area then update the ConLib/ProductCustomFieldsDialog control so that it doesn't render that specific information. Need to change the following statement

Code: Select all

if (!string.IsNullOrEmpty(tf.InputValue) && tf.InputField.IsMerchantField)
to

Code: Select all

if (!string.IsNullOrEmpty(tf.InputValue) && tf.InputField.IsMerchantField && tf.InputField.Name != "EmployeeNote")
Where EmployeeNote is the field name. With this approach obviously you need to apply the product template on all of your products.

Second Approach

The second possibility is to use CustomFields and save extra information there for each product. This modification will only change the Admin/Products/EditProduct.aspx page. With this approach you need no extra effort like to apply product template etc. Instead of guiding where to place the code I am attaching the test sample created here. You can easily find the changes in the in the page. Just look for _CustomField member in the code and in aspx file check the newly added textbox called EmployeeNote. Here is the modified page

User avatar
rhuffman
Lieutenant, Jr. Grade (LT JG)
Lieutenant, Jr. Grade (LT JG)
Posts: 24
Joined: Thu May 19, 2005 6:36 pm
Location: Dublin, OH
Contact:

customized fields in editcategory.aspx page

Post by rhuffman » Tue Jul 27, 2010 5:31 pm

Mazhar:

I incorporated the above on the editproduct.aspx page and it worked perfectly! Thank you.
I attempted, using the same logic, to add the same, to the editcategory.aspx page and it kept blowing up regardless of what I did.

Would it be possbile for you to submit a similar example for the editcategory.aspx page? If we can incorporate custom fields in the editcategory.aspx we will 95% on our way to going live with Able 7.x.

Your help would be greatly appreciated.

Ray Huffman
Darby Creek Trading Co.
www.DarbyCreekTrading.com

User avatar
mazhar
Master Yoda
Master Yoda
Posts: 5084
Joined: Wed Jul 09, 2008 8:21 am
Contact:

Re: customized fields in editcategory.aspx page

Post by mazhar » Wed Jul 28, 2010 6:11 am

rhuffman wrote:Mazhar:

I incorporated the above on the editproduct.aspx page and it worked perfectly! Thank you.
I attempted, using the same logic, to add the same, to the editcategory.aspx page and it kept blowing up regardless of what I did.

Would it be possbile for you to submit a similar example for the editcategory.aspx page? If we can incorporate custom fields in the editcategory.aspx we will 95% on our way to going live with Able 7.x.

Your help would be greatly appreciated.

Ray Huffman
Darby Creek Trading Co.
http://www.DarbyCreekTrading.com
Here is the sample for adding custom field on category.

User avatar
rhuffman
Lieutenant, Jr. Grade (LT JG)
Lieutenant, Jr. Grade (LT JG)
Posts: 24
Joined: Thu May 19, 2005 6:36 pm
Location: Dublin, OH
Contact:

Re: Non-Public Information in each Product

Post by rhuffman » Wed Jul 28, 2010 8:02 am

Mazhar

When through both files and copied the code that was different for botth aspx and aspx.cs
When we tried to edit the category we got the following error:

Server Error in '/' Application.
--------------------------------------------------------------------------------

Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message: CS0103: The name '_CustomField' does not exist in the current context

Source Error:



Line 39: CustomFieldCollection customFields = CustomFieldDataSource.LoadForCriteria(String.Format(" StoreId = {0} AND TableName='{1}' AND ForeignKeyId={2} ", Token.Instance.Store.StoreId, "ac_Categories", _Category.CategoryId));
Line 40: if (customFields != null && customFields.Count > 0)
Line 41: _CustomField = customFields[0];
Line 42:
Line 43:


Source File: c:\AbleCommerce\Admin\Catalog\EditCategory.aspx.cs Line: 41


Any suggestions?

Thank you.

Ray Huffman
Darby Creek Trading Co.
www.DarbyCreekTrading.com

User avatar
mazhar
Master Yoda
Master Yoda
Posts: 5084
Joined: Wed Jul 09, 2008 8:21 am
Contact:

Re: Non-Public Information in each Product

Post by mazhar » Wed Jul 28, 2010 8:31 am

Make sure in your code file you have

Code: Select all

Category _Category;
private CustomField _CustomField;
if you have only

Code: Select all

Category _Category;
Then update it as mentioned above.

User avatar
rhuffman
Lieutenant, Jr. Grade (LT JG)
Lieutenant, Jr. Grade (LT JG)
Posts: 24
Joined: Thu May 19, 2005 6:36 pm
Location: Dublin, OH
Contact:

Re: Non-Public Information in each Product

Post by rhuffman » Wed Jul 28, 2010 11:20 am

Mashar:

Thank you! That worked.

Ray Huffman
Darby Creek Trading
www.DarbyCreekTrading.com

User avatar
rhuffman
Lieutenant, Jr. Grade (LT JG)
Lieutenant, Jr. Grade (LT JG)
Posts: 24
Joined: Thu May 19, 2005 6:36 pm
Location: Dublin, OH
Contact:

Re: Non-Public Information in each Product

Post by rhuffman » Wed Jul 28, 2010 2:06 pm

Mashar:

As previously stated, you solution worked. However, when I try to add an additional custom field and try to duplicate the previously code, I can either update one custom field or the other, but not both. If you could provide an example with 2 custom fields - I think my problem is in the update statement or declaration - not really sure. I just hacking my way throuht it (not very sucessfully) I would hope I could figure out with customfield3, customfield4, with you fine examples.

I really appreciate your help.

Thank you.

Ray Huffman
Darby Creek Trading Co.
www.DarbyCreekTrading.com

User avatar
mazhar
Master Yoda
Master Yoda
Posts: 5084
Joined: Wed Jul 09, 2008 8:21 am
Contact:

Re: Non-Public Information in each Product

Post by mazhar » Thu Jul 29, 2010 4:27 am

Actually in order to to do so you need to make use of field name column. For example in above posted sample you have

Code: Select all

CustomFieldCollection customFields = CustomFieldDataSource.LoadForCriteria(String.Format(" StoreId = {0} AND TableName='{1}' AND ForeignKeyId={2}", Token.Instance.Store.StoreId, "ac_Categories", _Category.CategoryId));
You need to update it something like this where FirstField is name of first custom field. Similarly you could load other field for same category just by providing corresponding custom field name in query.

Code: Select all

CustomFieldCollection customFields = CustomFieldDataSource.LoadForCriteria(String.Format(" StoreId = {0} AND TableName='{1}' AND ForeignKeyId={2} AND FieldName={3}", Token.Instance.Store.StoreId, "ac_Categories", _Category.CategoryId,"FirstField"));
On the other hand when it comes to creating/saving new custom field you need to provide its name when saving custom field object. For example

Code: Select all

_CustomField.FieldName = "FirstField";
and
_CustomField.FieldName = "SecondField";
In above sample you can see CEN is used as custom field name. You are having problem when you try to add two fields because code is not taking care of field name so it always loads/updates single CEN custom field.

User avatar
rhuffman
Lieutenant, Jr. Grade (LT JG)
Lieutenant, Jr. Grade (LT JG)
Posts: 24
Joined: Thu May 19, 2005 6:36 pm
Location: Dublin, OH
Contact:

Re: Non-Public Information in each Product

Post by rhuffman » Thu Jul 29, 2010 2:08 pm

Mazhar:

I have spend several hours trying to add an additonal second custom field with no sucess.
I have used every combination of code I can think of.
Can you kindly provid a full EditCategory.aspx.cs sample with two custom fields.
Although I am not a programmer, I am an average "hack" but this one has me baffled.

Thank you.

dappy2
Commander (CMDR)
Commander (CMDR)
Posts: 114
Joined: Wed Jan 18, 2006 5:53 pm
Contact:

Re: Non-Public Information in each Product

Post by dappy2 » Wed Nov 24, 2010 1:24 pm

I know this topic is a bit old but I'm stuck.

I've successfully added a custom field to the editcategory.aspx using the above code. However, I want to pull that custom field into HTML in the code behind of the pages and I can't seem to do it. I was looking at the ProductCustomFieldsDialog file but it seems vastly different to what I need to do.

I'm trying to implement some SEO features like specifying a custom link title (<a href="someurl" title="CUSTOMFIELD"). I want to pull this in various places listed in order from most important to least:

Navigation (I'm using the simple category list that renders nexted <ul>'s) AllCategories.ascx - that's what my file is called, not sure if that's in Able or not.
CategoryDetailsPage.ascx
CategoryBreadCrumbs.ascx

I'm just thoroughly confused and eventually I'd like to add this to all the products too in order to pull SEO optimized title attributes on all links.

Thanks,
Dappy

User avatar
s_ismail
Commander (CMDR)
Commander (CMDR)
Posts: 162
Joined: Mon Nov 09, 2009 12:20 am
Contact:

Re: Non-Public Information in each Product

Post by s_ismail » Wed Dec 01, 2010 8:52 am

You can get custom fields value like this

Code: Select all

protected void Page_Load(object sender, EventArgs e)
    {
        string customFieldValue = GetCustomFieldValue(CategoryId, "CUSTOM_FIELD_NAME");

    }
    public string GetCustomFieldValue(int categoryId, string customFieldName)
    {
        CustomFieldCollection customFields = CustomFieldDataSource.LoadForCriteria(" TableName='ac_Categories' AND ForeignKeyId=" + categoryId);
        foreach (CustomField customfield in customFields)
        {
            if (customfield.FieldName == customFieldName)
                return customfield.FieldValue;
        }
        return string.Empty;
    }

Post Reply