Try our conversational search powered by Generative AI!

Issues using ShippingMethodParameter for my custom Shipping provider

Vote:
 

I'm trying to setup a custom shipping provider with extra parameters and have followed the instructions found here

http://world.episerver.com/Documentation/Items/Developers-Guide/EPiServer-Commerce1/751/Shipping/Shipping-methods/

and here

http://world.episerver.com/Documentation/Items/Developers-Guide/EPiServer-Commerce1/751/Shipping/Shipping-gateways-and-providers/

But I have trouble retrieving and storing the parameters. In the examples it says (one is about ShippingMethodCase, but it is handled in the same way as ShippingMethodParameter):

//Adding a row of data
if (_ShippingMethodDto != null && _ShippingMethodDto.ShippingMethod.Count > 0)
{
 ShippingMethodDto.ShippingMethodCaseRow row = _ShippingMethodDto.ShippingMethodCase.NewShippingMethodCaseRow();
 row.Total = Double.Parse(Weight.Text, _NumberFormat);
 row.Charge = Double.Parse(Price.Text, _NumberFormat);
 row.StartDate = StartDate.Value;
 row.EndDate = EndDate.Value;

 //the ShippingMethodDto will only contain one row for the ShippingMethod row, which
 //represents the shipping method information stored on the first tab of the shipping method in
 //commerce manager
 row.ShippingMethodId = _ShippingMethodDto.ShippingMethod[0].ShippingMethodId;
 row.JurisdictionGroupId = Int32.Parse(JurisdictionGroupList.SelectedValue);

 // add the row to the dto
 if (row.RowState == DataRowState.Detached)
 _ShippingMethodDto.ShippingMethodCase.Rows.Add(row);
}

//retrieving data

if (_ShippingMethodDto != null && _ShippingMethodDto.ShippingMethodParameter != null &&  _ShippingMethodDto.ShippingMethodParameter.Rows.Count > 0) 
{ 
 ShippingMethodDto.ShippingMethodParameterRow row = (ShippingMethodDto.ShippingMethodParameterRow)_ShippingMethodDto.ShippingMethodParameter.Rows[0]; 
 txtTypeOfService.Text = row.Value; 
 lblTypeOfService.Text = row.Parameter; 
}


But when I use this implementation I only get a long table with a new row everytime I change the settings, and using Rows[0](as in the example) only gets me the first parameter I added. I changed it to just .Last() instead as a workaround but not only does it seem wrong to just keep adding a new parameter instead of overwriting the same but when I try to add different parameters at the same time I have noway of retrieving two different parameters from the "ShippingMethodParameter" table at the same time.
 _ShippingMethodDto.ShippingMethodParameter only have the following methods
NewShippingMethodParameterRow();
AddShippingMethodParameterRow

RemoveShippingMethodParameterRow

FindByShippingMethodParamterId

and the "ShippingMethodParamterId" seems to be auto incremented when a new row is added so I cant find the parameter with the find method


Anyone have any suggestions?





#80213
Jan 16, 2014 17:01
Vote:
 

I'm assuming you are inside the "ConfigureShippingMethod.ascx" - the control that loads the Shipping Provider Parameters tab inside Commerce Manager. I use the following code:

//inside your save method:
var parameterRow = GetParameterByName(shippingMethod, parameterName);
if (parameterRow != null)
 {
   parameterRow.Value = value;
 }
else
 {
   CreateParameter(shippingMethod, parameterName, value, methodId);
}


//GetParameterByName method
protected ShippingMethodDto.ShippingMethodParameterRow 
  GetParameterByName(ShippingMethodDto shippingMethod, string parameterName)
 {
    var rowArray =
           (ShippingMethodDto.ShippingMethodParameterRow[])
       shippingMethod.ShippingMethodParameter.Select(string.Format("Parameter = '{0}'", parameterName));
            return rowArray.Any() ? rowArray[0] : null;
  } 

// create method
protected void CreateParameter(ShippingMethodDto dto, string parameterName, string value, Guid paymentMethodId)
 {
   var row = dto.ShippingMethodParameter.NewShippingMethodParameterRow();
   row.ShippingMethodId = paymentMethodId;
   row.Parameter = parameterName;
   row.Value = value;

   if (row.RowState == DataRowState.Detached)
   {
       dto.ShippingMethodParameter.Rows.Add(row);
   }
}

    

 

 

 

#80332
Jan 21, 2014 10:01
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.