예제 #1
0
        private LSDecimal Calculate_PointOfDelivery(Basket basket, Dictionary <string, string> existingTransactions)
        {
            WebTrace.Write("CertiTAX: Begin Calculate POD");
            LSDecimal totalTax = 0;

            foreach (BasketShipment shipment in basket.Shipments)
            {
                CertiTAX.Order taxOrder = new CertiTAX.Order();
                //SET THE TAXORDER ADDRESS
                BuildTaxOrderAddress(taxOrder, shipment.Address);
                //BUILD THE TAXORDER OBJECT
                BuildTaxOrder(taxOrder, basket, shipment.BasketShipmentId, existingTransactions);
                taxOrder.Nexus = "POD";
                //EXECUTE THE TRANSACTION
                CertiTAX.TaxTransaction taxTransaction = null;
                try
                {
                    taxTransaction = (new CertiTAX.CertiCalc()).Calculate(taxOrder);
                }
                catch (Exception ex)
                {
                    WebTrace.Write("CertiTax could not calculate tax.  The error was: " + ex.Message);
                    if (!this.IgnoreFailedConfirm)
                    {
                        throw;
                    }
                }
                //PARSE THE RESULTS
                totalTax += ParseTaxTransaction(taxTransaction, basket, shipment.BasketShipmentId);
            }
            WebTrace.Write("CertiTAX: End Calculate POD");
            //RETURN THE TOTAL TAX
            return(totalTax);
        }
예제 #2
0
 /// <summary>
 /// Validates a credit card number using the standard Luhn/mod10
 /// validation algorithm.
 /// </summary>
 /// <param name="routingNumber">Card number, without punctuation or spaces.</param>
 /// <returns>True if card number appears valid, false if not
 /// </returns>
 public bool ValidateRoutingNumber(string routingNumber)
 {
     try
     {
         if (String.IsNullOrEmpty(routingNumber))
         {
             return(false);
         }
         if (routingNumber.Length != 9)
         {
             return(false);
         }
         int digit, sum = 0;
         for (int i = 0; i < routingNumber.Length; i += 3)
         {
             digit = AlwaysConvert.ToInt(routingNumber.Substring(i, 1));
             sum  += digit * 3;
             digit = AlwaysConvert.ToInt(routingNumber.Substring(i + 1, 1));
             sum  += digit * 7;
             digit = AlwaysConvert.ToInt(routingNumber.Substring(i + 2, 1));
             sum  += digit;
         }
         WebTrace.Write("sum: " + sum);
         return((sum > 0) && (sum % 10 == 0));
     }
     catch
     {
         return(false);
     }
 }
예제 #3
0
        private LSDecimal Calculate_PointOfSale(Basket basket, Dictionary <string, string> existingTransactions)
        {
            WebTrace.Write("CertiTAX: Begin Calculate POS");
            CertiTAX.Order taxOrder = new CertiTAX.Order();
            //SET THE TAXORDER ADDRESS
            BuildTaxOrderAddress(taxOrder, StoreDataSource.Load().DefaultWarehouse);
            //BUILD THE TAXORDER OBJECT
            BuildTaxOrder(taxOrder, basket, 0, existingTransactions);
            taxOrder.Nexus = "POS";
            //EXECUTE THE TRANSACTION
            CertiTAX.TaxTransaction taxTransaction = null;
            try
            {
                taxTransaction = (new CertiTAX.CertiCalc()).Calculate(taxOrder);
            }
            catch (Exception ex)
            {
                WebTrace.Write("CertiTax could not calculate tax.  The error was: " + ex.Message);
                if (!this.IgnoreFailedConfirm)
                {
                    throw;
                }
            }
            //PARSE THE RESULTS
            LSDecimal totalTax = ParseTaxTransaction(taxTransaction, basket, 0);

            WebTrace.Write("CertiTAX: End Calculate POS");
            return(totalTax);
        }
예제 #4
0
 void Page_InitComplete(object sender, EventArgs e)
 {
     WebTrace.Write("InitComplete, Ensuring Child Controls for ScriptletPart");
     // MAKE SURE ALL CONTROLS ARE CREATED AFTER PERSONALIZATION IS APPLIED
     // BUT BEFORE THE PAGE LOAD EVENT OCCURS
     this.EnsureChildControls();
 }
