0

我的目标是让列表显示“免费国际送货”。尝试设置国际选项,它说我需要设置ShipToLocation我尝试了以下行:

internationalShippingOptions.ShipToLocation.Add("Worldwide");

但是当程序点击它时,我得到了这个错误:

"Object reference not set to an instance of an object"

如果您想查看完整的方法,它是:

    static ShippingDetailsType BuildShippingDetails()
    {

        ShippingDetailsType sd = new ShippingDetailsType();
        sd.ApplyShippingDiscount = false;
        sd.ShippingType = ShippingTypeCodeType.Flat;

        AmountType amount = new AmountType();
        amount.Value = 0;
        amount.currencyID = CurrencyCodeType.USD;            

        ShippingServiceOptionsTypeCollection shippingOptions = new ShippingServiceOptionsTypeCollection();

        ShippingServiceOptionsType domesticShippingOptions = new ShippingServiceOptionsType();
        domesticShippingOptions.ShippingService = ShippingServiceCodeType.EconomyShippingFromOutsideUS.ToString();
        domesticShippingOptions.FreeShipping = true;
        domesticShippingOptions.ShippingServiceCost = amount;
        domesticShippingOptions.ShippingServicePriority = 1;
        shippingOptions.Add(domesticShippingOptions);

        ShippingServiceOptionsType internationalShippingOptions = new ShippingServiceOptionsType();
        InternationalShippingServiceOptionsType internationalShippingOptions = new InternationalShippingServiceOptionsType();
        internationalShippingOptions.ShippingService = ShippingServiceCodeType.StandardInternational.ToString();
        internationalShippingOptions.ShipToLocation.Add("Worldwide");
        internationalShippingOptions.FreeShipping = true;

        sd.InternationalShippingServiceOption = new InternationalShippingServiceOptionsTypeCollection(new InternationalShippingServiceOptionsType[] { internationalShippingOptions });
        sd.ShippingServiceOptions = shippingOptions;

        return sd;
    }
4

1 回答 1

0

这是使其显示“免费标准国际运输”的代码。起初在沙盒中显示“免费标准配送”,但如果您在沙盒中更改配送目的地,它会显示“免费标准国际配送”。

    static ShippingDetailsType BuildShippingDetails()
    {
        // Shipping details
        ShippingDetailsType sd = new ShippingDetailsType();

        sd.ApplyShippingDiscount = true;
        sd.PaymentInstructions = "eBay .Net SDK test instruction.";
        sd.ShippingRateType = ShippingRateTypeCodeType.StandardList;

        // Shipping type and shipping service options
        //adding international shipping
        InternationalShippingServiceOptionsType internationalShipping1 = new InternationalShippingServiceOptionsType();
        internationalShipping1.ShippingService = ShippingServiceCodeType.StandardInternational.ToString();
        internationalShipping1.ShippingServiceCost = new AmountType { Value = 0, currencyID = CurrencyCodeType.USD };
        internationalShipping1.ShippingServicePriority = 1;
        internationalShipping1.ShipToLocation = new StringCollection(new[] { "Worldwide" });
        sd.ShippingServiceUsed = ShippingServiceCodeType.StandardInternational.ToString();
        sd.InternationalShippingServiceOption = new InternationalShippingServiceOptionsTypeCollection(new[] { internationalShipping1 });

        //adding domestic shipping
        ShippingServiceOptionsType domesticShipping1 = new ShippingServiceOptionsType();
        domesticShipping1.ShippingService = ShippingServiceCodeType.ShippingMethodStandard.ToString();
        domesticShipping1.ShippingServiceCost = new AmountType { Value = 0, currencyID = CurrencyCodeType.USD };
        domesticShipping1.ShippingInsuranceCost = new AmountType { Value = 0, currencyID = CurrencyCodeType.USD };
        domesticShipping1.ShippingServicePriority = 4;
        domesticShipping1.LocalPickup = true;
        domesticShipping1.FreeShipping = true;
        sd.ShippingServiceOptions = new ShippingServiceOptionsTypeCollection(new[] { domesticShipping1 });
        sd.ShippingType = ShippingTypeCodeType.Flat;

        return sd;

调用方法:

 item.ShippingDetails = BuildShippingDetails();
于 2013-06-13T00:45:05.177 回答