Esempio n. 1
0
        public override ShippingResult GetShippingResult(string ShipMethodName,
                                                         Order ThisOrder, AnonymousAddress Address)
        {
            ShippingResult RetVal = new ShippingResult();

            if (ShipMethodName == "UPS Ground" && Address.Region != "HI" &&
                Address.Region != "AL")
            {
                RetVal.Shippable    = true;
                RetVal.ShippingRate = 20;
            }
            else if (ShipMethodName == "SuperShip")
            {
                RetVal.Shippable    = true;
                RetVal.ShippingRate = 0;
            }
            else
            {
                //next we will look at the merchant-private-item-data
                //if the supplier-id is "ABC Candy Company" then you will get free shipping.
                //do not assume the nodes will be in the same order, we will walk the node
                //list looking for a node with the name of "supplier-id"

                //you can just as easily import all the nodes into an XmlDocument and perform
                //XPath statements.

                //You can also create a string dictionary by performing a foreach statement
                //on the nodes and using the node name as the key and the innerText as the
                //value.

                //We are just showing one of many ways to work with an array of XmlNodes.
                //As you can see from the sample code, you may also have children on any
                //of the MerchantPrivateDataNodes.

                string supplierID = "ABC Candy Company".ToUpper();

                foreach (OrderLine Line in ThisOrder)
                {
                    foreach (System.Xml.XmlNode node in Line.MerchantPrivateDataNodes)
                    {
                        if (node.Name == "supplier-id")
                        {
                            if (supplierID == node.InnerText.ToUpper())
                            {
                                RetVal.Shippable    = true;
                                RetVal.ShippingRate = 0;
                                break;
                            }
                        }
                    }
                }
            }
            return(RetVal);
        }
        public byte[] Process(string CallbackXML)
        {
            // Deserialize the callback request.
            AutoGen.MerchantCalculationCallback Callback =
                (AutoGen.MerchantCalculationCallback)
                EncodeHelper.Deserialize
                    (CallbackXML, typeof(AutoGen.MerchantCalculationCallback));
            // Create the callback response.
            AutoGen.MerchantCalculationResults RetVal =
                new AutoGen.MerchantCalculationResults();
            // Create the order.
            Order ThisOrder = new Order(Callback);

            // Are there shipping methods?
            string[] ShippingMethods = new string[1] {
                ""
            };
            if (Callback.calculate.shipping != null &&
                Callback.calculate.shipping.Length > 0)
            {
                ShippingMethods = new string[Callback.calculate.shipping.Length];
                for (int s = 0; s < ShippingMethods.Length; s++)
                {
                    ShippingMethods[s] = Callback.calculate.shipping[s].name;
                }
            }

            string currencyCode = Token.Instance.Store.BaseCurrency.ISOCode;

            RetVal.results =
                new AutoGen.Result
                [Callback.calculate.addresses.Length * ShippingMethods.Length];
            int ResultIndex = 0;

            for (int s = 0; s < ShippingMethods.Length; s++)
            {
                for (int a = 0; a < Callback.calculate.addresses.Length; a++)
                {
                    AutoGen.Result ThisResult = new AutoGen.Result();
                    ThisResult.addressid = Callback.calculate.addresses[a].id;
                    AnonymousAddress ThisAddress =
                        new AnonymousAddress(Callback.calculate.addresses[a]);
                    // Check shipping, if requested.
                    if (!string.IsNullOrEmpty(ShippingMethods[s]))
                    {
                        ThisResult.shippingname = ShippingMethods[s];
                        ShippingResult SResult = _Rules.GetShippingResult(ShippingMethods[s], ThisOrder, ThisAddress);
                        ThisResult.shippableSpecified    = true;
                        ThisResult.shippable             = SResult.Shippable;
                        ThisResult.shippingrate          = new AutoGen.ResultShippingrate();
                        ThisResult.shippingrate.currency = currencyCode;
                        ThisResult.shippingrate.Value    = (Decimal)SResult.ShippingRate;
                    }
                    // Check tax, if requested.
                    if (Callback.calculate.tax)
                    {
                        ThisResult.totaltax          = new AutoGen.ResultTotaltax();
                        ThisResult.totaltax.currency = currencyCode;
                        ThisResult.totaltax.Value    =
                            (Decimal)_Rules.GetTaxResult
                                (ThisOrder, ThisAddress,
                                (ThisResult.shippingrate != null?
                                 ThisResult.shippingrate.Value: 0));
                    }
                    // Check merchant codes.
                    if (Callback.calculate.merchantcodestrings != null)
                    {
                        ThisResult.merchantcoderesults =
                            new AutoGen.ResultMerchantcoderesults();
                        ThisResult.merchantcoderesults.Items =
                            new object[Callback.calculate.merchantcodestrings.Length];
                        ArrayList UsedMerchantCodes = new ArrayList();
                        for (int c = 0; c < Callback.calculate.merchantcodestrings.Length;
                             c++)
                        {
                            MerchantCodeResult MCR;
                            string             CurrentMerchantCode =
                                Callback.calculate.merchantcodestrings[c].code;
                            if (UsedMerchantCodes.Contains(CurrentMerchantCode.ToUpper()))
                            {
                                AutoGen.CouponResult CouponResult = new AutoGen.CouponResult();
                                CouponResult.calculatedamount          = new AutoGen.CouponResultCalculatedamount();
                                CouponResult.calculatedamount.currency = currencyCode;
                                CouponResult.calculatedamount.Value    = 0;
                                CouponResult.code    = CurrentMerchantCode;
                                CouponResult.message = "Code already used.";
                                CouponResult.valid   = false;
                                ThisResult.merchantcoderesults.Items[c] = CouponResult;
                            }
                            else
                            {
                                MCR =
                                    _Rules.GetMerchantCodeResult
                                        (ThisOrder, ThisAddress, CurrentMerchantCode);
                                if (MCR.Type == MerchantCodeType.GiftCertificate)
                                {
                                    AutoGen.GiftCertificateResult GCResult =
                                        new AutoGen.GiftCertificateResult();
                                    GCResult.calculatedamount          = new AutoGen.GiftCertificateResultCalculatedamount();
                                    GCResult.calculatedamount.currency = currencyCode;
                                    GCResult.calculatedamount.Value    = (Decimal)MCR.Amount;
                                    GCResult.code    = CurrentMerchantCode;
                                    GCResult.message = MCR.Message;
                                    GCResult.valid   = MCR.Valid;
                                    ThisResult.merchantcoderesults.Items[c] = GCResult;
                                    UsedMerchantCodes.Add(CurrentMerchantCode.ToUpper());
                                }
                                else
                                {
                                    AutoGen.CouponResult CouponResult =
                                        new AutoGen.CouponResult();
                                    CouponResult.calculatedamount          = new AutoGen.CouponResultCalculatedamount();
                                    CouponResult.calculatedamount.currency = currencyCode;
                                    CouponResult.calculatedamount.Value    = (Decimal)MCR.Amount;
                                    CouponResult.code    = CurrentMerchantCode;
                                    CouponResult.message = MCR.Message;
                                    CouponResult.valid   = MCR.Valid;
                                    ThisResult.merchantcoderesults.Items[c] = CouponResult;
                                    UsedMerchantCodes.Add(CurrentMerchantCode.ToUpper());
                                }
                            }
                        }
                    }
                    RetVal.results[ResultIndex] = ThisResult;
                    ResultIndex++;
                }
            }

            return(EncodeHelper.Serialize(RetVal));
        }