Ejemplo n.º 1
0
        private void WriteFeedFile(XmlWriter xmlWriter, FeedGenerationFileInstruction fileInstruction)
        {
            var countRec = new Tuple <int, int, int>(0, 0, 0);

            xmlWriter.WriteStartDocument();
            xmlWriter.WriteDocType("product_catalog_data", null, DocTypeSystemId, null);
            xmlWriter.WriteStartElement("product_catalog_data");
            var header = new XE("header");

            header.Add(new XE("cid", Cid));
            header.Add(new XE("subid", SubId));
            //header.Add(new XE("datefmt", DateFormatString));
            header.Add(new XE("processtype", (_isIncrementalRun) ? "UPDATE" : "OVERWRITE"));
            header.Add(new XE("aid", fileInstruction.Aid));

            header.WriteTo(xmlWriter);

            //<feedGenerationFileLineItem isIncluded="true" catalog="books" storedProcedureName="uspCJFeedBooks" catalogattributesection="booksattributes" ranges="00-04;05-09" />
            foreach (var fileComponent in fileInstruction.LineItems)
            {
                WriteFileComponent(xmlWriter, fileComponent, ref countRec);
            }

            xmlWriter.WriteEndElement();
            xmlWriter.WriteEndDocument();
        }
        private void AddRootNode()
        {
            _catFeedXml  = new XD(new XDeclaration("1.0", "utf-8", null));
            _feedElement = new XE(_gNsAtom + "feed", new object[]
            {
                new XA(XN.Xmlns + "g", _gNsG),
                new XA(XN.Xmlns + "c", _gNsC),
                new XA(XN.Xmlns + "gd", _gNs)
            });
            var titleElement  = new XE(_gNsAtom + "title", "Category Feed XML");
            var nameElement   = new XE(_gNsAtom + "name", "TEST Feed");
            var authorElement = new XE(_gNsAtom + "author", nameElement);
            var idElement     = new XE(_gNsAtom + "id",
                                       string.Format("tag:indigo.ca,{0}:/support/products", DateTime.Now.ToString(DateTime.Now.ToString("yy-MM-dd"))));

            _feedElement.Add(new object[] { titleElement, authorElement, idElement });
        }
Ejemplo n.º 3
0
        private static XE GetDeletedElement(DeletedProductInfo deletedProductInfo)
        {
            var entry = new XE("product");

            var name = new XE("name", deletedProductInfo.Name);

            entry.Add(name);

            var keywords = new XE("keywords", deletedProductInfo.Keywords);

            entry.Add(keywords);

            var description = new XE("description", deletedProductInfo.Description);

            entry.Add(description);

            var gaId = new XE("sku", deletedProductInfo.Pid);

            entry.Add(gaId);

            var buyUrl = new XE("buyurl", deletedProductInfo.BuyUrl);

            entry.Add(buyUrl);

            var available = new XE("available", deletedProductInfo.IsAvailable);

            entry.Add(available);

            var price = new XE("price", deletedProductInfo.Price);

            entry.Add(price);

            var merchandiseType = new XE("merchandisetype", ZeroCommissionListName);

            entry.Add(merchandiseType);

            return(entry);
        }
        private void AddNodeToFeed(string parentId, XContainer node)
        {
            //Get node values
            var idAttribute = node.XPathSelectElement("./DVAL/DVAL_ID").Attribute("ID");

            if (idAttribute == null)
            {
                return;
            }
            var id          = idAttribute.Value;
            var displayName = node.XPathSelectElement("./DVAL/SYN[@DISPLAY='TRUE']").Value;

            foreach (var synonym in node.XPathSelectElements("./DVAL/SYN[@DISPLAY='FALSE'][@CLASSIFY='TRUE']"))
            {
                if (synonym.Value == id)
                {
                    continue;
                }
                if (_synonymsDict.Keys.Contains(synonym.Value))
                {
                    _synonymsDict[synonym.Value] = new Category(displayName, id);
                }
                else
                {
                    _synonymsDict.Add(synonym.Value, new Category(displayName, id));
                }
            }

            //Create node
            var current      = new XE(_gNsAtom + DefaultNodeName);
            var idElement    = new XE(_gNsAtom + "id", id);
            var titleElement = new XE(_gNsAtom + "title", displayName);
            //link?? - is it mandatory?
            var linkElement = new XE(_gNsAtom + "link");
            var linkAttr    = new XA("href", _indigoLink);

            linkElement.Add(linkAttr);
            var parentsElement = new XE(_gNsG + "parents", parentId);
            var groupElement   = new XE(_gNsG + "group", _taxonomyVersionName);

            current.Add(new object[] { idElement, titleElement, linkElement, parentsElement, groupElement });

            //Add node to the feed
            _feedElement.Add(current);

            // Add the node info to the breadcrumbs list
            if (_categoryBreadcrumbs.ContainsKey(parentId))
            {
                _categoryBreadcrumbs.Add(id, _categoryBreadcrumbs[parentId] + " > " + displayName);
            }
            else
            {
                _categoryBreadcrumbs.Add(id, "{TOP_LEVEL}");
            }

            //Add childrens as well
            foreach (var child in node.Elements("DIMENSION_NODE"))
            {
                AddNodeToFeed(id, child);
            }
        }
