public static FileuploadMessage ToEdgeFileuploadExportMessage(this List <ProductLocalizedImage> images, string providerCode,
                                                                      string xrefMerchantId)
        {
            var message = new FileuploadMessage();

            var head = new MessageHead
            {
                Sender      = new MessageHeadSender[1],
                Recipient   = new MessageHeadRecipient[1],
                Messageid   = Guid.NewGuid().ToString(),
                Messagetype = "Fileupload",
                Date        = DateTime.Now.ToString(CultureInfo.InvariantCulture)
            };
            var sender = new MessageHeadSender {
                Systemid = providerCode
            };

            head.Sender[0] = sender;

            var recipient = new MessageHeadRecipient {
                Companyid = xrefMerchantId
            };

            head.Recipient[0] = recipient;
            message.Items     = new object[2];
            message.Items[0]  = head;


            var fileupload = new MessageBodyFileupload();

            if (images != null)
            {
                fileupload.Files = new MessageBodyFileuploadFilesFile[images.Count];

                for (var i = 0; i < images.Count; i++)
                {
                    fileupload.Files[i] = new MessageBodyFileuploadFilesFile
                    {
                        Title     = images[i].ImageLabel,
                        Filename  = images[i].ImageLabel,
                        Fileclass = "image",
                        FileLink  = String.Format("{0}{1}",
                                                  images[i].ImageUrl.Contains("http:")
                        ? "" : "http:", images[i].ImageUrl),
                        Locales = new[] { new MessageBodyFileuploadFilesFileLocalesLocale {
                                              Description = String.Empty, Title = String.Empty, LocaleCode = String.Empty
                                          } }
                    };
                }
            }

            var body = new FileuploadMessageBody {
                Fileupload = new[] { fileupload }
            };

            message.Items[1] = body;
            return(message);
        }
