Product templates and customer fields

For general questions and discussions specific to the AbleCommerce 7.0 Asp.Net product.
Post Reply
User avatar
draneb
Captain (CAPT)
Captain (CAPT)
Posts: 314
Joined: Sun Jun 12, 2005 4:07 pm
Location: Texas
Contact:

Product templates and customer fields

Post by draneb » Mon May 25, 2009 9:00 pm

Hello,

I am using product templates to obtain special instructions from the customer (if needed).
I don't like how regardless of whether the customer enters information in the field(s) or not it still shows the field name in the basket when they add an item to the basket.

Is there anyway to have it so that if the field is left blank (null) then the field name is not added to the basket?

Thank you.
AC 7.0.3 build 13937

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

Re: Product templates and customer fields

Post by mazhar » Tue May 26, 2009 4:24 am

Edit your ConLib/Utility/MiniBasketItemDetail.ascx.cs file and locate following code

Code: Select all

private BasketItemInputCollection GetCustomerInputs()
    {
        BasketItemInputCollection inputs = new BasketItemInputCollection();
        foreach (BasketItemInput input in _BasketItem.Inputs)
        {
            if ((input.InputField != null) && (!input.InputField.IsMerchantField))
                inputs.Add(input);
        }
        return inputs;
    }
and then change it as below

Code: Select all

private BasketItemInputCollection GetCustomerInputs()
    {
        BasketItemInputCollection inputs = new BasketItemInputCollection();
        foreach (BasketItemInput input in _BasketItem.Inputs)
        {
            if ((input.InputField != null) && (!input.InputField.IsMerchantField) && !string.IsNullOrEmpty(input.InputValue))
                inputs.Add(input);
        }
        return inputs;
    }
You may need a very similar change in ConLib/Utility/OrderItemDetail.ascx.cs and ConLib/Utility/BasketItemDetail.ascx.cs file as well for other potential locations.

User avatar
draneb
Captain (CAPT)
Captain (CAPT)
Posts: 314
Joined: Sun Jun 12, 2005 4:07 pm
Location: Texas
Contact:

Re: Product templates and customer fields

Post by draneb » Tue May 26, 2009 6:09 am

Ohhh wow! That small change in code makes such a difference.

I wished they would put that in a future release so I don't have to have custom code.
I can't imagine anyone wanting to see the Field Name if nothing is entered.

I changed the BasketItemDetail file because it was just like the minibasket file but the OrderItemsDetail I am afraid to touch because it looks quite different and I don't want to break any code.
If anyone has time to help with that file I would certainly be grateful.

Thanks Mazhar!
AC 7.0.3 build 13937

William M
Commander (CMDR)
Commander (CMDR)
Posts: 150
Joined: Sat Feb 14, 2009 9:40 am
Contact:

Re: Product templates and customer fields

Post by William M » Tue May 26, 2009 6:33 am

draneb wrote: I can't imagine anyone wanting to see the Field Name if nothing is entered.
A blank space after "Special Instructions" on the email receipt can prompt the buyer to email an important note which may prevent an uncomfortable phone call once the product arrives.


I'd prefer to have "None" placed there as the default text just make it perfectly clear that instructions were not entered at the time of the order.

Mazhar, is this possible?

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

Re: Product templates and customer fields

Post by mazhar » Tue May 26, 2009 7:20 am

Yep possiable, edit your App_Code/ProductHelper.cs file and locate following code block

Code: Select all

//ONLY LOOK FOR CUSTOMER INPUT FIELDS
                    if (!input.IsMerchantField)
                    {
                        //SEE IF WE CAN LOCATE THE CONTROL
                        WebControl inputControl = (WebControl)PageHelper.RecursiveFindControl(container, input.UniqueId);
                        if (inputControl != null)
                        {
                            BasketItemInput itemInput = new BasketItemInput();
                            itemInput.InputFieldId = input.InputFieldId;
                            itemInput.InputValue = input.GetControlValue(inputControl);
                            item.Inputs.Add(itemInput);
                        }
                    }
and then change it as below

Code: Select all

//ONLY LOOK FOR CUSTOMER INPUT FIELDS
                    if (!input.IsMerchantField)
                    {
                        //SEE IF WE CAN LOCATE THE CONTROL
                        WebControl inputControl = (WebControl)PageHelper.RecursiveFindControl(container, input.UniqueId);
                        if (inputControl != null)
                        {
                            BasketItemInput itemInput = new BasketItemInput();
                            itemInput.InputFieldId = input.InputFieldId;
                            itemInput.InputValue = input.GetControlValue(inputControl);
                            if (string.IsNullOrEmpty(itemInput.InputValue))
                                itemInput.InputValue = "none";
                            item.Inputs.Add(itemInput);
                        }
                    }
