public static void AdjustMerchantCalculatedShipping(Basket basket, MerchantCalculatedShippingAdjustment mcsa)
 {
     if (mcsa != null)
     {
         BasketItem basketItem = new BasketItem();
         basketItem.OrderItemType = OrderItemType.Shipping;
         basketItem.Price         = mcsa.shippingcost.Value;
         basketItem.Quantity      = 1;
         basketItem.BasketId      = basket.BasketId;
         //basketItem.Name = AcHelper.CleanShipMethodName(mcsa.shippingname);
         basketItem.Name = mcsa.shippingname;
         basketItem.Sku  = basketItem.Name; // +"_Google";
         basket.Items.Add(basketItem);
     }
 }
        public static void DoOrderAdjustments(OrderAdjustment orderAdj, Basket basket)
        {
            TraceContext trace    = WebTrace.GetTraceContext();
            string       traceKey = "OrderAdjustmentHelper.DoOrderAdjustments";

            if (orderAdj == null)
            {
                throw new ArgumentNullException("orderAdj", "OrderAdjustment can't be null");
            }

            OrderAdjustmentMerchantcodes oamcs = orderAdj.merchantcodes;

            if (oamcs != null && oamcs.Items != null)
            {
                trace.Write(traceKey, "check merchant codes");
                Object[]                  merchantCodes = oamcs.Items;
                CouponAdjustment          coupAdj;
                GiftCertificateAdjustment giftCertAdj;

                //coupon and giftcertificate adjustment
                foreach (Object obj in merchantCodes)
                {
                    if (obj == null)
                    {
                        continue;
                    }
                    if (obj is CouponAdjustment)
                    {
                        coupAdj = (CouponAdjustment)obj;
                        trace.Write(traceKey, "Apply coupon: " + coupAdj.code + ", " + coupAdj.appliedamount);
                        OrderAdjustmentHelper.AdjustCoupon(basket, coupAdj);
                    }
                    else if (obj is GiftCertificateAdjustment)
                    {
                        giftCertAdj = (GiftCertificateAdjustment)obj;
                        trace.Write(traceKey, "Apply gift cert: " + giftCertAdj.code + " for " + giftCertAdj.appliedamount.Value);
                        OrderAdjustmentHelper.AdjustGiftCertificate(basket, giftCertAdj);
                    }
                }
            }

            OrderAdjustmentShipping oas = orderAdj.shipping;

            if (oas != null && oas.Item != null)
            {
                trace.Write(traceKey, "check shipping adjustments");
                Object shipAdj = oas.Item;
                if (shipAdj is MerchantCalculatedShippingAdjustment)
                {
                    MerchantCalculatedShippingAdjustment mcsa = (MerchantCalculatedShippingAdjustment)shipAdj;
                    OrderAdjustmentHelper.AdjustMerchantCalculatedShipping(basket, mcsa);
                }
                else if (shipAdj is FlatRateShippingAdjustment)
                {
                    FlatRateShippingAdjustment frsa = (FlatRateShippingAdjustment)shipAdj;
                    OrderAdjustmentHelper.AdjustFlatRateShipping(basket, frsa);
                }
                else if (shipAdj is PickupShippingAdjustment)
                {
                    PickupShippingAdjustment pusa = (PickupShippingAdjustment)shipAdj;
                    OrderAdjustmentHelper.AdjustPickupShipping(basket, pusa);
                }
            }

            //tax adjustments
            if (orderAdj.totaltax != null && orderAdj.totaltax.Value > 0)
            {
                trace.Write(traceKey, "process tax adjustments");
                OrderAdjustmentHelper.AdjustTax(basket, orderAdj.totaltax.Value);
            }
        }
    private void BuildShoppingCart(string requestXml, NewOrderNotification notification)
    {
        foreach (Item item in notification.shoppingcart.items)
        {
            XmlNode[] node = item.merchantprivateitemdata.Any;

            Product product = DataAccessContext.ProductRepository.GetOne(
                StoreContext.Culture,
                item.merchantitemid,
                new StoreRetriever().GetCurrentStoreID()
                );

            if (node.Length <= 1)
            {
                StoreContext.ShoppingCart.AddItem(
                    product, item.quantity);
            }
            else
            {
                // Creating option item from google checkout is not details of option type is text.
                OptionItemValueCollection optionCollection = OptionItemValueCollection.Null;
                if (!String.IsNullOrEmpty(node[1].InnerText))
                {
                    optionCollection = new OptionItemValueCollection(
                        StoreContext.Culture, node[1].InnerText, item.merchantitemid);
                }

                StoreContext.ShoppingCart.AddItem(
                    product, item.quantity, optionCollection);
            }
        }

        Log.Debug("SetShippingDetails");
        Vevo.Base.Domain.Address address = new Vevo.Base.Domain.Address(
            notification.buyershippingaddress.contactname,
            "",
            notification.buyerbillingaddress.companyname,
            notification.buyershippingaddress.address1,
            notification.buyershippingaddress.address2,
            notification.buyershippingaddress.city,
            notification.buyershippingaddress.region,
            notification.buyershippingaddress.postalcode,
            notification.buyershippingaddress.countrycode,
            notification.buyerbillingaddress.phone,
            notification.buyerbillingaddress.fax);

        StoreContext.CheckoutDetails.ShippingAddress = new ShippingAddress(address, false);

        Log.Debug("Set Shipping ");
        MerchantCalculatedShippingAdjustment shippingAdjust = (MerchantCalculatedShippingAdjustment)notification.orderadjustment.shipping.Item;

        string         shippingID = DataAccessContext.ShippingOptionRepository.GetIDFromName(shippingAdjust.shippingname);
        ShippingMethod shipping   = ShippingFactory.CreateShipping(shippingID);

        shipping.Name = shippingAdjust.shippingname;
        StoreContext.CheckoutDetails.SetShipping(shipping);
        StoreContext.CheckoutDetails.SetCustomerComments("");

        PaymentOption paymentOption = DataAccessContext.PaymentOptionRepository.GetOne(
            StoreContext.Culture, PaymentOption.GoogleCheckout);

        StoreContext.CheckoutDetails.SetPaymentMethod(
            paymentOption.CreatePaymentMethod());

        Log.Debug("Set Coupon ID");
        StoreContext.CheckoutDetails.SetCouponID(GetCouponCode(notification.orderadjustment.merchantcodes.Items));

        Log.Debug("Set Gift");
        string giftID = GetGiftCertificateCode(notification.orderadjustment.merchantcodes.Items);

        if (giftID != String.Empty)
        {
            StoreContext.CheckoutDetails.SetGiftCertificate(giftID);
        }

        StoreContext.CheckoutDetails.SetGiftRegistryID("0");
        StoreContext.CheckoutDetails.SetShowShippingAddress(true);
    }