Example #1
0
        private void Persist(ListingDto listingDto, string sellingState)
        {
            using (berkeleyEntities dataContext = new berkeleyEntities())
            {
                BonanzaListing listing = new BonanzaListing();

                listing.MarketplaceID   = _marketplace.ID;
                listing.Code            = listingDto.Code;
                listing.FullDescription = listingDto.FullDescription;
                listing.Title           = listingDto.Title;
                listing.Status          = sellingState;
                listing.LastSyncTime    = DateTime.UtcNow;
                listing.Sku             = listingDto.Sku;
                listing.IsVariation     = listingDto.IsVariation;

                foreach (ListingItemDto listingItemDto in listingDto.Items)
                {
                    BonanzaListingItem listingItem = new BonanzaListingItem();
                    listingItem.Listing  = listing;
                    listingItem.Item     = dataContext.Items.Single(p => p.ItemLookupCode.Equals(listingItemDto.Sku));
                    listingItem.Quantity = listingItemDto.Qty.Value;
                    listingItem.Price    = listingItemDto.Price.Value;
                }

                dataContext.SaveChanges();
            }
        }
Example #2
0
        public void Revise(int marketplaceID, ListingDto listingDto, bool includeProductData, bool includeTemplate)
        {
            if (!_publishers.ContainsKey(marketplaceID))
            {
                _publishers.Add(marketplaceID, new Publisher(marketplaceID));
            }

            Publisher publisher = _publishers[marketplaceID];

            publisher.ReviseListing(listingDto, includeProductData, includeTemplate);
        }
Example #3
0
        public void Publish(int marketplaceID, ListingDto listingDto)
        {
            if (!_publishers.ContainsKey(marketplaceID))
            {
                _publishers.Add(marketplaceID, new Publisher(marketplaceID));
            }

            Publisher publisher = _publishers[marketplaceID];

            publisher.AddListing(listingDto);
        }
Example #4
0
        private void Update(ListingDto listingDto)
        {
            using (berkeleyEntities dataContext = new berkeleyEntities())
            {
                BonanzaListing listing = dataContext.BonanzaListings.Single(p => p.MarketplaceID == _marketplace.ID && p.Code.Equals(listingDto.Code));

                if (!string.IsNullOrWhiteSpace(listingDto.FullDescription))
                {
                    listing.FullDescription = listingDto.FullDescription;
                }

                if (!string.IsNullOrWhiteSpace(listingDto.Title))
                {
                    listing.Title = listingDto.Title;
                }

                foreach (ListingItemDto listingItemDto in listingDto.Items)
                {
                    Item item = dataContext.Items.Single(p => p.ItemLookupCode.Equals(listingItemDto.Sku));

                    BonanzaListingItem listingItem = listing.ListingItems.SingleOrDefault(p => p.Item.ID == item.ID);

                    if (listingItem == null)
                    {
                        listingItem = new BonanzaListingItem()
                        {
                            Item = item, Listing = listing
                        };
                    }

                    if (listingItemDto.Qty.HasValue)
                    {
                        listingItem.Quantity = listingItemDto.Qty.Value;
                    }

                    if (listingItemDto.Price.HasValue)
                    {
                        listingItem.Price = listingItemDto.Price.Value;
                    }
                }

                listing.LastSyncTime = DateTime.UtcNow;

                dataContext.SaveChanges();
            }
        }
Example #5
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);
        }
