Need help adding second value to each attribute

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
11 Jahre weitere
Hi,

I need a pointer as to how to modify the reading and writing of the attributes to allow me to save a second value for each attribute. This is for a pizza product where we want to specify additional toppings, and for each topping specify a second value: whole pizza, 1st half, or 2nd half.

The interface was quite easy to modify to achieve the result. I added a new AttirbuteControlType called CheckboxesWithCoverage to the "_ProductAttributes.cshtml" file (added at line 186)...

case AttributeControlType.CheckboxesWithCoverage:
    {
<table cellpadding="0" cellspacing="0" class="tableOptionList">
    @foreach (var pvaValue in attribute.Values)
    {              
        <tr>
        <td><input id="@(controlId)_@(pvaValue.Id)" type="checkbox" name="@(controlId)" value="@pvaValue.Id" @(pvaValue.IsPreSelected ? Html.Raw(" checked=\"checked\"") : null) onclick="togglePizzaCoverage('@(controlId)','@(pvaValue.Id)');" />
        <label for="@(controlId)_@(pvaValue.Id)">@pvaValue.Name @(!String.IsNullOrEmpty(pvaValue.PriceAdjustment) ? " [" + pvaValue.PriceAdjustment + "]" : null)</label></td>
        <td><div id="divCoverage@(pvaValue.Id)" style="display:none;">[&nbsp;&nbsp;&nbsp;<input type="radio" name="coverage@(pvaValue.Id)" id="coverage@(pvaValue.Id)whole" value="Whole" checked /><label for="coverage@(pvaValue.Id)whole"> Whole</label>&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;<input type="radio" name="coverage@(pvaValue.Id)" id="coverage@(pvaValue.Id)1stHalf" value="1st Half" /><label for="coverage@(pvaValue.Id)1stHalf"> 1st Half</label>&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;<input type="radio" name="coverage@(pvaValue.Id)" id="coverage@(pvaValue.Id)2ndHalf" value="2nd Half" /><label for="coverage@(pvaValue.Id)2ndHalf"> 2nd Half</label>&nbsp;&nbsp;&nbsp;]</div></td>
        </tr>
    }
</table>
    }
    break;

You have to include some jquery to toggle the visibility of the coverage inputs...

function togglePizzaCoverage(controlID, pvaValueID) {
        $('#divCoverage' + pvaValueID).toggle();
}

And I modified the file "ShoppingCartController.cs" (added to line 971) to save the first value, but it is not yet saving the second coverage value (just a copy.paste of the case for "AttributeControlType.Checkboxes")...

case AttributeControlType.CheckboxesWithCoverage:
    {
        var cblAttributes = form[controlId];
        if (!String.IsNullOrEmpty(cblAttributes))
        {
            foreach (var item in cblAttributes.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries))
            {
                int selectedAttributeId = int.Parse(item);
                if (selectedAttributeId > 0)
                    selectedAttributes = _productAttributeParser.AddProductAttribute(selectedAttributes,
                        attribute, selectedAttributeId.ToString());
            }
        }
    }
    break;

And I am pretty sure the file "ProductAttributeFormatter.cs" (add at Line 191) needs to have additional code to display the new coverage value, for now it is hard coded to show " - (Whole Pizza) after each attribute when the checkboxeswithcoverage type is being used...

// Add Coverage for Attributes using Checkboxes With Coverage
if (pva.AttributeControlType == AttributeControlType.CheckboxesWithCoverage)
{
    result.Append(" - (Whole Pizza)");
}

WHAT I NEED...

What I am missing is two things...

- Storing the additional coverage value somewhere (like the AttributesXML in the table "ShoppingCartItem," and there may be other tables that need it, too).

- Reading the second attribute value so it can be displayed instead of the hard coded " - (Whole Pizza)" text.

Any pointers or code would be appreciated.
11 Jahre weitere
I used a pretty easy approach to accomplish this. Where the value of each attribute is passed in by the CheckboxesWithCoverage object, I attach the extra value to the attribute id and separate with a pipe ("|"). Then I simply separate out the values by splitting them at the pipe character on the other side when the display values are formatted for display.
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.