public List <ProductScan> GetProductScans(IVisitorContext visitorContext, string currentCatalogItemId)
        {
            Assert.ArgumentNotNull(visitorContext, "visitorContext");
            var model             = ModelProvider.GetModel <ProductListJsonResult>();
            var curentCatalogItem = !string.IsNullOrEmpty(currentCatalogItemId) ? Context.Database.GetItem(currentCatalogItemId) : null;

            if (string.IsNullOrEmpty(currentCatalogItemId))
            {
                curentCatalogItem = StorefrontContext.CurrentStorefront.CatalogItem;
            }
            if (curentCatalogItem == null)
            {
                return(null);
            }

            CategorySearchInformation searchInformation     = SearchInformation.GetCategorySearchInformation(curentCatalogItem);
            CommerceSearchOptions     commerceSearchOptions = new CommerceSearchOptions(GetDefaultItemsPerPage(null, searchInformation), 0);

            SearchResults        childProducts     = GetChildProducts(commerceSearchOptions, curentCatalogItem);
            List <ProductEntity> productEntityList = AdjustProductPriceAndStockStatus(visitorContext, childProducts, curentCatalogItem);

            productEntityList.Select(p => p.ProductId);

            return(productEntityList.Select(p => new ProductScan {
                ProductId = p.ProductId, ScanFilePath = GetProductArMapFilePath(p.ProductId, StorefrontContext.CurrentStorefront.Context)
            }).ToList());
        }
        /// <summary>
        /// Gets the sample rendering model.
        /// </summary>
        /// <param name="rendering">The rendering.</param>
        /// <param name="propertyBag">The property bag.</param>
        /// <returns>
        /// An initilaized sample rendering model is returned.
        /// </returns>
        public SampleJsonResult GetSample(IVisitorContext visitorContext, StringPropertyCollection propertyBag = null)
        {
            var jsonResult = ModelProvider.GetModel <SampleJsonResult>();

            if (PageMode.IsExperienceEditor)
            {
                try
                {
                    var response = SampleManager.GetSample(visitorContext, StorefrontContext, propertyBag);
                    if (!response.ServiceProviderResult.Success)
                    {
                        jsonResult.SetErrors(response.ServiceProviderResult);
                        return(jsonResult);
                    }

                    var sample = response.Result;
                    if (sample != null)
                    {
                        jsonResult.Initialize(sample);
                    }
                }
                catch (Exception e)
                {
                    Log.Error(e.Message, e, this);
                    jsonResult.SetErrors("GetSample", e);
                    return(jsonResult);
                }
            }

            return(jsonResult);
        }
        /// <summary>
        /// Gets the sample rendering model.
        /// </summary>
        /// <param name="rendering">The rendering.</param>
        /// <param name="propertyBag">The property bag.</param>
        /// <returns>
        /// An initilaized sample rendering model is returned.
        /// </returns>
        public SamplesJsonResult GetSamples(IVisitorContext visitorContext, GetSamplesInputModel inputModel, StringPropertyCollection propertyBag = null)
        {
            Assert.ArgumentNotNull(inputModel, nameof(inputModel));

            var jsonResult = ModelProvider.GetModel <SamplesJsonResult>();

            try
            {
                var response = SampleManager.GetSamples(StorefrontContext.CurrentStorefront, visitorContext, propertyBag);
                if (!response.ServiceProviderResult.Success)
                {
                    jsonResult.SetErrors(response.ServiceProviderResult);
                    return(jsonResult);
                }

                var samples = response.Result;
                if (samples != null)
                {
                    jsonResult.Initialize(samples);
                }
            }
            catch (Exception e)
            {
                Log.Error(e.Message, e, this);
                jsonResult.SetErrors("GetSample", e);
                return(jsonResult);
            }

            return(jsonResult);
        }
        /// <summary>
        /// Gets the delivery data.
        /// </summary>
        /// <param name="visitorContext">The visitor context.</param>
        /// <param name="propertyBag">The property bag.</param>
        /// <returns>
        /// The sample.
        /// </returns>
        public SampleRenderingModel GetSampleRenderingModel(IRendering rendering, StringPropertyCollection propertyBag = null)
        {
            var model = ModelProvider.GetModel <SampleRenderingModel>();

            Init(model);

            model.Initialize(rendering);

            return(model);
        }
Example #5
0
        /// <summary>
        /// Initialises the model.
        /// </summary>
        /// <param name="cart"></param>
        /// <param name="visitorContext"></param>
        public virtual void Initialize(IEnumerable <Sample> samples)
        {
            Assert.ArgumentNotNull(samples, nameof(samples));

            foreach (var sample in samples)
            {
                var sampleJsonResult = ModelProvider.GetModel <SampleJsonResult>();
                sampleJsonResult.Initialize(sample);
            }
        }
