Пример #1
0
        private dynamic MapToBonanzaDto(ListingDto listingDto, bool includeProductData, bool includeTemplate)
        {
            dynamic item = new ExpandoObject();

            if (!string.IsNullOrEmpty(listingDto.Sku))
            {
                item.sku = listingDto.Sku;
            }

            if (!string.IsNullOrEmpty(listingDto.Title))
            {
                item.title = listingDto.Title;
            }

            if (includeTemplate)
            {
                string designName = string.IsNullOrWhiteSpace(listingDto.Design) ? "default" : listingDto.Design;

                item.description = GetDesign(designName).Replace("<!-- INSERT FULL DESCRIPTION -->", listingDto.FullDescription);
            }

            item.primaryCategory            = new ExpandoObject();
            item.primaryCategory.categoryId = "Guess";

            if (listingDto.PicUrls.Count > 0)
            {
                item.pictureDetails            = new ExpandoObject();
                item.pictureDetails.pictureURL = listingDto.PicUrls.ToArray();
            }

            if (includeTemplate)
            {
                item.shippingDetails = new ExpandoObject();

                dynamic localOption = new ExpandoObject();
                localOption.shippingType = "Free";
                localOption.freeShipping = true;

                item.shippingDetails.shippingServiceOptions = new[] { localOption };

                dynamic worldwideOption = new ExpandoObject();
                worldwideOption.shippingType        = "Fixed";
                worldwideOption.shippingServiceCost = 29.95;
                worldwideOption.shipToLocation      = "Worldwide";

                dynamic canadaOption = new ExpandoObject();
                canadaOption.shippingType        = "Fixed";
                canadaOption.shippingServiceCost = 17.99;
                canadaOption.shipToLocation      = "Canada";

                item.shippingDetails.internationalShippingServiceOption = new[] { worldwideOption, canadaOption };


                item.returnPolicy = new ExpandoObject();
                item.returnPolicy.returnsAcceptedOption    = "ReturnsAccepted";
                item.returnPolicy.description              = "Items must not be worn and should be returned in their original box and packaging. Buyer is responsible for return shipping costs. Once we receive you return, we will refund the cost of the product only. We don&#39;t refund original shipping charges. Also, when returning an article of clothing please return it with its respective tags, unworn, and in its original packaging.";
                item.returnPolicy.returnsWithinOption      = 30;
                item.returnPolicy.shippingCostPaidByOption = "buyer";
            }

            if (listingDto.Items.Any(p => p.Price.HasValue))
            {
                item.price = Convert.ToDouble(listingDto.Items.First(p => p.Price.HasValue).Price.Value);
            }

            if (!listingDto.IsVariation)
            {
                ListingItemDto listingItemDto = listingDto.Items.First();

                if (listingItemDto.Qty.HasValue)
                {
                    item.quantity = listingItemDto.Qty.Value;
                }

                if (includeProductData)
                {
                    ProductMapper mapper = _productMapperFactory.GetProductMapper(_dataContext.Items.Single(p => p.ItemLookupCode.Equals(listingItemDto.Sku)));

                    var itemSpecifics = mapper.GetItemSpecifics().Concat(mapper.GetVariationSpecifics()).ToArray();

                    item.itemSpecifics = itemSpecifics.Select(p => new [] { p.Name, p.Value }).ToArray();
                }
            }
            else
            {
                if (includeProductData)
                {
                    string sku = listingDto.Items.First().Sku;

                    ProductMapper mapper = _productMapperFactory.GetProductMapper(_dataContext.Items.Single(p => p.ItemLookupCode.Equals(sku)));

                    var itemSpecifics = mapper.GetItemSpecifics().ToArray();

                    item.itemSpecifics = itemSpecifics.Select(p => new[] { p.Name, p.Value }).ToArray();
                }

                List <ExpandoObject> variations = new List <ExpandoObject>();

                foreach (ListingItemDto listingItemDto in listingDto.Items)
                {
                    dynamic variationDto = new ExpandoObject();

                    if (listingItemDto.Qty.HasValue)
                    {
                        variationDto.quantity = listingItemDto.Qty.Value;
                    }

                    if (includeProductData)
                    {
                        ProductMapper productData = _productMapperFactory.GetProductMapper(_dataContext.Items.Single(p => p.ItemLookupCode.Equals(listingItemDto.Sku)));
                        variationDto.nameValueList = productData.GetVariationSpecifics().Select(p => new { name = p.Name, value = p.Value }).ToArray();
                    }

                    variations.Add(variationDto);
                }

                item.variations = variations.ToArray();
            }

            return(item);
        }