/// <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));
        }
Ejemplo n.º 2
0
        public override BaseJsonResult GetProductStockInformation(string productId, StringPropertyCollection propertyBag = null)
        {
            StockInfoListJsonResult model = this.ModelProvider.GetModel <StockInfoListJsonResult>();

            if (string.IsNullOrWhiteSpace(productId))
            {
                return(model);
            }
            try
            {
                CommerceStorefront currentStorefront = this.StorefrontContext.CurrentStorefront;
                string             catalog           = currentStorefront.Catalog;
                Item product = this.SearchManager.GetProduct(productId, catalog);
                Assert.IsNotNull(product, string.Format(CultureInfo.InvariantCulture, "Unable to locate the product with id: {0}", productId));
                bool includeBundledItemsInventory = this.ItemTypeProvider.IsBundle(product);
                List <CommerceInventoryProduct> inventoryProductList1 = new List <CommerceInventoryProduct>();
                if (!includeBundledItemsInventory && product.HasChildren)
                {
                    var childList = product.Children.Where(child =>
                    {
                        var variantPersonalizationId = child["PersonalizationId"];
                        var liveDate   = child["LiveDate"];
                        var expiryDate = child["ExpiryDate"];

                        if (this.PersonalizationId.Equals(child["PersonalizationId"], System.StringComparison.OrdinalIgnoreCase))
                        {
                            if (!string.IsNullOrEmpty(liveDate))
                            {
                                var parseSuccess = DateTimeOffset.TryParseExact(liveDate, "yyyyMMddTHHmmss", null, DateTimeStyles.None, out var variantLiveDate);
                                if (parseSuccess && variantLiveDate > DateTimeOffset.Now)
                                {
                                    return(false);
                                }
                            }

                            if (!string.IsNullOrEmpty(expiryDate))
                            {
                                var parseSuccess = DateTimeOffset.TryParseExact(expiryDate, "yyyyMMddTHHmmss", null, DateTimeStyles.None, out var variantExpiryDate);
                                if (parseSuccess && variantExpiryDate <= DateTimeOffset.Now)
                                {
                                    return(false);
                                }
                            }

                            return(true);
                        }

                        return(false);
                    });

                    if (!childList.Any())
                    {
                        childList = product.Children.Where(child => string.IsNullOrEmpty(child["PersonalizationId"]));
                    }
                    foreach (Item child in childList)
                    {
                        List <CommerceInventoryProduct> inventoryProductList2 = inventoryProductList1;
                        CommerceInventoryProduct        inventoryProduct      = new CommerceInventoryProduct();
                        inventoryProduct.ProductId   = productId;
                        inventoryProduct.CatalogName = catalog;
                        inventoryProduct.VariantId   = child.Name;
                        inventoryProductList2.Add(inventoryProduct);
                    }
                }
                else
                {
                    List <CommerceInventoryProduct> inventoryProductList2 = inventoryProductList1;
                    CommerceInventoryProduct        inventoryProduct      = new CommerceInventoryProduct();
                    inventoryProduct.ProductId   = productId;
                    inventoryProduct.CatalogName = catalog;
                    inventoryProductList2.Add(inventoryProduct);
                }
                ManagerResponse <GetStockInformationResult, IEnumerable <StockInformation> > stockInformation = this.InventoryManager.GetStockInformation(currentStorefront, inventoryProductList1, StockDetailsLevel.All, includeBundledItemsInventory, propertyBag);
                if (!stockInformation.ServiceProviderResult.Success)
                {
                    model.SetErrors(stockInformation.ServiceProviderResult);
                }
                else
                {
                    model.Initialize(stockInformation.Result);
                }
            }
            catch (Exception ex)
            {
                model.SetErrors("GetCurrentProductStockInfo", ex);
            }
            return(model);
        }