示例#2
0
        public static CatalogMessage ToEdgeProductExportMessage(this Product product, string providerCode, string xrefMerchantId)
        {
            var message = new CatalogMessage();

            var head = new MessageHead
            {
                Sender      = new MessageHeadSender[1],
                Recipient   = new MessageHeadRecipient[1],
                Messageid   = Guid.NewGuid().ToString(),
                Messagetype = "Catalogimport",
                Date        = DateTime.Now.ToString(CultureInfo.InvariantCulture)
            };
            var sender = new MessageHeadSender {
                Systemid = providerCode
            };

            head.Sender[0] = sender;

            var recipient = new MessageHeadRecipient {
                Companyid = xrefMerchantId
            };

            head.Recipient[0] = recipient;
            message.Items     = new object[2];
            message.Items[0]  = head;

            var body = new CatalogMessageBody {
                Catalogimport = new MessageBodyCatalogimport[1]
            };

            var status         = StatusCode.Active;
            var prodInCatatlog = product.ProductInCatalogs.FirstOrDefault();

            if (prodInCatatlog != null)
            {
                status = prodInCatatlog.IsActive.GetValueOrDefault() ? StatusCode.Active : StatusCode.Inactive;
            }

            var taxcode            = product.GetPropertyValue(AttributeConstants.TaxCode);
            var catalogImportField = new MessageBodyCatalogimport
            {
                Skus = new[] { new MessageBodyCatalogimportSkus {
                                   Sku = product.ProductCode
                               } },
                Itemtypename = String.Empty,
                Uomname      = String.Join(",", product.GetPropertyListValue(AttributeConstants.UnitOfMeasure)),
                Filenames    = new MessageBodyCatalogimportFilenamesFilename[] { },
                Projects     = new[] { new MessageBodyCatalogimportProjectsProject {
                                           Value = "Aubuchon"
                                       } },
                Categories          = new MessageBodyCatalogimportCategoriesCategoryCode[] { },
                Prerequisites       = new Prerequisites[] { },
                Deliverymethodcodes = new[] { new MessageBodyCatalogimportDeliverymethodcodes {
                                                  Deliverymethodcode = "Ship"
                                              } },
                PriceLists                = new MessageBodyCatalogimportPriceListsPriceList[] { },
                Dynamicfields             = new MessageBodyCatalogimportDynamicfieldsDynamicfield[3],
                CatalogTaxClassCode       = String.IsNullOrEmpty(taxcode) ? "P0000000" : taxcode,
                Catalogitem               = product.ProductCode,
                Catalogname               = product.Content.ProductName,
                Catalognotes              = String.Empty,
                Shortdescription          = System.Security.SecurityElement.Escape(product.Content.ProductShortDescription),
                Longdescription           = System.Security.SecurityElement.Escape(product.Content.ProductFullDescription),
                Retailprice               = Convert.ToString(product.Price.Price),
                Downloadable              = "0",
                Taxable                   = product.IsTaxable.GetValueOrDefault() ? "1" : "0",
                Minorderqty               = String.Empty,
                Maxorderqty               = String.Empty,
                Iselectronic              = "0",
                Allowautoship             = "0",
                Chargeshipping            = "1",
                Taxresellers              = "1",
                Budgetitem                = "0",
                Startdate                 = DateTime.Today.ToString("yyyy-MM-dd"),
                Searchable                = "1",
                Statuscode                = Enum.GetName(typeof(StatusCode), status),
                Custodianusername         = "******",
                Defaultdeliverymethodcode = "Ship",
                Shippingamount            = product.GetPropertyStringValue(AttributeConstants.ShippingSurcharge) ?? String.Empty,
                Handlingamount            = String.Empty,
                Salesaccount              = String.Empty,
                Sortorder                 = String.Empty,//TODO:What should be the value?
                Enddate                   = String.Empty,
                Catalogcode               = String.Empty,
                Dutytax                   = String.Empty,
                Orderquantity             = String.Empty
            };



            if (product.Content.ProductImages != null)
            {
                catalogImportField.Filenames =
                    new MessageBodyCatalogimportFilenamesFilename[product.Content.ProductImages.Count];



                for (var i = 0; product.Content.ProductImages != null && i < product.Content.ProductImages.Count; i++)
                {
                    var fileName = new MessageBodyCatalogimportFilenamesFilename
                    {
                        Value = product.Content.ProductImages[i].ImageLabel
                    };

                    if (i == 0)
                    {
                        fileName.Default = "true";
                    }
                    catalogImportField.Filenames[i] = fileName;
                }
            }

            var freeAssembly       = product.GetExtraValue(AttributeConstants.FreeAssembly);
            var instantReward      = product.GetPropertyStringValue(AttributeConstants.InstantRewards) ?? String.Empty;
            var instantRewardAdmin = product.GetPropertyStringValue(AttributeConstants.InstantRewardsAdmin) ?? String.Empty;

            for (var i = 0; i < 3; i++)
            {
                if (freeAssembly > 0)
                {
                    catalogImportField.Dynamicfields[i] = new MessageBodyCatalogimportDynamicfieldsDynamicfield
                    {
                        Dynamicfieldcode  = "assembleable",
                        DynamicFieldLabel = "Eligible for Assembly?",
                        Dynamicfieldvalue = Convert.ToString(freeAssembly)
                    };
                    i++;
                }
                if (!String.IsNullOrEmpty(instantReward))
                {
                    catalogImportField.Dynamicfields[i] = new MessageBodyCatalogimportDynamicfieldsDynamicfield
                    {
                        Dynamicfieldcode  = "instant-reward",
                        DynamicFieldLabel = "Instant Reward",
                        Dynamicfieldvalue = instantReward
                    };
                    i++;
                }
                if (String.IsNullOrEmpty(instantRewardAdmin))
                {
                    continue;
                }
                catalogImportField.Dynamicfields[i] = new MessageBodyCatalogimportDynamicfieldsDynamicfield
                {
                    Dynamicfieldcode  = "instant_reward_admin_catalog",
                    DynamicFieldLabel = "Instant Reward Admin",
                    Dynamicfieldvalue = instantRewardAdmin
                };
                i++;
            }



            body.Catalogimport[0] = catalogImportField;

            message.Items[1] = body;

            return(message);
        }
        public static InventoryMessage ToEdgeInventoryExportMessage(this Product product, string providerCode,
                                                                    string xrefMerchantId, IList <LocationInventory> locations)
        {
            var message = new InventoryMessage();

            var head = new MessageHead
            {
                Sender      = new MessageHeadSender[1],
                Recipient   = new MessageHeadRecipient[1],
                Messageid   = Guid.NewGuid().ToString(),
                Messagetype = "Inventoryimport",
                Date        = DateTime.Now.ToString(CultureInfo.InvariantCulture)
            };
            var sender = new MessageHeadSender {
                Systemid = providerCode
            };

            head.Sender[0] = sender;

            var recipient = new MessageHeadRecipient {
                Companyid = xrefMerchantId
            };

            head.Recipient[0] = recipient;
            message.Items     = new object[2];
            message.Items[0]  = head;

            var status         = StatusCode.Active;
            var prodInCatatlog = product.ProductInCatalogs.FirstOrDefault();

            if (prodInCatatlog != null)
            {
                status = prodInCatatlog.IsActive.GetValueOrDefault() ? StatusCode.Active : StatusCode.Inactive;
            }

            var body = new InventoryMessageBody {
                Inventoryimport = new MessageBodyInventoryimport[1]
            };

            var inventoryImport = new MessageBodyInventoryimport
            {
                Sku                                                                    = product.ProductCode,
                Description                                                            = product.Content.ProductName,
                Skutypecode                                                            = "Standard",
                Manufacturername                                                       = product.GetPropertyStringLabel(AttributeConstants.Brand) ?? String.Empty,
                Uomname                                                                = product.GetPropertyStringLabel(AttributeConstants.UnitOfMeasure) ?? String.Empty,
                Manufacturerpartno                                                     = product.SupplierInfo.MfgPartNumber ?? String.Empty,//TODO:Check the actual mapping
                Width                                                                  = product.PackageWidth != null?Convert.ToString(product.PackageWidth.Value) : "0.1",
                                                      Cost                             = product.SupplierInfo.Cost.Cost.ToString(),
                                                      Reorderpoint                     = String.Empty,
                                                      Maxbuildqty                      = String.Empty,
                                                      Qtyperpackage                    = String.Empty,
                                                      Leadtime                         = String.Empty,
                                                      Allowbackorder                   = product.InventoryInfo.OutOfStockBehavior == "AllowBackOrder" ? "1" : "0",
                                                      Statuscode                       = Enum.GetName(typeof(StatusCode), status),
                                                      Statusdate                       = String.Empty,
                                                      Custodianusername                = "******",
                                                      Parentsku                        = String.Empty,
                                                      Inventory                        = "1",
                                                      Returnable                       = "1",
                                                      Refundable                       = "1",
                                                      Restockable                      = "1",
                                                      Obsolete                         = "0",
                                                      Weight                           = product.PackageWeight != null?Convert.ToString(product.PackageWeight.Value) : "0.1",
                                                                                Length = product.PackageLength != null?Convert.ToString(product.PackageLength.Value) : "0.1",
                                                                                             Height = product.PackageHeight != null?Convert.ToString(product.PackageHeight.Value) : "0.1",
                                                                                                          Lwhunit          = String.Empty,
                                                                                                          Upcnumber        = product.Upc ?? String.Empty,//TODO:Check what should be the value if null
                                                                                                          Trademarkname    = String.Empty,
                                                                                                          Legacynumber     = String.Empty,
                                                                                                          Hazardclass      = product.GetPropertyBooleanValue(AttributeConstants.Hazardous) ? "1" : "0",
                                                                                                          Packaginggroup   = String.Empty,
                                                                                                          Colorname        = String.Empty,
                                                                                                          Sizename         = String.Empty,
                                                                                                          Stylename        = String.Empty,
                                                                                                          InventoryNotes   = String.Empty,
                                                                                                          Skuplacementcode = String.Empty,
                                                                                                          Forecasteddate   = String.Empty,
                                                                                                          Reorderrulecode  = String.Empty,
                                                                                                          Reorderqty       = String.Empty,
                                                                                                          Avgdailyusage    = String.Empty,
                                                                                                          Secureshipment   = String.Empty,
                                                                                                          Graceperiod      = String.Empty,
                                                                                                          Docktostock      = String.Empty,
                                                                                                          Minbuildqty      = String.Empty,
                                                                                                          Startdate        = DateTime.Today.ToString("yyyy-MM-dd"),
                                                                                                          Enddate          = String.Empty,
                                                                                                          Categories       = new MessageBodyInventoryimportCategoriesCategoryCode[]
                {
                },
                Providers = new MessageBodyInventoryimportProviders(),
                Suppliers = new MessageBodyInventoryimportSuppliers[] {  },
                Projects  = new[] { new MessageBodyInventoryimportProjectsProject {
                                        Value = "Aubuchon"
                                    } },
                Locales = new[] { new MessageBodyInventoryimportLocalesLocale
                                  {
                                      LocaleCode                      = "en-US",
                                      Description                     = product.Content.ProductName,
                                      InventoryNotes                  = product.Content.ProductShortDescription,
                                      RetailPrice                     = Convert.ToString(product.Price.Price),
                                      SalePrice                       = product.Price.SalePrice == null?Convert.ToString(product.Price.Price) : Convert.ToString(product.Price.SalePrice),
                                                                 Cost = Convert.ToString(product.SupplierInfo.Cost.Cost)
                                  } },
                Dynamicfields = new MessageBodyInventoryimportDynamicfieldsDynamicfield[] { },
            };

            if (product.Content.ProductImages != null)
            {
                inventoryImport.Filenames =
                    new MessageBodyInventoryimportFilenamesFilename[product.Content.ProductImages.Count];

                for (var i = 0; product.Content.ProductImages != null && i < product.Content.ProductImages.Count; i++)
                {
                    inventoryImport.Filenames[i] = new MessageBodyInventoryimportFilenamesFilename
                    {
                        Default = i == 0 ? "1" : "0",
                        Value   = product.Content.ProductImages[i].ImageLabel
                    };
                }
            }

            if (locations != null)
            {
                inventoryImport.Providers = new MessageBodyInventoryimportProviders
                {
                    ProviderCode = new MessageBodyInventoryimportProvidersProviderCode[locations.Count]
                };
                for (var i = 0; i < locations.Count; i++)
                {
                    inventoryImport.Providers.ProviderCode[i] = new MessageBodyInventoryimportProvidersProviderCode
                    {
                        ProviderCode = locations[i].LocationCode
                    };
                }
            }

            //inventoryImport.Suppliers = new MessageBodyInventoryimportSuppliers[1];
            //inventoryImport.Suppliers[0] = new MessageBodyInventoryimportSuppliers();

            //inventoryImport.Projects = new MessageBodyInventoryimportProjectsProject[1];
            //inventoryImport.Projects[0] = new MessageBodyInventoryimportProjectsProject();

            //inventoryImport.Locales = new MessageBodyInventoryimportLocalesLocale[1];

            //inventoryImport.Locales[0] = new MessageBodyInventoryimportLocalesLocale
            //{
            //    LocaleCode = "US-EN",
            //    Description = product.Content.ProductShortDescription,
            //    InventoryNotes = "test note",//TODO: Check the right mapping value as it is required
            //    RetailPrice = Convert.ToString(product.Price.Price),
            //    SalePrice = Convert.ToString(product.Price.SalePrice ?? product.Price.Price) //TODO:Check what should be passed if SalePrice is null
            //};

            //inventoryImport.Dynamicfields = new MessageBodyInventoryimportDynamicfieldsDynamicfield[1];
            body.Inventoryimport[0] = inventoryImport;
            message.Items[1]        = body;

            return(message);
        }