예제 #5
0
        private void CombineItems()
        {
            WebTrace.Write("Begin Combine");
            WishlistItem item;

            for (int i = this.Count - 1; i > 0; i--)
            {
                item = this[i];
                if (item.Desired > 0)
                {
                    WebTrace.Write("i: " + i.ToString() + ", WishlistItemId: " + item.WishlistItemId.ToString() + ", ProductId: " + item.ProductId);
                    WishlistItem match = this.Find(new System.Predicate <WishlistItem>(item.CanCombine));
                    WebTrace.Write("(match!=null): " + (match != null));
                    if ((match != null) && (item.WishlistItemId != match.WishlistItemId))
                    {
                        WebTrace.Write("match.WishlistItemId: " + match.WishlistItemId.ToString());
                        match.Desired += item.Desired;
                        this.DeleteAt(i);
                    }
                }
                else
                {
                    this.DeleteAt(i);
                }
            }
        }
 protected override bool EvaluateIsValid()
 {
     if (IsValidCardType(_cardNumber.Text))
     {
         WebTrace.Write("Valid Card Type Detected.  Accepted Card Type: " + AcceptedCardType.ToString());
         return(ValidateCardNumber(_cardNumber.Text));
     }
     return(false);
 }
예제 #7
0
 /// <summary>
 /// Combines any shipments in the collection that have equivalent data.
 /// </summary>
 /// <param name="save">Flag indicating whether or not to persist changes.</param>
 /// <remarks>When shipments are combined any items they contain are merged into a single shipment.</remarks>
 public void Combine(bool save)
 {
     WebTrace.Write("Combine Basket Shipments");
     for (int i = this.Count - 1; i >= 0; i--)
     {
         BasketShipment    shipment      = this[i];
         List <BasketItem> shipmentItems = shipment.Items.FindAll(delegate(BasketItem item) { return(item.BasketShipmentId == shipment.BasketShipmentId); });
         if (shipmentItems.Count > 0)
         {
             WebTrace.Write("i: " + i.ToString() + ", BasketShipmentId: " + shipment.BasketShipmentId.ToString());
             BasketShipment match = this.Find(new System.Predicate <BasketShipment>(shipment.CanCombine));
             if ((match != null) && (match.BasketShipmentId != shipment.BasketShipmentId))
             {
                 WebTrace.Write("match.BasketShipmentId: " + match.BasketShipmentId.ToString());
                 //NEED TO MOVE ITEMS FROM THIS SHIPMENT TO THE MATCHED SHIPMENT
                 foreach (BasketItem item in shipmentItems)
                 {
                     item.BasketShipmentId = match.BasketShipmentId;
                     if (save)
                     {
                         item.Save();
                     }
                 }
                 if (save)
                 {
                     this.DeleteAt(i);
                 }
                 else
                 {
                     removedItems.Add(this[i]);
                     this.RemoveAt(i);
                 }
             }
         }
         else
         {
             if (save)
             {
                 this.DeleteAt(i);
             }
             else
             {
                 removedItems.Add(this[i]);
                 this.RemoveAt(i);
             }
         }
     }
     this.Save();
 }
예제 #8
0
        private void CreateTaxLineItem(Basket basket, int shipmentId, string authorityName, string certiTaxTransactionId, LSDecimal amount)
        {
            BasketItem taxLineItem = new BasketItem();

            taxLineItem.BasketId         = basket.BasketId;
            taxLineItem.OrderItemType    = OrderItemType.Tax;
            taxLineItem.BasketShipmentId = shipmentId;
            taxLineItem.Name             = authorityName;
            taxLineItem.Sku      = string.Format("CT:" + certiTaxTransactionId);
            taxLineItem.Price    = amount;
            taxLineItem.Quantity = 1;
            taxLineItem.Save();
            basket.Items.Add(taxLineItem);
            WebTrace.Write("Tax Line Item Added");
        }
예제 #9
0
        public override void Cancel(CommerceBuilder.Orders.Basket basket)
        {
            WebTrace.Write("Cancel Existing Taxes");
            List <string> uniqueTransactionIds = new List <string>();
            Dictionary <string, string> existingTransactions = ClearExistingTaxes(basket);

            CertiTAX.CertiCalc comm = new CertiTAX.CertiCalc();
            foreach (string transactionId in existingTransactions.Values)
            {
                if (uniqueTransactionIds.IndexOf(transactionId) < 0)
                {
                    uniqueTransactionIds.Add(transactionId);
                    comm.Cancel(transactionId, CT_SERIAL_NUMBER, this.ReferredID);
                }
            }
        }
