Hi,
Thank you! I also found out that the GooglecheckoutPaymentProcessor.cs code passes the Flat Rate Shipping charges configured in admin even if you set your shipping by weight and have that enabled, it would still pass the flat rate shipping charges. Please look at the bottom code marked in "bold". There's a FlatRateShippingAdjustment namespace/object I'm not sure what it is. But I got a red squiggly mark on my visual studio saying that the type or namespace cannot be found..are you missing an assembly reference? so I'm not sure how to correct the code to maybe pass the type/object for the shipping by weight table definition in the admin. Thanks.
private void ProcessNewOrderNotification(string xmlData)
{
try
{
var newOrderNotification = (NewOrderNotification)EncodeHelper.Deserialize(xmlData, typeof(NewOrderNotification));
string googleOrderNumber = newOrderNotification.googleordernumber;
XmlNode customerInfo = newOrderNotification.shoppingcart.merchantprivatedata.Any[0];
int customerId = Convert.ToInt32(customerInfo.Attributes["CustomerID"].Value);
//int customerLanguageId = Convert.ToInt32(customerInfo.Attributes["CustomerLanguageID"].Value);
//int customerCurrencyId = Convert.ToInt32(customerInfo.Attributes["CustomerCurrencyID"].Value);
var customer = _customerService.GetCustomerById(customerId);
if (customer == null)
{
LogMessage("Could not load a customer");
return;
}
var cart = customer.ShoppingCartItems.Where(sci => sci.ShoppingCartType == ShoppingCartType.ShoppingCart).ToList();
_workContext.CurrentCustomer = customer;
if (cart.Count == 0)
{
LogMessage("Cart is empty");
return;
}
//validate cart
foreach (var sci in cart)
{
bool ok = false;
foreach (Item item in newOrderNotification.shoppingcart.items)
{
if (!String.IsNullOrEmpty(item.merchantitemid))
{
if ((Convert.ToInt32(item.merchantitemid) == sci.Id) && (item.quantity == sci.Quantity))
{
ok = true;
break;
}
}
}
if (!ok)
{
LogMessage(string.Format("Shopping Cart item has been changed. {0}. {1}", sci.Id, sci.Quantity));
return;
}
}
string[] billingFullname = newOrderNotification.buyerbillingaddress.contactname.Trim().Split(new char[] { ' ' }, 2, StringSplitOptions.RemoveEmptyEntries);
string billingFirstName = billingFullname[0];
string billingLastName = string.Empty;
if (billingFullname.Length > 1)
billingLastName = billingFullname[1];
string billingEmail = newOrderNotification.buyerbillingaddress.email.Trim();
string billingAddress1 = newOrderNotification.buyerbillingaddress.address1.Trim();
string billingAddress2 = newOrderNotification.buyerbillingaddress.address2.Trim();
string billingPhoneNumber = newOrderNotification.buyerbillingaddress.phone.Trim();
string billingCity = newOrderNotification.buyerbillingaddress.city.Trim();
int? billingStateProvinceId = null;
var billingStateProvince = _stateProvinceService.GetStateProvinceByAbbreviation(newOrderNotification.buyerbillingaddress.region.Trim());
if (billingStateProvince != null)
billingStateProvinceId = billingStateProvince.Id;
string billingZipPostalCode = newOrderNotification.buyerbillingaddress.postalcode.Trim();
int? billingCountryId = null;
var billingCountry = _countryService.GetCountryByTwoLetterIsoCode(newOrderNotification.buyerbillingaddress.countrycode.Trim());
if (billingCountry != null)
billingCountryId = billingCountry.Id;
var billingAddress = customer.Addresses.ToList().FindAddress(
billingFirstName, billingLastName, billingPhoneNumber,
billingEmail, string.Empty, string.Empty, billingAddress1, billingAddress2, billingCity,
billingStateProvinceId, billingZipPostalCode, billingCountryId);
if (billingAddress == null)
{
billingAddress = new Core.Domain.Common.Address()
{
FirstName = billingFirstName,
LastName = billingLastName,
PhoneNumber = billingPhoneNumber,
Email = billingEmail,
Address1 = billingAddress1,
Address2 = billingAddress2,
City = billingCity,
StateProvinceId = billingStateProvinceId,
ZipPostalCode = billingZipPostalCode,
CountryId = billingCountryId,
CreatedOnUtc = DateTime.UtcNow,
};
customer.Addresses.Add(billingAddress);
}
//set default billing address
customer.BillingAddress = billingAddress;
_customerService.UpdateCustomer(customer);
_genericAttributeService.SaveAttribute<ShippingOption>(customer, SystemCustomerAttributeNames.LastShippingOption, null);
bool shoppingCartRequiresShipping = cart.RequiresShipping();
if (shoppingCartRequiresShipping)
{
string[] shippingFullname = newOrderNotification.buyershippingaddress.contactname.Trim().Split(new char[] { ' ' }, 2, StringSplitOptions.RemoveEmptyEntries);
string shippingFirstName = shippingFullname[0];
string shippingLastName = string.Empty;
if (shippingFullname.Length > 1)
shippingLastName = shippingFullname[1];
string shippingEmail = newOrderNotification.buyershippingaddress.email.Trim();
string shippingAddress1 = newOrderNotification.buyershippingaddress.address1.Trim();
string shippingAddress2 = newOrderNotification.buyershippingaddress.address2.Trim();
string shippingPhoneNumber = newOrderNotification.buyershippingaddress.phone.Trim();
string shippingCity = newOrderNotification.buyershippingaddress.city.Trim();
int? shippingStateProvinceId = null;
var shippingStateProvince = _stateProvinceService.GetStateProvinceByAbbreviation(newOrderNotification.buyershippingaddress.region.Trim());
if (shippingStateProvince != null)
shippingStateProvinceId = shippingStateProvince.Id;
int? shippingCountryId = null;
string shippingZipPostalCode = newOrderNotification.buyershippingaddress.postalcode.Trim();
var shippingCountry = _countryService.GetCountryByTwoLetterIsoCode(newOrderNotification.buyershippingaddress.countrycode.Trim());
if (shippingCountry != null)
shippingCountryId = shippingCountry.Id;
var shippingAddress = customer.Addresses.ToList().FindAddress(
shippingFirstName, shippingLastName, shippingPhoneNumber,
shippingEmail, string.Empty, string.Empty,
shippingAddress1, shippingAddress2, shippingCity,
shippingStateProvinceId, shippingZipPostalCode, shippingCountryId);
if (shippingAddress == null)
{
shippingAddress = new Core.Domain.Common.Address()
{
FirstName = shippingFirstName,
LastName = shippingLastName,
PhoneNumber = shippingPhoneNumber,
Email = shippingEmail,
Address1 = shippingAddress1,
Address2 = shippingAddress2,
City = shippingCity,
StateProvinceId = shippingStateProvinceId,
ZipPostalCode = shippingZipPostalCode,
CountryId = shippingCountryId,
CreatedOnUtc = DateTime.UtcNow,
};
customer.Addresses.Add(shippingAddress);
}
//set default shipping address
customer.ShippingAddress = shippingAddress;
_customerService.UpdateCustomer(customer);
if (newOrderNotification.orderadjustment != null &&
newOrderNotification.orderadjustment.shipping != null &&
newOrderNotification.orderadjustment.shipping.Item != null)
{
var shippingMethod = (FlatRateShippingAdjustment)newOrderNotification.orderadjustment.shipping.Item;
var shippingOption = new ShippingOption();
shippingOption.Name = shippingMethod.shippingname;
shippingOption.Rate = shippingMethod.shippingcost.Value; _genericAttributeService.SaveAttribute(customer, SystemCustomerAttributeNames.LastShippingOption, shippingOption);
}
}