public CartContext Apply(PreCheckoutRuleContext preCheckoutRuleContext)
        {
            var persistedCheckout = preCheckoutRuleContext
                                    .PersistedCheckoutContext;

            var customer = preCheckoutRuleContext
                           .Customer;

            // If an offsite payment method has flagged billing or shipping as required, any changes by the customer will be reverted.
            if (persistedCheckout.OffsiteRequiredBillingAddressId.HasValue &&
                customer.PrimaryBillingAddressID != persistedCheckout.OffsiteRequiredBillingAddressId)
            {
                customer.UpdateCustomer(
                    billingAddressId: persistedCheckout.OffsiteRequiredBillingAddressId.Value);
                NoticeProvider.PushNotice(AppLogic.GetString("checkout.offsites.billing.reverted"), NoticeType.Warning);
            }

            if (persistedCheckout.OffsiteRequiredShippingAddressId.HasValue &&
                customer.PrimaryShippingAddressID != persistedCheckout.OffsiteRequiredShippingAddressId)
            {
                customer.UpdateCustomer(
                    shippingAddressId: persistedCheckout.OffsiteRequiredShippingAddressId.Value);
                NoticeProvider.PushNotice(AppLogic.GetString("checkout.offsites.shipping.reverted"), NoticeType.Warning);
            }

            return(new CartContext(
                       cartContext: preCheckoutRuleContext.CartContext,
                       cart: CachedShoppingCartProvider.Get(customer, CartTypeEnum.ShoppingCart, AppLogic.StoreID())));
        }