Example #6
0
        public void ReviseListing(ListingDto listingDto, bool includeProductData, bool includeTemplate)
        {
            HttpWebRequest request = WebRequest.CreateHttp("https://api.bonanza.com/api_requests/secure_request");

            request.Headers.Add("X-BONANZLE-API-DEV-NAME", "vWhzo4w8l7sKDUT");
            request.Headers.Add("X-BONANZLE-API-CERT-NAME", "YOL7ZWkbcBJGKTI");

            request.ContentType = "application/json";

            ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(AcceptAllCertifications);

            request.Method = "POST";

            dynamic reviseFixedPriceItemRequest = new ExpandoObject();

            reviseFixedPriceItemRequest.requesterCredentials = new ExpandoObject();
            reviseFixedPriceItemRequest.requesterCredentials.bonanzleAuthToken = _marketplace.Token;
            reviseFixedPriceItemRequest.item   = MapToBonanzaDto(listingDto, includeProductData, includeTemplate);
            reviseFixedPriceItemRequest.itemId = int.Parse(listingDto.Code);

            dynamic jsonPayload = new ExpandoObject();

            jsonPayload.reviseFixedPriceItemRequest = reviseFixedPriceItemRequest;

            byte[] contentBytes = Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(jsonPayload));

            request.ContentLength = contentBytes.Length;

            using (Stream stream = request.GetRequestStream())
            {
                stream.Write(contentBytes, 0, contentBytes.Length);
            }

            try
            {
                HttpWebResponse response = (HttpWebResponse)request.GetResponse();

                string output = null;

                using (StreamReader sr = new StreamReader(response.GetResponseStream(), Encoding.UTF8))
                {
                    output = sr.ReadToEnd();
                }

                dynamic result = Newtonsoft.Json.JsonConvert.DeserializeObject <dynamic>(output);

                string ack = result.ack;

                if (ack.Equals("Success"))
                {
                    Update(listingDto);
                }
            }
            catch (WebException e)
            {
                using (WebResponse response = e.Response)
                {
                    var httpResponse = (HttpWebResponse)response;

                    using (Stream data = response.GetResponseStream())
                    {
                        StreamReader sr = new StreamReader(data);
                        throw new Exception(sr.ReadToEnd());
                    }
                }
            }
        }
Example #7
0
        public void AddListing(ListingDto listingDto)
        {
            var pics = _picSetRepository.GetPictures(listingDto.Brand, listingDto.Items.Select(p => p.Sku).ToList()).Take(4).OrderBy(p => p.Name);

            if (pics.Count() == 0)
            {
                throw new InvalidOperationException("picture required");
            }

            foreach (var pic in pics)
            {
                listingDto.PicUrls.Add(pic.Path.Replace("\\", "/").Replace(LOCAL_PICTURE_ROOT, S3_PICTURE_URL_ROOT));
            }

            HttpWebRequest request = WebRequest.CreateHttp("https://api.bonanza.com/api_requests/secure_request");

            request.Headers.Add("X-BONANZLE-API-DEV-NAME", "vWhzo4w8l7sKDUT");
            request.Headers.Add("X-BONANZLE-API-CERT-NAME", "YOL7ZWkbcBJGKTI");

            request.ContentType = "application/json";

            ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(AcceptAllCertifications);

            request.Method = "POST";

            dynamic addFixedPriceItemRequest = new ExpandoObject();

            addFixedPriceItemRequest.requesterCredentials = new ExpandoObject();
            addFixedPriceItemRequest.requesterCredentials.bonanzleAuthToken = _marketplace.Token;
            addFixedPriceItemRequest.item = MapToBonanzaDto(listingDto, true, true);

            dynamic jsonPayload = new ExpandoObject();

            jsonPayload.addFixedPriceItemRequest = addFixedPriceItemRequest;

            byte[] contentBytes = Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(jsonPayload));

            request.ContentLength = contentBytes.Length;

            using (Stream stream = request.GetRequestStream())
            {
                stream.Write(contentBytes, 0, contentBytes.Length);
            }

            try
            {
                HttpWebResponse response = (HttpWebResponse)request.GetResponse();

                string output = null;

                using (StreamReader sr = new StreamReader(response.GetResponseStream(), Encoding.UTF8))
                {
                    output = sr.ReadToEnd();
                }

                dynamic result = Newtonsoft.Json.JsonConvert.DeserializeObject <dynamic>(output);

                string ack = result.ack;

                if (ack.Equals("Success"))
                {
                    string itemID       = result.addFixedPriceItemResponse.itemId;
                    string sellingState = result.addFixedPriceItemResponse.sellingState;

                    listingDto.Code = itemID;

                    Persist(listingDto, sellingState);
                }
            }
            catch (WebException e)
            {
                using (WebResponse response = e.Response)
                {
                    var httpResponse = (HttpWebResponse)response;

                    using (Stream data = response.GetResponseStream())
                    {
                        StreamReader sr = new StreamReader(data);
                        throw new Exception(sr.ReadToEnd());
                    }
                }
            }
        }