Now when collecting customer input if application found it empty it will place none in value.

User avatar
draneb
Captain (CAPT)
Captain (CAPT)
Posts: 314
Joined: Sun Jun 12, 2005 4:07 pm
Location: Texas
Contact:

Re: Product templates and customer fields

Post by draneb » Fri May 29, 2009 8:53 pm

Hello,

I changed the BasketItemDetail file because it was just like the minibasket file and those work great, but the OrderItemsDetail.ascx.cs file I am afraid to touch because it looks quite different and I don't want to break any code. There is mention of Wishlist, Kits, Gift Wrap, Gift Message.... wheewww, that file makes my brain hurt.

This would be to hide the Custom Field if no text was entered by the user.
If anyone has time to help with the code for that file I would certainly be grateful. If you are a programmer and are for hire send me a message.

Thank you!
AC 7.0.3 build 13937

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

Re: Product templates and customer fields

Post by mazhar » Sat May 30, 2009 1:30 am

Locate following code block in your ConLib/Utiltiy/OrderItemDetails.ascx.cs file

Code: Select all

InputList.DataSource = _OrderItem.Inputs;
InputList.DataBind();
and then change it to as below

Code: Select all

OrderItemInputCollection inputsCollection = new OrderItemInputCollection();
                    foreach (OrderItemInput input in _OrderItem.Inputs)
                        if (!string.IsNullOrEmpty(input.InputValue))
                            inputsCollection.Add(input);
                    InputList.DataSource = inputsCollection;
                    InputList.DataBind();

User avatar
draneb
Captain (CAPT)
Captain (CAPT)
Posts: 314
Joined: Sun Jun 12, 2005 4:07 pm
Location: Texas
Contact:

Re: Product templates and customer fields

Post by draneb » Sat May 30, 2009 3:07 pm

As usual, thank you Mazhar!

Where does that file remove the mention of the custom field?
I just wanted to make sure the change worked.

I placed a test order and the only other place I see mention of it for now is in the Admin.
I am wondering if I should remove it there as well and if so what file that would be in?
(viewing order in admin)

Thanks again.
AC 7.0.3 build 13937

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

Re: Product templates and customer fields

Post by mazhar » Mon Jun 01, 2009 3:45 am

Hmm for admin side you need to do very same thing in Website/Admin/UserControls/OrderItemDetail.ascx.csfile. Edit it and locate

Code: Select all

InputList.DataSource = _OrderItem.Inputs;
InputList.DataBind();
and replace it with

Code: Select all

OrderItemInputCollection inputsCollection = new OrderItemInputCollection();
                    foreach (OrderItemInput input in _OrderItem.Inputs)
                        if (!string.IsNullOrEmpty(input.InputValue))
                            inputsCollection.Add(input);
                    InputList.DataSource = inputsCollection;
                    InputList.DataBind();

User avatar
draneb
Captain (CAPT)
Captain (CAPT)
Posts: 314
Joined: Sun Jun 12, 2005 4:07 pm
Location: Texas
Contact:

Re: Product templates and customer fields

Post by draneb » Sat Jul 04, 2009 5:26 pm

Mazhar,

I have one more question regarding this terrific project :)

Everything is working great so far. But there is one area I hadn't experimented with - the Wishlist.

So if I add an item without special instructions to My Wishlist it still shows the Field Name(s).

Is there a place where that can be fixed as well?

Thank you!
AC 7.0.3 build 13937

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

Re: Product templates and customer fields

Post by mazhar » Mon Jul 06, 2009 3:51 am

For this try to edit ConLib/MyWishlistPage.ascx file and lcoate following line of code

Code: Select all

<asp:DataList ID="InputList" runat="server" DataSource='<%# Eval("Inputs") %>'>
and update it as below

Code: Select all

<asp:DataList ID="InputList" runat="server" DataSource='<%# GetInputs(Eval("Inputs")) %>'>
finally add following method to its code file

Code: Select all

protected WishlistItemInputCollection GetInputs(Object dataItem)
    {
        WishlistItemInputCollection inputs = (WishlistItemInputCollection)dataItem;
        WishlistItemInputCollection notEmptyInputs = new WishlistItemInputCollection();
        foreach (WishlistItemInput input in inputs)
            if (!String.IsNullOrEmpty(input.InputValue))
                notEmptyInputs.Add(input);
        return notEmptyInputs;
    }

Post Reply