Ejemplo n.º 5
0
        private XE EntryAttribute(string catalog, IDataReader reader, StringDictionary dict
                                  , string gId
                                  , string sanitizedTitle
                                  , string linkCatalog
                                  , string linkSku
                                  , string gPrice
                                  , string gAdjustedPrice
                                  , string gAvailability
                                  , string gBrandName,
                                  string publisherName,
                                  XE contributors,
                                  string breadcrumb, bool isZeroCommissionProduct, string merchandiseType, IRuleEvaluationResult promotionalTextEvaluationResult, string description)
        {
            //entry
            var entry = new XE("product");

            sanitizedTitle = GetCjString(sanitizedTitle, MaxTitleLength);
            var name = new XE("name", sanitizedTitle);

            entry.Add(name);

            var keywordsValue = string.Empty;

            // First get the major contributor text
            if (!string.IsNullOrWhiteSpace(gBrandName))
            {
                keywordsValue = gBrandName;
            }
            else if (contributors != null)
            {
                keywordsValue = contributors.Value;
            }

            // Now add the breadcrumb
            if (!string.IsNullOrWhiteSpace(keywordsValue))
            {
                keywordsValue += ", ";
            }

            keywordsValue += string.Join(", ", breadcrumb.Split(new[] { BreadcrumbTrailSplitter }, StringSplitOptions.RemoveEmptyEntries)) + ", ";
            keywordsValue += sanitizedTitle;
            var keywords = new XE("keywords", GetCjString(keywordsValue, MaxKeywordLength));

            entry.Add(keywords);

            var descriptionValue = GetCjString(FeedUtils.RemoveHtmlTags(description), MaxDescriptionLength);

            if (string.IsNullOrWhiteSpace(descriptionValue))
            {
                descriptionValue = sanitizedTitle;
            }
            var descriptionXe = new XE("description", descriptionValue);

            entry.Add(descriptionXe);

            var gaId = new XE("sku", gId);

            entry.Add(gaId);

            var aLink = FeedEntryLink(GetFeedEntryLinkValue(reader, linkCatalog, linkSku));

            entry.Add(aLink);

            var available = new XE("available", "Yes");

            entry.Add(available);

            var aImgLink = EntryImageLink(reader, linkSku);

            entry.Add(aImgLink);

            Decimal price;
            bool    isSpecial = false;

            if (DisplaySalePriceInfo)
            {
                if (Decimal.TryParse(gPrice, out price))
                {
                    var gaPrice = new XE("price", price.ToString("F", CultureInfo.InvariantCulture));
                    entry.Add(gaPrice);

                    Decimal salePrice;
                    if (!string.IsNullOrWhiteSpace(gAdjustedPrice) && Decimal.TryParse(gAdjustedPrice, out salePrice) && salePrice != price)
                    {
                        isSpecial = true;
                        var gaSalePrice = new XE("saleprice", salePrice.ToString("F", CultureInfo.InvariantCulture));
                        entry.Add(gaSalePrice);
                    }
                }
            }
            else
            {
                price = Decimal.Parse(gAdjustedPrice);
                var gaPrice = new XE("price", price.ToString("F", CultureInfo.InvariantCulture));
                entry.Add(gaPrice);
            }

            entry.Add(new XE("currency", "CAD"));

            // CJ expects the optional xml nodes in a certain order
            var isBook = catalog.Equals("books", StringComparison.OrdinalIgnoreCase);

            if (!isBook && (linkSku.Length == 12 || linkSku.Length == 13))
            {
                entry.Add(new XE("upc", linkSku));
            }

            if (promotionalTextEvaluationResult.HasMatch)
            {
                if (!promotionalTextEvaluationResult.IsDefaultMatch)
                {
                    isSpecial = true;
                }

                var promoTextValue = GetCjString(promotionalTextEvaluationResult.MatchingRulePayLoads.First(), MaxPromotionalTextLength);
                entry.Add(new XE("promotionaltext", promoTextValue));
            }

            var advertiserCategoryText = breadcrumb.Replace(BreadcrumbTrailSplitter, ">");

            entry.Add(new XE("advertisercategory", GetCjString(advertiserCategoryText, MaxAdvertiserCategoryLength)));

            if (!string.IsNullOrWhiteSpace(gBrandName))
            {
                var manufacturer = GetCjString(gBrandName, MaxManufacturerLength);
                entry.Add(new XE("manufacturer", manufacturer));
                entry.Add(new XE("manufacturerid", linkSku));
            }

            if (isBook)
            {
                entry.Add(new XE("isbn", linkSku));

                if (contributors != null)
                {
                    entry.Add(new XE("author", GetCjString(contributors.Value, MaxManufacturerLength)));
                }

                if (!string.IsNullOrWhiteSpace(publisherName))
                {
                    entry.Add(new XE("publisher", GetCjString(publisherName, MaxManufacturerLength)));
                }
            }
            else
            {
                if (contributors != null)
                {
                    entry.Add(new XE("artist", GetCjString(contributors.Value, MaxManufacturerLength)));
                }
            }

            entry.Add(new XE("title", sanitizedTitle));

            if (!isBook)
            {
                if (!string.IsNullOrWhiteSpace(publisherName))
                {
                    entry.Add(new XE("label", GetCjString(publisherName, MaxManufacturerLength)));
                }

                if (dict.ContainsKey("format"))
                {
                    var format = reader[dict["format"]].ToString();
                    if (!string.IsNullOrWhiteSpace(format))
                    {
                        entry.Add(new XE("format", format));
                    }
                }
            }

            entry.Add(new XE("special", (isSpecial) ? "Yes" : "No"));

            if (catalog.Equals("generalmerchandise", StringComparison.OrdinalIgnoreCase))
            {
                entry.Add(new XE("gift", "Yes"));
            }

            entry.Add(new XE("instock", (string.IsNullOrWhiteSpace(gAvailability)) ? "No" : "Yes"));
            entry.Add(new XE("condition", "New"));

            if (!string.IsNullOrWhiteSpace(DefaultShippingCost))
            {
                entry.Add(new XE("standardshippingcost", DefaultShippingCost));
            }

            if (string.IsNullOrWhiteSpace(merchandiseType))
            {
                entry.Add(new XE("merchandisetype", ZeroCommissionListName));
            }
            else
            {
                if (isZeroCommissionProduct)
                {
                    entry.Add(new XE("merchandisetype", ZeroCommissionListName));
                    // If the merchandise type has a different value and it's not equal to zero commission list
                    // and if we're putting the item on the zero commission list, add it to the list of items to be
                    // updated inside the
                    if (!merchandiseType.Equals(ZeroCommissionListName, StringComparison.OrdinalIgnoreCase))
                    {
                        _updatedMerchandiseTypeProductPids.Add(decimal.Parse(gId));
                    }

                    Log.DebugFormat("Product {0} was put in zero commission list.", gId);
                }
                else
                {
                    entry.Add(new XE("merchandisetype", merchandiseType));
                }
            }

            return(entry);
        }