Portal Engine Questions on portal engine and web parts.
Version 7.x > Portal Engine > Add custom attribute View modes: 
User avatar
Member
Member
d.severi-netribegroup - 11/20/2013 3:02:56 AM
   
Add custom attribute
How do I add a custom attribute to the class AddressInfoProvider.

thanks

User avatar
Kentico Consulting
Kentico Consulting
Kentico_RichardS - 11/20/2013 3:36:06 AM
   
RE:Add custom attribute
Hi,

Thank you for your message.

You cant add a newattribute to the class without the access to the surce code (and some advanced programming skills), however I believe that what you need can be accomplish in a different way.

If you go to CMS_Class table and find the Ecommerce - Address Class and change the attribute of this class from ClassShowAsSystemTable to true instead of false. Now you should be able to see adress system table in Site manager -> Development -> System tables. You can add a new fields there. However whenever you will need to populate this with some value you would also need to edit the form which is responsible for insertint a new adress. E.g. the one in CMS Desk -> Ecommerce -> Customers -> Edit some customer -> Adresses which would be the file CMSModules/Ecommerce/Pages/Tools/Customers/Customer_Edit_Address_Edit.aspx and also if you would like to see those field you will have to customize e.g. the Adresses list page -> CMSModules/Ecommerce/Pages/Tools/Customers/Customer_Edit_Address_List.aspx

I hope this draw some lines of where you can start and will help you with this issue.

Kind regards,
Richard Sustek

User avatar
Member
Member
d.severi-netribegroup - 11/20/2013 4:02:59 AM
   
RE:Add custom attribute
Hi,

Thanks for the reply.

I did what you tell me. I created the new attribute in Ecommerce - Address.
But I want to use in ShoppingCartOrderAddresses.ascx and does not find that attribute.

What I forget?

User avatar
Kentico Consulting
Kentico Consulting
Kentico_RichardS - 11/20/2013 5:23:54 AM
   
RE:Add custom attribute
Hi,

How are you getting the value in C#? Is your value saved in the database COM_Adress ?

In C# you should get the value like:
string MyCustomValue = ai.GetStringValue("ColumnNameOfYourCustomField", "");

the ai is AddressInfo object.

I tried it on my end and it was working as excpeted. I was getting this value in method LoadBillingAddressInfo() in case that ai wasnt null. Can you try that as well? How does it work?

Let me know if you have further questions.

Kind regards,
Richard Sustek

User avatar
Member
Member
d.severi-netribegroup - 11/20/2013 7:22:08 AM
   
RE:Add custom attribute
Thank you very much, however, does not work.
I tried to recover the value as you told me. But it does not find anything.
This is the code of the function:
/// <summary>
/// Loads selected billing address info.
/// </summary>
protected void LoadBillingAddressInfo()
{
// Try to select company address from ViewState first
if (!ShoppingCartControl.IsCurrentStepPostBack && ShoppingCartControl.GetTempValue(BILLING_ADDRESS_ID) != null)
{
LoadBillingFromViewState();
}
else
{
int addressId = 0;

if (drpBillingAddr.SelectedValue != "0")
{
addressId = Convert.ToInt32(drpBillingAddr.SelectedValue);

AddressInfo ai = AddressInfoProvider.GetAddressInfo(addressId);
if (ai != null)
{
txtBillingName.Text = ai.AddressPersonalName;
txtBillingAddr1.Text = ai.AddressLine1;
txtBillingAddr2.Text = ai.AddressLine2;
txtBillingCity.Text = ai.AddressCity;
txtBillingZip.Text = ai.AddressZip;
txtBillingPhone.Text = ai.AddressPhone;
txtCF.Text = ai.GetStringValue("AddressCF", "");
CountrySelector1.CountryID = ai.AddressCountryID;
CountrySelector1.StateID = ai.AddressStateID;
CountrySelector1.ReloadData(true);
}
}
else
{
// Clean billing part of the form
CleanForm(true, false, false);

// Prefill customer company name or full name
if ((ShoppingCart.Customer != null) &&
(ShoppingCart.Customer.CustomerCompany != ""))
{
txtBillingName.Text = ShoppingCart.Customer.CustomerCompany;
}
else
{
txtBillingName.Text = ShoppingCart.Customer.CustomerFirstName + " " + ShoppingCart.Customer.CustomerLastName;
}
}
}
}

User avatar
Kentico Consulting
Kentico Consulting
Kentico_RichardS - 11/21/2013 2:21:29 AM
   
RE:Add custom attribute
Hi,

Where are you running this code? You have to be inside shopping cart and you have to choose the Billing adress -> this adress has to have the field populated in database? Does your custom field for this particular adress really hold some data?

Kind reagrds,
Richard Sustek

User avatar
Member
Member
d.severi-netribegroup - 11/22/2013 2:59:45 AM
   
RE:Add custom attribute
Yes, I am in the shopping cart and I want to save this field in the billing address. But when I try to retrieve the value saved to the db can not find the new attribute.

Denis

User avatar
Kentico Consulting
Kentico Consulting
Kentico_RichardS - 11/22/2013 3:35:45 AM
   
RE:Add custom attribute
Hi Denis,

You have to choose also the correct billing adress which has this value you want to pullout. I cant see any reason why it works on my end but not in your case. You are probably missing something. Can you post pictures of your code/database where the value is saved and when on live page you are trying to get this value?

Otherwise Im not sure how can I help you.

Kind regards,
Richard Sustek