Exemple #1
0
        /// <summary>
        /// Visitors the sign up for stock notification.
        /// </summary>
        /// <param name="storefront">The storefront.</param>
        /// <param name="model">The model.</param>
        /// <param name="location">The location.</param>
        /// <returns>
        /// The manager response which returns success flag in the Result.
        /// </returns>
        public virtual ManagerResponse <VisitorSignUpForStockNotificationResult, bool> VisitorSignupForStockNotification([NotNull] CommerceStorefront storefront, SignUpForNotificationInputModel model, string location)
        {
            Assert.ArgumentNotNull(storefront, "storefront");
            Assert.ArgumentNotNull(model, "model");
            Assert.ArgumentNotNullOrEmpty(model.ProductId, "model.ProductId");
            Assert.ArgumentNotNullOrEmpty(model.Email, "model.Email");

            var visitorId = this.ContactFactory.GetContact();
            var builder   = new CommerceInventoryProductBuilder();
            InventoryProduct inventoryProduct = builder.CreateInventoryProduct(model.ProductId);

            if (string.IsNullOrEmpty(model.VariantId))
            {
                ((CommerceInventoryProduct)inventoryProduct).VariantId = model.VariantId;
            }

            DateTime interestDate;
            var      isDate  = DateTime.TryParse(model.InterestDate, out interestDate);
            var      request = new VisitorSignUpForStockNotificationRequest(storefront.ShopName, visitorId, model.Email, inventoryProduct)
            {
                Location = location
            };

            if (isDate)
            {
                request.InterestDate = interestDate;
            }

            var result = this.InventoryServiceProvider.VisitorSignUpForStockNotification(request);

            Helpers.LogSystemMessages(result.SystemMessages, result);
            return(new ManagerResponse <VisitorSignUpForStockNotificationResult, bool>(result, result.Success));
        }
        public ManagerResponse <VisitorSignUpForStockNotificationResult, bool> VisitorSignupForStockNotification(SignUpForNotificationInputModel model, string location)
        {
            Assert.ArgumentNotNull(model, nameof(model));
            Assert.ArgumentNotNullOrEmpty(model.ProductId, nameof(model.ProductId));
            Assert.ArgumentNotNullOrEmpty(model.Email, nameof(model.Email));
            if (StorefrontContext.Current == null)
            {
                throw new InvalidOperationException("Cannot be called without a valid storefront context.");
            }

            var visitorId        = ContactFactory.GetContact();
            var builder          = new CommerceInventoryProductBuilder();
            var inventoryProduct = (CommerceInventoryProduct)builder.CreateInventoryProduct(model.ProductId);

            if (string.IsNullOrEmpty(model.VariantId))
            {
                inventoryProduct.VariantId = model.VariantId;
            }

            if (string.IsNullOrEmpty(inventoryProduct.CatalogName))
            {
                inventoryProduct.CatalogName = model.CatalogName;
            }

            DateTime interestDate;
            var      isDate  = DateTime.TryParse(model.InterestDate, out interestDate);
            var      request = new VisitorSignUpForStockNotificationRequest(StorefrontContext.Current.ShopName, visitorId, model.Email, inventoryProduct)
            {
                Location = location
            };

            if (isDate)
            {
                request.InterestDate = interestDate;
            }

            var result = InventoryServiceProvider.VisitorSignUpForStockNotification(request);

            result.WriteToSitecoreLog();
            return(new ManagerResponse <VisitorSignUpForStockNotificationResult, bool>(result, result.Success));
        }
        /// <summary>
        /// Visitors the sign up for stock notification.
        /// </summary>
        /// <param name="storefront">The storefront.</param>
        /// <param name="model">The model.</param>
        /// <param name="location">The location.</param>
        /// <returns>
        /// The manager response which returns success flag in the Result.
        /// </returns>
        public virtual ManagerResponse<VisitorSignUpForStockNotificationResult, bool> VisitorSignupForStockNotification([NotNull] CommerceStorefront storefront, SignUpForNotificationInputModel model, string location)
        {
            Assert.ArgumentNotNull(storefront, "storefront");
            Assert.ArgumentNotNull(model, "model");
            Assert.ArgumentNotNullOrEmpty(model.ProductId, "model.ProductId");
            Assert.ArgumentNotNullOrEmpty(model.Email, "model.Email");

            var visitorId = this.ContactFactory.GetContact();
            var builder = new CommerceInventoryProductBuilder();
            CommerceInventoryProduct inventoryProduct = (CommerceInventoryProduct)builder.CreateInventoryProduct(model.ProductId);
            if (string.IsNullOrEmpty(model.VariantId))
            {
                (inventoryProduct).VariantId = model.VariantId;
            }

            if (string.IsNullOrEmpty(inventoryProduct.CatalogName))
            {
                (inventoryProduct).CatalogName = model.CatalogName;
            }

            DateTime interestDate;
            var isDate = DateTime.TryParse(model.InterestDate, out interestDate);
            var request = new VisitorSignUpForStockNotificationRequest(storefront.ShopName, visitorId, model.Email, inventoryProduct) { Location = location };
            if (isDate)
            {
                request.InterestDate = interestDate;
            }

            var result = this.InventoryServiceProvider.VisitorSignUpForStockNotification(request);

            Helpers.LogSystemMessages(result.SystemMessages, result);
            return new ManagerResponse<VisitorSignUpForStockNotificationResult, bool>(result, result.Success);
        }