Exemple #2
0
        public CartContext Apply(PreCheckoutRuleContext preCheckoutRuleContext)
        {
            var customer = preCheckoutRuleContext.Customer;

            var persistedCheckout = preCheckoutRuleContext
                                    .PersistedCheckoutContext;

            if (!AppLogic.ro_OffsitePayMentMethods.Contains(customer.PrimaryBillingAddress.OffsiteSource))
            {
                return(preCheckoutRuleContext.CartContext);
            }

            if (preCheckoutRuleContext.PaymentMethodInfo == null ||
                AppLogic.ro_OffsitePayMentMethods.Contains(preCheckoutRuleContext.PaymentMethodInfo.Name))
            {
                customer.PrimaryBillingAddressID  = persistedCheckout.OffsiteRequiresBillingAddressId ?? 0;
                customer.PrimaryShippingAddressID = persistedCheckout.OffsiteRequiresShippingAddressId ?? 0;
            }
            else if (!AppLogic.ro_OffsitePayMentMethods.Contains(preCheckoutRuleContext.PaymentMethodInfo.Name))
            {
                if (AppLogic.ro_OffsitePayMentMethods.Contains(customer.PrimaryBillingAddress.OffsiteSource))
                {
                    customer.PrimaryBillingAddressID = 0;
                }

                if (AppLogic.ro_OffsitePayMentMethods.Contains(customer.PrimaryShippingAddress.OffsiteSource))
                {
                    customer.PrimaryShippingAddressID = 0;
                }
            }

            return(new CartContext(
                       cartContext: preCheckoutRuleContext.CartContext,
                       cart: new ShoppingCart(customer.SkinID, customer, CartTypeEnum.ShoppingCart, 0, false)));
        }
        public CartContext Apply(PreCheckoutRuleContext preCheckoutRuleContext)
        {
            var customerId = preCheckoutRuleContext
                             .Customer
                             .CustomerID;

            var shippingAddressId = preCheckoutRuleContext.Customer.PrimaryShippingAddressID;

            DB.ExecuteSQL(@"
				update
					dbo.ShoppingCart
				set
					ShippingAddressId = @shippingAddressId
				where
					CustomerId = @CustomerId
					and CartType in (0,1)
					and StoreId = @StoreId
					AND ShippingAddressid <> @shippingAddressId"                    ,

                          new SqlParameter("@StoreId", AppLogic.StoreID()),
                          new SqlParameter("@CustomerId", customerId),
                          new SqlParameter("@ShippingAddressId", shippingAddressId));

            return(new CartContext(
                       cartContext: preCheckoutRuleContext.CartContext,
                       cart: CachedShoppingCartProvider.Get(preCheckoutRuleContext.Customer, CartTypeEnum.ShoppingCart, AppLogic.StoreID())));
        }
        public CartContext Apply(PreCheckoutRuleContext context)
        {
            var shippingAddress = EffectiveShippingAddressProvider.GetEffectiveShippingAddress(context.Customer);

            var availableShippingMethods = CachedShippingMethodCollectionProvider
                                           .Get(context.Customer, shippingAddress, context.CartContext.Cart.CartItems, AppLogic.StoreID());

            // If there are no available shipping methods, the customer hasn't selected one, or the customer selected an invalid one, selectedShipping will be null.
            var selectedShippingMethod = availableShippingMethods
                                         .Where(shippingMethod => shippingMethod.Id == context.PersistedCheckoutContext.SelectedShippingMethodId)
                                         .FirstOrDefault();

            // No matter what shipping method was selected but the customer, if there is only one available shipping method, set the customers selection to it.
            if (availableShippingMethods.Count() == 1)
            {
                selectedShippingMethod = availableShippingMethods.First();
            }

            // Update all cart items to the updated selection. If the selection is null, then it clears the selection from the cart items and the customer has to select a new one.
            ShippingMethodCartItemApplicator.UpdateCartItemsShippingMethod(
                context.Customer,
                context.CartContext.Cart,
                selectedShippingMethod);

            return(new CartContext(
                       cartContext: context.CartContext,
                       cart: CachedShoppingCartProvider.Get(context.Customer, CartTypeEnum.ShoppingCart, AppLogic.StoreID())));
        }
        public CartContext Apply(PreCheckoutRuleContext preCheckoutRuleContext)
        {
            // Age the cart
            var ageCartDays = preCheckoutRuleContext.CheckoutConfiguration.AgeCartDays == 0
                                ? 7
                                : preCheckoutRuleContext.CheckoutConfiguration.AgeCartDays;

            CartActionProvider.RemoveItemsBeyondMaxAge(preCheckoutRuleContext.Customer, preCheckoutRuleContext.CartContext.Cart.CartType, ageCartDays);
            CartActionProvider.ClearDeletedAndUnPublishedProducts(preCheckoutRuleContext.Customer);

            return(new CartContext(
                       cartContext: preCheckoutRuleContext.CartContext,
                       cart: CachedShoppingCartProvider.Get(preCheckoutRuleContext.Customer, CartTypeEnum.ShoppingCart, AppLogic.StoreID())));
        }
        public CartContext Apply(PreCheckoutRuleContext preCheckoutRuleContext)
        {
            var customer = preCheckoutRuleContext
                           .Customer;

            // Ensure the payment method on the billing address matches the selected payment method
            if (customer.PrimaryBillingAddressID != 0 &&
                customer.PrimaryBillingAddress.PaymentMethodLastUsed != customer.RequestedPaymentMethod)
            {
                customer.PrimaryBillingAddress.PaymentMethodLastUsed = customer.RequestedPaymentMethod;
                customer.PrimaryBillingAddress.UpdateDB();
            }

            return(new CartContext(
                       cartContext: preCheckoutRuleContext.CartContext,
                       cart: CachedShoppingCartProvider.Get(customer, CartTypeEnum.ShoppingCart, AppLogic.StoreID())));
        }
        public CartContext Apply(PreCheckoutRuleContext preCheckoutRuleContext)
        {
            InventoryTrimmedReason inventoryTrimmedReason =
                CartActionProvider
                .ValidateCartQuantitiesAgainstInventory(preCheckoutRuleContext.Customer, preCheckoutRuleContext.CartContext.Cart.CartType);

            //Display inventory adjustment notice if necessary
            var cartTrimmedMessage = preCheckoutRuleContext.CartContext.Cart.GetInventoryTrimmedUserMessage(inventoryTrimmedReason);

            if (!string.IsNullOrEmpty(cartTrimmedMessage))
            {
                NoticeProvider.PushNotice(cartTrimmedMessage, NoticeType.Info);
            }

            return(new CartContext(
                       cartContext: preCheckoutRuleContext.CartContext,
                       cart: CachedShoppingCartProvider.Get(preCheckoutRuleContext.Customer, CartTypeEnum.ShoppingCart, AppLogic.StoreID())));
        }