Example #1
0
        public async virtual Task <bool> MapRecurringOrderFrequencies(LineItemDetailViewModel vm, LineItem lineItem, CultureInfo cultureInfo)
        {
            if (lineItem == null)
            {
                return(false);
            }

            var scope = ComposerContext.Scope;
            var recurringProgramName = lineItem.RecurringOrderProgramName;

            if (string.IsNullOrEmpty(recurringProgramName) || !RecurringOrdersSettings.Enabled)
            {
                return(false);
            }

            var program = await RecurringOrderRepository.GetRecurringOrderProgram(scope, recurringProgramName).ConfigureAwait(false);

            vm.RecurringOrderFrequencyDisplayName = GetRecurringOrderFrequencyDisplayName(program, lineItem, cultureInfo);

            var programViewModel = RecurringOrderProgramViewModelFactory.CreateRecurringOrderProgramViewModel(program, cultureInfo);

            vm.RecurringOrderProgramFrequencies = programViewModel?.Frequencies;

            return(true);
        }
        protected virtual async Task <ProductViewModel> SetViewModelRecurringOrdersRelatedProperties(GetProductParam param, ProductViewModel vm, Overture.ServiceModel.Products.Product product)
        {
            if (param == null)
            {
                throw new ArgumentNullException(nameof(param));
            }
            if (vm == null)
            {
                throw new ArgumentNullException(nameof(vm));
            }

            var recurringOrdersEnabled = RecurringOrdersSettings.Enabled;

            var recurringOrderProgramName = product.PropertyBag.GetValueOrDefault <string>(Constants.ProductAttributes.RecurringOrderProgramName);

            if (string.IsNullOrWhiteSpace(recurringOrderProgramName))
            {
                return(vm);
            }

            vm.RecurringOrderProgramName            = recurringOrderProgramName;
            vm.Context["RecurringOrderProgramName"] = recurringOrderProgramName;

            var program = await RecurringOrdersRepository.GetRecurringOrderProgram(param.Scope, recurringOrderProgramName).ConfigureAwait(false);

            if (program == null)
            {
                return(vm);
            }


            vm.IsRecurringOrderEligible            = recurringOrdersEnabled;
            vm.Context["IsRecurringOrderEligible"] = recurringOrdersEnabled;

            if (recurringOrdersEnabled)
            {
                var recurringOrderProgramViewModel = RecurringOrderProgramViewModelFactory.CreateRecurringOrderProgramViewModel(program, param.CultureInfo);

                vm.RecurringOrderFrequencies            = recurringOrderProgramViewModel.Frequencies;
                vm.Context["RecurringOrderFrequencies"] = recurringOrderProgramViewModel.Frequencies;
            }

            return(vm);
        }