예제 #10
0
 private void BuildTaxOrderItems(CertiTAX.Order taxOrder, Basket basket, int shipmentId)
 {
     if (this.UseLineItems)
     {
         WebTrace.Write("Process Tax Items -- Line Items Mode");
         LSDecimal productTotal = 0;
         List <CertiTAX.OrderLineItem> taxLineItems = new List <CertiTAX.OrderLineItem>();
         foreach (BasketItem item in basket.Items)
         {
             if (item.OrderItemType == OrderItemType.Product)
             {
                 CertiTAX.OrderLineItem taxLineItem = new CertiTAX.OrderLineItem();
                 taxLineItem.ItemId        = item.ProductId.ToString();
                 taxLineItem.StockingUnit  = item.Sku;
                 taxLineItem.Quantity      = item.Quantity;
                 taxLineItem.ExtendedPrice = (Decimal)item.ExtendedPrice;
                 productTotal += item.ExtendedPrice;
                 taxLineItems.Add(taxLineItem);
             }
         }
         taxOrder.LineItems = taxLineItems.ToArray();
         taxOrder.Total     = (Decimal)productTotal;
     }
     else
     {
         WebTrace.Write("Process Tax Items -- Order Total Mode");
         OrderItemType[] productTypes = { OrderItemType.Product, OrderItemType.Coupon, OrderItemType.Discount };
         if (shipmentId == 0)
         {
             //SET TOTAL FOR THE BASKET
             taxOrder.Total = (Decimal)basket.Items.TotalPrice(productTypes);
         }
         else
         {
             //SET TOTAL FOR THE SHIPMENT
             BasketShipment shipment = this.GetShipment(basket, shipmentId);
             if (shipment != null)
             {
                 taxOrder.Total = (Decimal)shipment.GetItems().TotalPrice(productTypes);
             }
             else
             {
                 taxOrder.Total = 0;
             }
         }
     }
 }
예제 #11
0
        private static Dictionary <string, string> ClearExistingTaxes(Basket basket)
        {
            WebTrace.Write("Clear Existing Taxes");
            Dictionary <string, string> existingTransactions = new Dictionary <string, string>();

            for (int i = basket.Items.Count - 1; i >= 0; i--)
            {
                BasketItem item = basket.Items[i];
                if (item.OrderItemType == OrderItemType.Tax)
                {
                    if (!existingTransactions.ContainsKey(item.BasketShipmentId.ToString()) && item.Sku.StartsWith("CT:"))
                    {
                        existingTransactions[item.BasketShipmentId.ToString()] = item.Sku.Substring(3);
                    }
                    basket.Items.DeleteAt(i);
                }
            }
            return(existingTransactions);
        }
예제 #12
0
 protected override void CreateControlHierarchy()
 {
     if (HttpContext.Current != null)
     {
         WebTrace.Write(this.GetType().ToString(), "CreateControlHierarchy, CategoryId " + this.CategoryId);
         WebTrace.Write(this.GetType().ToString(), "CurrentNodeId: " + CurrentNodeId);
         WebTrace.Write(this.GetType().ToString(), "CurrentNodeType: " + CurrentNodeType);
         SiteMapNodeItemType itemType;
         List <CmsPathNode>  cmsPath = CmsPath.GetCmsPath(CategoryId, CurrentNodeId, CurrentNodeType);
         int pathIndex = 0;
         int nodeIndex = 1;
         foreach (CmsPathNode node in cmsPath)
         {
             if (nodeIndex == cmsPath.Count)
             {
                 WebTrace.Write(node.Title + ": Current");
                 itemType = SiteMapNodeItemType.Current;
             }
             else if (nodeIndex == 1)
             {
                 WebTrace.Write(node.Title + ": Root");
                 itemType = SiteMapNodeItemType.Root;
             }
             else
             {
                 WebTrace.Write(node.Title + ": Parent");
                 itemType = SiteMapNodeItemType.Parent;
             }
             if (nodeIndex > 1)
             {
                 this.CreateItemFromCmsPathNode(pathIndex, SiteMapNodeItemType.PathSeparator, null);
                 pathIndex++;
             }
             CreateItemFromCmsPathNode(pathIndex, itemType, node);
             pathIndex++;
             nodeIndex++;
         }
     }
     else
     {
         base.CreateControlHierarchy();
     }
 }