Example #6
0
        private void AddModel(IDictionary <uint, CameraData> cameras, IDictionary <string, PlatformData> platforms, IDictionary <string, TreePlatformData> treeCameras,
                              string key, ListPlatformData list, string productName)
        {
            var platform = PlatformProvider.GetPlatform(key, platforms, productName);
            var tree     = PlatformProvider.GetTree(key, treeCameras, productName);
            var modelId  = Convert.ToUInt32(platform.ModelId, 16);
            var camera   = GetOrAddCamera(modelId, key, list, tree, cameras, productName);
            var model    = ModelProvider.GetModel(key, platform.Names, list, tree, productName);

            camera.Models = camera.Models.Concat(new[] { model }).ToArray();
        }
        protected virtual CatalogItemVariantsRenderingModel GetCatalogItemVariantsRenderingModel(
            IVisitorContext visitorContext,
            Item productItem)
        {
            Assert.ArgumentNotNull(visitorContext, nameof(visitorContext));
            //Important: make sure to use the CurrentCatalogItemVariantsRenderingModelKeyName constant here
            if (SiteContext.Items[CurrentCatalogItemVariantsRenderingModelKeyName] != null)
            {
                return((CatalogItemVariantsRenderingModel)SiteContext.Items[CurrentCatalogItemVariantsRenderingModelKeyName]);
            }
            CommerceStorefront   currentStorefront = StorefrontContext.CurrentStorefront;
            List <VariantEntity> variantEntityList = new List <VariantEntity>();

            if (productItem != null && productItem.HasChildren)
            {
                foreach (Item child in productItem.Children)
                {
                    VariantEntity model = ModelProvider.GetModel <VariantEntity>();
                    model.Initialize(child);
                    variantEntityList.Add(model);
                }
            }
            ProductEntity productEntity = ModelProvider.GetModel <ProductEntity>();

            productEntity.Initialize(currentStorefront, productItem, variantEntityList);
            CatalogItemVariantsRenderingModel catalogModel = ModelProvider.GetModel <CatalogItemVariantsRenderingModel>();

            Init(catalogModel);
            if (SiteContext.UrlContainsCategory)
            {
                catalogModel.ParentCategoryId = CatalogUrlManager.ExtractCategoryNameFromCurrentUrl();
                Item category = SearchManager.GetCategory(catalogModel.ParentCategoryId, currentStorefront.Catalog);
                if (category != null)
                {
                    catalogModel.ParentCategoryName = category.DisplayName;
                }
            }
            if (string.Equals(catalogModel.ProductId, currentStorefront.GiftCardProductId, StringComparison.Ordinal))
            {
                catalogModel.GiftCardAmountOptions = GetGiftCardAmountOptions(visitorContext, currentStorefront, productEntity);
            }
            else
            {
                CatalogManager.GetProductPrice(currentStorefront, visitorContext, productEntity, null);
                catalogModel.CustomerAverageRating = CatalogManager.GetProductRating(productItem, null);
            }
            catalogModel.Initialize(productEntity, false);
            SiteContext.Items["CurrentCatalogItemVariantsRenderingModel"] = catalogModel;
            return(catalogModel);
        }
Example #8
0
        public OrderLinesViewModel GetOrderLinesRenderingModel(IVisitorContext visitorContext, string orderId)
        {
            OrderLinesViewModel model = ModelProvider.GetModel <OrderLinesViewModel>();

            Init(model);
            if (string.IsNullOrEmpty(orderId))
            {
                return(OrderLinesMockData.InitializeMockData(model));
            }

            ManagerResponse <GetVisitorOrderResult, Order> orderDetails = OrderManager.GetOrderDetails(StorefrontContext.CurrentStorefront, visitorContext, orderId);

            if (!orderDetails.ServiceProviderResult.Success || orderDetails.Result == null)
            {
                string systemMessage = StorefrontContext.GetSystemMessage("Could not retrieve order details!", true);
                model.ErrorMessage = systemMessage;
                return(model);
            }
            model.Initialize(orderDetails.Result);
            return(model);
        }
        protected virtual ProductSummaryViewModel CatalogItemRenderingModel(IVisitorContext visitorContext, Item productItem)
        {
            Assert.ArgumentNotNull(visitorContext, "visitorContext");

            var currentStorefront = StorefrontContext.CurrentStorefront;
            var variantEntityList = new List <VariantEntity>();

            if (productItem != null && productItem.HasChildren)
            {
                foreach (Item variant in productItem.Children)
                {
                    VariantEntity model = ModelProvider.GetModel <VariantEntity>();
                    model.Initialize(variant);
                    variantEntityList.Add(model);
                }
            }
            ProductEntity productEntity = ModelProvider.GetModel <ProductEntity>();

            productEntity.Initialize(currentStorefront, productItem, variantEntityList);
            var renderingModel = ModelProvider.GetModel <ProductSummaryViewModel>();

            var products = new List <ProductEntity> {
                productEntity
            };

            InventoryManager.GetProductsStockStatus(currentStorefront, products, currentStorefront.UseIndexFileForProductStatusInLists);
            CatalogManager.GetProductBulkPrices(currentStorefront, visitorContext, products);
            if (productEntity.ProductId == currentStorefront.GiftCardProductId)
            {
                renderingModel.GiftCardAmountOptions = GetGiftCardAmountOptions(visitorContext, currentStorefront, productEntity);
            }
            else
            {
                renderingModel.CustomerAverageRating = CatalogManager.GetProductRating(productItem);
            }
            renderingModel.Initialize(productEntity, false);
            return(renderingModel);
        }
        protected virtual CatalogItemVariantsRenderingModel GetProduct(
            IVisitorContext visitorContext)
        {
            Item currentCatalogItem = SiteContext.CurrentCatalogItem;
            CatalogItemVariantsRenderingModel itemRenderingModel;

            if (currentCatalogItem != null)
            {
                Item productItem = currentCatalogItem;
                itemRenderingModel      = GetCatalogItemVariantsRenderingModel(visitorContext, productItem);
                itemRenderingModel.Item = itemRenderingModel.DataSourceItem = itemRenderingModel.PageItem = currentCatalogItem;
            }
            else
            {
                //Important: need to get the new variant model
                var model = ModelProvider.GetModel <CatalogItemVariantsRenderingModel>();
                Init(model);

                //Important: need to create a variant version of mock data rendering model
                itemRenderingModel      = CatalogItemVariantsRenderingModelMockData.InitializeMockData(model);
                itemRenderingModel.Item = Context.Item; //Need a mock catalog item
            }
            return(itemRenderingModel);
        }
