コード例 #1
0
        /// <summary>
        /// Create Inbound Shipment
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnCreateInboundShipment_Click(object sender, RoutedEventArgs e)
        {
            string SellerId           = CommonValue.strMerchantId;
            string MarketplaceId      = CommonValue.strMarketplaceId;
            string AccessKeyId        = CommonValue.strAccessKeyId;
            string SecretKeyId        = CommonValue.strSecretKeyId;
            string ApplicationVersion = CommonValue.strApplicationVersion;
            string ApplicationName    = CommonValue.strApplicationName;
            string MWSAuthToken       = CommonValue.strMWSAuthToken;
            string strbuff            = string.Empty;

            FBAInboundServiceMWSConfig config = new FBAInboundServiceMWSConfig();

            config.ServiceURL = CommonValue.strServiceURL;

            FBAInboundServiceMWSClient client = new FBAInboundServiceMWSClient(
                AccessKeyId,
                SecretKeyId,
                ApplicationName,
                ApplicationVersion,
                config);
            CreateInboundShipmentPlanRequest request = new CreateInboundShipmentPlanRequest();

            request.SellerId     = SellerId;
            request.Marketplace  = MarketplaceId;
            request.MWSAuthToken = MWSAuthToken;
            Address shipFromAddress = new Address();

            shipFromAddress.AddressLine1        = txtAddress11.Text;
            shipFromAddress.AddressLine2        = txtAddress21.Text;
            shipFromAddress.City                = txtCity1.Text;
            shipFromAddress.StateOrProvinceCode = txtPrefecture1.Text;
            shipFromAddress.Name                = txtName1.Text;
            shipFromAddress.PostalCode          = txtPostalCode1.Text;
            shipFromAddress.CountryCode         = "JP";
            request.ShipFromAddress             = shipFromAddress;
            request.LabelPrepPreference         = "SELLER_LABEL";
            request.ShipToCountryCode           = "JP";
            InboundShipmentPlanRequestItemList itemList = new InboundShipmentPlanRequestItemList();
            InboundShipmentPlanRequestItem     item     = new InboundShipmentPlanRequestItem();

            item.SellerSKU = txtSKU1.Text;
            item.Quantity  = 1;
            itemList.member.Add(item);
            request.WithInboundShipmentPlanRequestItems(itemList);
            CreateInboundShipmentPlanResponse response = client.CreateInboundShipmentPlan(request);

            if (response.IsSetCreateInboundShipmentPlanResult())
            {
                CreateInboundShipmentPlanResult createInboundShipmentPlanResult = response.CreateInboundShipmentPlanResult;
                if (createInboundShipmentPlanResult.IsSetInboundShipmentPlans())
                {
                    InboundShipmentPlanList    inboundShipmentPlans = createInboundShipmentPlanResult.InboundShipmentPlans;
                    List <InboundShipmentPlan> memberList           = inboundShipmentPlans.member;
                    foreach (InboundShipmentPlan member in memberList)
                    {
                        if (member.IsSetShipmentId())
                        {
                            CreateInboundShipmentRequest request1 = new CreateInboundShipmentRequest();

                            request1.SellerId     = SellerId;
                            request1.Marketplace  = MarketplaceId;
                            request1.MWSAuthToken = MWSAuthToken;
                            request1.ShipmentId   = member.ShipmentId;

                            InboundShipmentHeader inboundShipmentHeader = new InboundShipmentHeader();
                            inboundShipmentHeader.ShipFromAddress     = shipFromAddress;
                            inboundShipmentHeader.LabelPrepPreference = "SELLER_LABEL";
                            inboundShipmentHeader.ShipmentName        = txtSKU1.Text;
                            request1.InboundShipmentHeader            = inboundShipmentHeader;
                            InboundShipmentItemList itemList1 = new InboundShipmentItemList();
                            InboundShipmentItem     item1     = new InboundShipmentItem();
                            item1.SellerSKU       = txtSKU1.Text;
                            item1.QuantityShipped = 1;
                            itemList1.member.Add(item1);
                            request1.WithInboundShipmentItems(itemList1);
                            request1.InboundShipmentHeader.DestinationFulfillmentCenterId = member.DestinationFulfillmentCenterId;
                            CreateInboundShipmentResponse response1 = client.CreateInboundShipment(request1);
                            if (response1.IsSetCreateInboundShipmentResult())
                            {
                                strbuff = "処理が正常に完了しました。";
                            }
                            else
                            {
                                strbuff = "処理時にエラーが発生しました。";
                            }
                        }
                    }
                }
            }
            txtCreateInboundShipment.Text = strbuff;
        }
        private CreatedShipment CreateShipment(
            InboundShipmentPlan inboundShipmentPlan,
            Dictionary <string, ShipmentItem> itemsToBeAddedToShipment,
            Address shipsFromAddress,
            string shipmentName,
            bool areCasesRequired,
            DateTime today)
        {
            List <InboundShipmentItem> inboundShipmentItems = new List <InboundShipmentItem>();

            foreach (InboundShipmentPlanItem inboundShipmentPlanItem in inboundShipmentPlan.Items.member)
            {
                if (itemsToBeAddedToShipment.ContainsKey(inboundShipmentPlanItem.SellerSKU))
                {
                    ShipmentItem shipmentItem = itemsToBeAddedToShipment[inboundShipmentPlanItem.SellerSKU];

                    InboundShipmentItem inboundShipmentItem = new InboundShipmentItem
                    {
                        FulfillmentNetworkSKU = inboundShipmentPlanItem.FulfillmentNetworkSKU,
                        SellerSKU             = inboundShipmentPlanItem.SellerSKU,
                        QuantityShipped       = inboundShipmentPlanItem.Quantity,
                        QuantityInCase        = shipmentItem.QuantityInCase ?? 0,
                        ShipmentId            = inboundShipmentPlan.ShipmentId
                    };

                    inboundShipmentItems.Add(inboundShipmentItem);
                }
            }

            string shipmentNameHeader = string.Concat(
                shipmentName,
                "_",
                inboundShipmentPlan.DestinationFulfillmentCenterId,
                "-",
                inboundShipmentPlan.LabelPrepType,
                "_",
                today.ToShortDateString());

            InboundShipmentHeader header = new InboundShipmentHeader
            {
                AreCasesRequired = areCasesRequired,
                ShipmentName     = shipmentNameHeader,
                DestinationFulfillmentCenterId = inboundShipmentPlan.DestinationFulfillmentCenterId,
                ShipFromAddress = shipsFromAddress,
                ShipmentStatus  = "WORKING"
            };

            InboundShipmentItemList inboundShipmentItemList = new InboundShipmentItemList {
                member = inboundShipmentItems
            };

            CreateInboundShipmentRequest request = new CreateInboundShipmentRequest
            {
                InboundShipmentItems  = inboundShipmentItemList,
                Marketplace           = m_marketPlaceId,
                SellerId              = m_sellerId,
                ShipmentId            = inboundShipmentPlan.ShipmentId,
                InboundShipmentHeader = header,
            };

            CreateInboundShipmentResponse createInboundShipmentResponse = m_fbaInboundServiceMwsClient.CreateInboundShipment(request);

            List <ShipmentItem> itemsInShipment = inboundShipmentItems
                                                  .Select(s =>
            {
                ShipmentItem shipmentItem = new ShipmentItem
                {
                    Asin           = s.FulfillmentNetworkSKU,
                    Sku            = s.SellerSKU,
                    Quantity       = s.QuantityShipped,
                    QuantityInCase = s.QuantityInCase
                };

                if (itemsToBeAddedToShipment.ContainsKey(s.SellerSKU))
                {
                    ShipmentItem originalShipmentItem = itemsToBeAddedToShipment[s.SellerSKU];

                    shipmentItem.Name       = originalShipmentItem.Name;
                    shipmentItem.ItemNumber = originalShipmentItem.ItemNumber;
                    shipmentItem.Cost       = originalShipmentItem.Cost;
                }
                else
                {
                    throw new InvalidOperationException(string.Format("SKU : {0} should not be in this shipment.", s.SellerSKU));
                }

                return(shipmentItem);
            })
                                                  .ToList();

            return(new CreatedShipment(
                       inboundShipmentPlan.DestinationFulfillmentCenterId,
                       inboundShipmentPlan.LabelPrepType,
                       createInboundShipmentResponse.CreateInboundShipmentResult.ShipmentId,
                       itemsInShipment));
        }