예제 #13
0
        public override void Commit(CommerceBuilder.Orders.Order order)
        {
            WebTrace.Write("Commit Existing Taxes");
            List <string> uniqueTransactionIds = new List <string>();

            CertiTAX.CertiCalc comm = new CertiTAX.CertiCalc();
            foreach (OrderItem item in order.Items)
            {
                if ((item.OrderItemType == OrderItemType.Tax) && (item.Sku.StartsWith("CT:") && (!item.LineMessage.Equals("Committed"))))
                {
                    string transactionId = item.Sku.Substring(3);
                    if (uniqueTransactionIds.IndexOf(transactionId) < 0)
                    {
                        CommerceBuilder.Taxes.Providers.CCH.CertiTAX.TaxTransaction tx = new CommerceBuilder.Taxes.Providers.CCH.CertiTAX.TaxTransaction();
                        uniqueTransactionIds.Add(transactionId);
                        comm.Commit(transactionId, CT_SERIAL_NUMBER, this.ReferredID);
                        item.LineMessage = "Committed";
                    }
                }
            }
        }
예제 #14
0
        private void BuildTaxOrder(CertiTAX.Order taxOrder, Basket basket, int shipmentId, Dictionary <string, string> existingTransactions)
        {
            if (existingTransactions.ContainsKey(shipmentId.ToString()))
            {
                taxOrder.CertiTAXTransactionId = existingTransactions[shipmentId.ToString()];
            }
            LSDecimal shippingCharge = 0;
            LSDecimal handlingCharge = 0;

            GetShipCharges(basket, shipmentId, out shippingCharge, out handlingCharge);
            taxOrder.SerialNumber          = CT_SERIAL_NUMBER;
            taxOrder.ReferredId            = ReferredID;
            taxOrder.CalculateTax          = true;
            taxOrder.ConfirmAddress        = this.ConfirmAddresses;
            taxOrder.DefaultProductCode    = 0;
            taxOrder.HandlingCharge        = (Decimal)handlingCharge;
            taxOrder.ShippingCharge        = (Decimal)shippingCharge;
            taxOrder.Location              = Location;
            taxOrder.MerchantTransactionId = basket.BasketId.ToString();
            WebTrace.Write("Processing Items");
            BuildTaxOrderItems(taxOrder, basket, shipmentId);
        }
예제 #15
0
        private void InitText(string uniqueId)
        {
            HttpContext context = HttpContext.Current;

            if (context != null)
            {
                if (string.IsNullOrEmpty(uniqueId))
                {
                    uniqueId = this.UniqueID;
                }
                WebTrace.Write("Init text, using uniqueid: " + this.UniqueID);
                if (string.IsNullOrEmpty(context.Request.Form[uniqueId]))
                {
                    this.Text = "0";
                }
                else
                {
                    this.Text = context.Request.Form[uniqueId];
                }
                WebTrace.Write("text: " + this.Text);
            }
        }
        /// <summary>
        /// Initializes the provider.
        /// </summary>
        /// <param name="name">The friendly name of the provider.</param>
        /// <param name="config">A collection of the name/value pairs representing the provider-specific attributes specified in the configuration for this provider.</param>
        public override void Initialize(string name, NameValueCollection config)
        {
            WebTrace.Write("Initializing AbleCommerceMembershipProvider");
            if (config == null)
            {
                throw new ArgumentNullException("config");
            }
            if (string.IsNullOrEmpty(name))
            {
                name = "AbleCommerceMembershipProvider";
            }
            config.Remove("name");
            if (string.IsNullOrEmpty(config["description"]))
            {
                config.Remove("description");
                config.Add("description", "A membership provider for the AbleCommerce application.");
            }

            base.Initialize(name, config);

            //SET THE PASSWORD FORMAT
            _PasswordPolicy = new MerchantPasswordPolicy();
        }
        protected override bool ControlPropertiesValid()
        {
            // Should have a text box control to check
            Control ctrl = FindControl(ControlToValidate);

            WebTrace.Write("Found control to validate: " + (null != ctrl));
            if (null != ctrl)
            {
                if (ctrl is System.Web.UI.WebControls.TextBox)                  // ensure its a text box
                {
                    _cardNumber = (System.Web.UI.WebControls.TextBox)ctrl;      // set the member variable
                    WebTrace.Write("Control to validate is textbox: " + (null != _cardNumber));
                    return(null != _cardNumber);                                // check that it's been set ok
                }
                else
                {
                    return(false);
                }
            }
            else
            {
                return(false);
            }
        }