Example #11
0
 public void Initialize(ProductEntity product, bool initializeAsMock = false)
 {
     Assert.ArgumentNotNull((object)product, nameof(product));
     CatalogItem = product.Item;
     ProductId   = product.ProductId;
     if (!initializeAsMock)
     {
         IsBundle   = ItemTypeProvider.IsBundle(product.Item);
         IsCategory = ItemTypeProvider.GetItemType(CatalogItem) == Sitecore.Commerce.XA.Foundation.Common.Constants.ItemTypes.Category;
         SetImages();
         string str = product.Item[FieldIDs.DisplayName.ToString()];
         DisplayName       = string.IsNullOrEmpty(str) ? string.Empty : str;
         Features          = CatalogItem["Features"];
         CatalogName       = StorefrontContext.CurrentStorefront.Catalog;
         Description       = CatalogItem["Description"];
         StockStatus       = product.StockStatus;
         StockStatusName   = product.StockStatusName;
         DisplayNameRender = PageContext.Current.HtmlHelper.Sitecore().Field(FieldIDs.DisplayName.ToString(), product.Item);
         DescriptionRender = PageContext.Current.HtmlHelper.Sitecore().Field("Description", product.Item);
         SetLink();
         if (IsBundle)
         {
             List <BundledItemViewModel> bundledItemViewModelList = new List <BundledItemViewModel>();
             NameValueCollection         urlParameters            = WebUtil.ParseUrlParameters(CatalogItem[Sitecore.Commerce.XA.Foundation.Common.Constants.ItemFieldNames.BundleItems]);
             foreach (string index in urlParameters)
             {
                 BundledItemViewModel model = ModelProvider.GetModel <BundledItemViewModel>();
                 Item obj = Context.Database.GetItem(ID.Parse(index));
                 model.Initialize(obj, System.Convert.ToDecimal(urlParameters[index], CultureInfo.InvariantCulture));
                 bundledItemViewModelList.Add(model);
             }
             BundledItems = bundledItemViewModelList;
         }
     }
     else
     {
         IsCategory      = false;
         StockStatus     = product.StockStatus;
         StockStatusName = product.StockStatusName;
         Images          = new List <MediaItem>();
     }
     CurrencySymbol = CurrentStorefront.SelectedCurrency;
     AdjustedPrice  = product.AdjustedPrice;
     HighestPricedVariantAdjustedPrice = product.HighestPricedVariantAdjustedPrice;
     ListPrice = product.ListPrice;
     LowestPricedVariantAdjustedPrice = product.LowestPricedVariantAdjustedPrice;
     LowestPricedVariantListPrice     = product.LowestPricedVariantListPrice;
     CustomerAverageRating            = product.CustomerAverageRating;
     if (product.Variants != null && product.Variants.Any <VariantEntity>())
     {
         List <VariantViewModel> variantViewModelList = new List <VariantViewModel>();
         foreach (VariantEntity variant in product.Variants)
         {
             VariantViewModel model = ModelProvider.GetModel <VariantViewModel>();
             model.Initialize(variant);
             variantViewModelList.Add(model);
         }
         Variants = variantViewModelList;
     }
     if (initializeAsMock)
     {
         return;
     }
     VariantDefinitions = VariantDefinitionProvider.GetVariantDefinitions(CatalogItem);
 }