예제 #18
0
 public void Rebuild()
 {
     WebTrace.Write(this.GetType().ToString(), "Rebuild on CategoryId " + this.CategoryId);
     this.Controls.Clear();
     this.CreateControlHierarchy();
 }
예제 #19
0
        protected override void Render(HtmlTextWriter output)
        {
            StringBuilder html = new StringBuilder();

            if (this.RenderOptions)
            {
                if (_Option != null)
                {
                    int productId = 0;
                    if (_Option.ProductOptions.Count > 0)
                    {
                        productId = _Option.ProductOptions[0].ProductId;
                    }
                    OptionChoiceCollection availableChoices = null;
                    if (ForceToLoadAllChoices)
                    {
                        availableChoices = _Option.Choices;
                    }
                    else
                    {
                        availableChoices = OptionChoiceDataSource.GetAvailableChoices(productId, _Option.OptionId, _SelectedChoices);
                    }
                    if (availableChoices.Count > 0)
                    {
                        //ADD REQUIRED STYLING FOR SWATCH
                        //SET THE HEIGHT AND WIDTH
                        html.Append("<style>\n");
                        html.Append("     ." + this.ClientID + " td { padding:0px !important;width:" + _Option.ActiveThumbnailWidth + "px;height:" + _Option.ActiveThumbnailHeight + "px;cursor:pointer; }\n");
                        html.Append("</style>\n");
                        html.Append("<div class=\"" + this.ClientID);
                        if (!string.IsNullOrEmpty(this.CssClass))
                        {
                            html.Append(" " + this.CssClass);
                        }
                        html.Append("\">\n");

                        //OUTPUT THE CURRENT SELECTION
                        html.Append("<span id=\"" + this.ClientID + "Text\">");
                        OptionChoice selOpt = GetSelectedChoice(availableChoices);
                        if (selOpt != null)
                        {
                            html.Append(selOpt.Name);
                        }
                        html.Append("</span>\n");

                        //OUTPUT THE SWATCH PICKER
                        html.Append("     <table cellpadding=\"0\" cellspacing=\"2\" onclick=\"javascript:OptionPickerClick(event, '" + this.ClientID + "');");
                        if (this.AutoPostBack)
                        {
                            PostBackOptions options = new PostBackOptions(this, string.Empty);
                            options.AutoPostBack = true;
                            html.Append(this.Page.ClientScript.GetPostBackEventReference(options, true));
                        }
                        html.Append("\">\n");
                        for (int i = 0; i < availableChoices.Count; i++)
                        {
                            if (i % _Option.ActiveThumbnailColumns == 0)
                            {
                                if (i > 0)
                                {
                                    html.Append("            </tr>\n");
                                }
                                html.Append("            <tr>\n");
                            }
                            OptionChoice choice = availableChoices[i];
                            html.Append("                <td");
                            if (choice.OptionChoiceId == this.SelectedChoiceId)
                            {
                                html.Append(" class=\"selected\"");
                            }
                            html.Append(" title=\"" + HttpUtility.HtmlEncode(choice.Name) + "\"");
                            html.Append(" style=\"background-image:url(" + this.Page.ResolveUrl(choice.ThumbnailUrl) + ");z-index:" + choice.OptionChoiceId.ToString() + "\">&nbsp;</td>\n");
                        }
                        html.Append("            </tr>\n");
                        html.Append("     </table>\n");
                        html.Append("</div>\n");
                    }
                    else
                    {
                        html.Append("(no options available)");
                    }
                    html.Append("<input type=\"hidden\" id=\"" + this.ClientID + "\" name=\"" + this.UniqueID + "\" value=\"" + this.SelectedChoiceId.ToString() + "\">\n");
                }
                else
                {
                    WebTrace.Write(this.UniqueID, "Invalid Option " + this.OptionId.ToString());
                }
            }
            output.Write(html.ToString());
        }
예제 #20
0
        /// <summary>
        /// Retrieves a site map node based on a search criterion.
        /// </summary>
        /// <param name="rawUrl">A URL that identifies the page for which to retrieve a SiteMapNode</param>
        /// <returns>A site map node based on a search criterion</returns>
        public override System.Web.SiteMapNode FindSiteMapNode(string rawUrl)
        {
            //FIRST CHECK WHETHER THIS PAGE IS SPECIFICALLY KEYED IN THE CONFIG FILE
            SiteMapNode baseNode = base.FindSiteMapNode(rawUrl);

            if (baseNode != null)
            {
                return(baseNode);
            }

            //PAGE NOT FOUND, CHECK WHETHER THIS URL MATCHES KNOWN CMS PAGES
            WebTrace.Write(this.GetType().ToString(), "FindSiteMapNode: " + rawUrl + ", Check For CategoryId");
            Match urlMatch = Regex.Match(rawUrl, "(?<baseUrl>.*)\\?.*CategoryId=(?<categoryId>[^&]*)", (RegexOptions.ExplicitCapture | RegexOptions.IgnoreCase));

            if (urlMatch.Success)
            {
                //FIND BASE NODE
                WebTrace.Write(this.GetType().ToString(), "CategoryId Detected, Find Base Node");
                baseNode = base.FindSiteMapNode(urlMatch.Groups[1].Value);
                if (baseNode != null)
                {
                    WebTrace.Write(this.GetType().ToString(), "Base Node Found, Inject Catalog Path");
                    List <SiteMapNode> pathNodes = this.GetSiteMapPathNodes(baseNode);
                    int catalogNodeIndex         = this.GetCatalogNodeIndex(pathNodes);
                    //IF CATALOG NODE IS NOT FOUND, RETURN THE BASE NODE FOUND BY PROVIDER
                    if (catalogNodeIndex < 0)
                    {
                        return(baseNode);
                    }
                    WebTrace.Write(this.GetType().ToString(), "Catalog Node Obtained, Building Dynamic Path");
                    //APPEND CMS PATH TO THE
                    List <SiteMapNode> dynamicNodes      = new List <SiteMapNode>();
                    List <CmsPathNode> activeCatalogPath = CmsPath.GetCmsPath(0, AlwaysConvert.ToInt(urlMatch.Groups[2].Value), CatalogNodeType.Category);
                    //IF THERE ARE IS NO PATH INFORMATION BEYOND THE ROOT NODE, RETURN THE BASE NODE FOUND BY PROVIDER
                    if (activeCatalogPath.Count < 2)
                    {
                        return(baseNode);
                    }
                    for (int i = 1; i < activeCatalogPath.Count; i++)
                    {
                        SiteMapNode newDynamicNode = new SiteMapNode(baseNode.Provider, activeCatalogPath[i].NodeId.ToString(), activeCatalogPath[i].Url, activeCatalogPath[i].Title, activeCatalogPath[i].Description);
                        if (dynamicNodes.Count > 0)
                        {
                            newDynamicNode.ParentNode = dynamicNodes[dynamicNodes.Count - 1];
                        }
                        dynamicNodes.Add(newDynamicNode);
                    }
                    dynamicNodes[0].ParentNode = pathNodes[catalogNodeIndex];
                    if (catalogNodeIndex == pathNodes.Count - 1)
                    {
                        //THERE ARE NO PATH NODES FOLLOWING CATALOG, RETURN LAST DYNAMIC NODE
                        return(dynamicNodes[dynamicNodes.Count - 1]);
                    }
                    else
                    {
                        //THERE WERE PATH NODES FOLLOWING CATALOG, UPDATE PARENT TO LAST DYNAMIC NODE
                        SiteMapNode nextPathNode = pathNodes[catalogNodeIndex + 1];
                        nextPathNode.ReadOnly   = false;
                        nextPathNode.ParentNode = dynamicNodes[dynamicNodes.Count - 1];
                        //THEN RETURN LAST PATH NODE
                        return(pathNodes[pathNodes.Count - 1]);
                    }
                }
            }

            //THIS PATH TO THIS PAGE CANNOT BE DETERMINED
            return(null);
        }
        public override SiteMapNode FindSiteMapNode(string rawUrl)
        {
            //FIRST CHECK WHETHER THIS PAGE IS SPECIFICALLY KEYED IN THE CONFIG FILE
            SiteMapNode baseNode = base.FindSiteMapNode(rawUrl);

            if (baseNode != null)
            {
                if (_EnableHiding)
                {
                    return(FindVisibleNode(baseNode));
                }
                return(baseNode);
            }

            //PAGE NOT FOUND, CHECK WHETHER THIS URL MATCHES KNOWN CMS PAGES
            int categoryId = -1;

            WebTrace.Write(this.GetType().ToString(), "FindSiteMapNode: " + rawUrl + ", Check For CategoryId");
            Match urlMatch = Regex.Match(rawUrl, "(?<baseUrl>.*)\\?(?:.*&)?CategoryId=(?<categoryId>[^&]*)", (RegexOptions.ExplicitCapture | RegexOptions.IgnoreCase));

            if (urlMatch.Success)
            {
                //CATEGORYID PROVIDED IN URL
                categoryId = AlwaysConvert.ToInt(urlMatch.Groups[2].Value);
            }
            else
            {
                WebTrace.Write(this.GetType().ToString(), "FindSiteMapNode: " + rawUrl + ", Check For Catalog Object Id");
                urlMatch = Regex.Match(rawUrl, "(?<baseUrl>.*)\\?(?:.*&)?(?<nodeType>ProductId|WebpageId|LinkId)=(?<catalogId>[^&]*)", (RegexOptions.ExplicitCapture | RegexOptions.IgnoreCase));
                if (urlMatch.Success)
                {
                    string objectType = urlMatch.Groups[2].Value;
                    switch (objectType)
                    {
                    case "ProductId":
                        categoryId = CatalogDataSource.GetCategoryId(AlwaysConvert.ToInt(urlMatch.Groups[3].Value), CatalogNodeType.Product);
                        break;

                    case "WebpageId":
                        categoryId = CatalogDataSource.GetCategoryId(AlwaysConvert.ToInt(urlMatch.Groups[3].Value), CatalogNodeType.Webpage);
                        break;

                    default:
                        categoryId = CatalogDataSource.GetCategoryId(AlwaysConvert.ToInt(urlMatch.Groups[3].Value), CatalogNodeType.Link);
                        break;
                    }
                    WebTrace.Write("Found catalogobjectid, type: " + objectType + ", id: " + categoryId.ToString());
                }
            }

            if (categoryId > -1)
            {
                //FIND BASE NODE
                WebTrace.Write(this.GetType().ToString(), "CategoryId Detected, Find Base Node");
                baseNode = base.FindSiteMapNode(urlMatch.Groups[1].Value);
                if (baseNode != null)
                {
                    WebTrace.Write(this.GetType().ToString(), "Base Node Found, Inject Catalog Path");
                    List <SiteMapNode> pathNodes = this.GetSiteMapPathNodes(baseNode);
                    WebTrace.Write("default pathnodes count: " + pathNodes.Count.ToString());
                    int catalogNodeIndex = this.GetCatalogNodeIndex(pathNodes);
                    //IF CATALOG NODE IS NOT FOUND, RETURN THE BASE NODE FOUND BY PROVIDER
                    if (catalogNodeIndex < 0)
                    {
                        return(baseNode);
                    }
                    WebTrace.Write(this.GetType().ToString(), "Catalog Node Obtained, Building Dynamic Path");
                    //APPEND CMS PATH TO THE
                    List <SiteMapNode> dynamicNodes      = new List <SiteMapNode>();
                    List <CmsPathNode> activeCatalogPath = CmsPath.GetCmsPath(0, categoryId, CatalogNodeType.Category);
                    //IF THERE ARE IS NO PATH INFORMATION BEYOND THE ROOT NODE, RETURN THE BASE NODE FOUND BY PROVIDER
                    if ((activeCatalogPath == null) || (activeCatalogPath.Count < 1))
                    {
                        return(baseNode);
                    }
                    WebTrace.Write("ActivePathCount: " + activeCatalogPath.Count.ToString());
                    for (int i = 0; i < activeCatalogPath.Count; i++)
                    {
                        SiteMapNode newDynamicNode = new SiteMapNode(baseNode.Provider, activeCatalogPath[i].NodeId.ToString(), activeCatalogPath[i].Url, activeCatalogPath[i].Title, activeCatalogPath[i].Description);
                        if (dynamicNodes.Count > 0)
                        {
                            newDynamicNode.ParentNode = dynamicNodes[dynamicNodes.Count - 1];
                        }
                        dynamicNodes.Add(newDynamicNode);
                    }
                    dynamicNodes[0].ParentNode = pathNodes[catalogNodeIndex];
                    if (catalogNodeIndex == pathNodes.Count - 1)
                    {
                        //THERE ARE NO PATH NODES FOLLOWING CATALOG, RETURN LAST DYNAMIC NODE
                        WebTrace.Write("return last dynamic node");
                        return(dynamicNodes[dynamicNodes.Count - 1]);
                    }
                    else
                    {
                        //THERE WERE PATH NODES FOLLOWING CATALOG, UPDATE PARENT TO LAST DYNAMIC NODE
                        WebTrace.Write("append nodes following catalog");
                        //GET NODE THAT SHOULD BE LINKED FROM LAST DYNAMIC PATH NODE
                        //CLONE THE NODE TO PREVENT CACHING, THEN SET PARENT TO DYNAMIC NODE
                        SiteMapNode dynamicNextPathNode = pathNodes[catalogNodeIndex + 1].Clone(false);
                        pathNodes[catalogNodeIndex + 1] = dynamicNextPathNode;
                        dynamicNextPathNode.ReadOnly    = false;
                        dynamicNextPathNode.ParentNode  = dynamicNodes[dynamicNodes.Count - 1];
                        //LOOP THROUGH REMAINING PATH NODES, CLONE THEM AND SET PARENT TO PREVIOUS DYNAMIC NODE
                        for (int i = catalogNodeIndex + 2; i < pathNodes.Count; i++)
                        {
                            dynamicNextPathNode            = pathNodes[i].Clone(false);
                            pathNodes[i]                   = dynamicNextPathNode;
                            dynamicNextPathNode.ReadOnly   = false;
                            dynamicNextPathNode.ParentNode = pathNodes[i - 1];
                        }
                        //NOW RETURN LAST PATH NODE
                        return(pathNodes[pathNodes.Count - 1]);
                    }
                }
            }

            //THIS PATH TO THIS PAGE CANNOT BE DETERMINED
            return(null);
        }
예제 #22
0
        private Dictionary <string, ProviderShipRateQuote> GetAllProviderShipRateQuotes(Warehouse origin, Address destination, BasketItemCollection contents)
        {
            //CHECK CACHE FOR QUOTES FOR THIS SHIPMEN
            string      cacheKey = StringHelper.CalculateMD5Hash(Utility.Misc.GetClassId(this.GetType()) + "_" + origin.WarehouseId.ToString() + "_" + destination.AddressId.ToString() + "_" + contents.GenerateContentHash());
            HttpContext context  = HttpContext.Current;

            if (context != null)
            {
                WebTrace.Write("Checking Cache for " + cacheKey);
                if (context.Items.Contains(cacheKey))
                {
                    return((Dictionary <string, ProviderShipRateQuote>)context.Items[cacheKey]);
                }
            }

            //VERIFY WE HAVE A DESTINATION COUNTRY
            if (string.IsNullOrEmpty(destination.CountryCode))
            {
                return(null);
            }

            //BUILD A LIST OF USPS PACKAGES FROM THE SHIPMENT ITEMS
            PackageList plist = PreparePackages(origin, contents);

            if (plist == null || plist.Count == 0)
            {
                return(null);
            }
            Package[] shipmentPackages = plist.ToArray();

            //BUILD THE REQUEST FOR THIS SHIPMENT
            XmlDocument providerRequest;
            bool        domestic = (destination.CountryCode == "US");

            if (domestic)
            {
                if (string.IsNullOrEmpty(origin.PostalCode) || (origin.PostalCode.Length < 5))
                {
                    throw new ArgumentException("origin.PostalCode is empty or invalid length");
                }
                if (string.IsNullOrEmpty(destination.PostalCode) || (destination.PostalCode.Length < 5))
                {
                    throw new ArgumentException("destination.PostalCode is empty or invalid length");
                }
                providerRequest = BuildProviderRequest(shipmentPackages, origin.PostalCode.Substring(0, 5), destination.PostalCode.Substring(0, 5));
            }
            else
            {
                string countryName = destination.Country.Name;
                if (destination.CountryCode.Equals("GB"))
                {
                    countryName = "Great Britain";
                }
                providerRequest = BuildProviderRequestIntl(shipmentPackages, countryName);
            }
            //SEND THIS REQUEST TO THE PROVIDER
            XmlDocument providerResponse = SendRequestToProvider(providerRequest, domestic ? "RateV3" : "IntlRate");
            //PARSE THE THE RATE QUOTES FROM THE RESPONSE
            Dictionary <string, ProviderShipRateQuote> allServiceQuotes;

            if (domestic)
            {
                allServiceQuotes = ParseProviderRateReponse(providerResponse, shipmentPackages);
            }
            else
            {
                allServiceQuotes = ParseProviderRateReponseIntl(providerResponse, shipmentPackages);
            }
            //CACHE THE RATE QUOTES INTO REQUEST
            if (context != null)
            {
                context.Items[cacheKey] = allServiceQuotes;
            }
            return(allServiceQuotes);
        }