Esempio n. 1
0
        public virtual async Task <IActionResult> ProductsAsync(AbcPromoProductSearchModel searchModel)
        {
            var products = await _abcPromoService.GetProductsByPromoIdAsync(searchModel.AbcPromoId);

            var productsPaged = products.ToPagedList(searchModel);

            var model = await new AbcPromoProductListModel().PrepareToGridAsync(searchModel, productsPaged, () =>
            {
                return(products.SelectAwait(async product =>
                {
                    var productAbcDescription =
                        await _productAbcDescriptionService.GetProductAbcDescriptionByProductIdAsync(product.Id);
                    var abcItemNumber = productAbcDescription?.AbcItemNumber;

                    var abcPromoProductModel = new AbcPromoProductModel()
                    {
                        AbcItemNumber = abcItemNumber,
                        Name = product.Name,
                        Published = product.Published
                    };

                    return abcPromoProductModel;
                }));
            });

            return(Json(model));
        }
        public virtual async Task <IActionResult> List(MissingImageProductSearchModel searchModel)
        {
            var productsWithoutImages = await _customProductService.GetProductsWithoutImagesAsync();

            var pagedList = productsWithoutImages.ToPagedList(searchModel);
            var model     = await new MissingImageProductListModel().PrepareToGridAsync(searchModel, pagedList, () =>
            {
                //fill in model values from the entity
                return(pagedList.SelectAwait(async product =>
                {
                    var pad = await _productAbcDescriptionService.GetProductAbcDescriptionByProductIdAsync(product.Id);
                    var itemNo = pad?.AbcItemNumber;

                    var missingImageProductModel = new MissingImageProductModel()
                    {
                        ItemNumber = itemNo,
                        Sku = product.Sku,
                        Name = product.Name
                    };

                    return missingImageProductModel;
                }));
            });

            return(Json(model));
        }
Esempio n. 3
0
        public async System.Threading.Tasks.Task HandleEventAsync(EntityDeletedEvent <ProductPicture> eventMessage)
        {
            // Is this an ABC product with an ABC Item Number?
            var pad = await _productAbcDescriptionService.GetProductAbcDescriptionByProductIdAsync(eventMessage.Entity.ProductId);

            if (pad == null)
            {
                return;
            }

            // Is there a picture in product_images?
            var abcProductImagePath = _nopFileProvider.GetFiles("wwwroot/product_images", $"{pad.AbcItemNumber}_large.*").FirstOrDefault();

            if (abcProductImagePath == null)
            {
                return;
            }

            // Are they the same picture? If so delete.
            var nopPictureBinary = await _pictureService.GetPictureBinaryByPictureIdAsync(eventMessage.Entity.PictureId);

            var fileSystemBinary = await _nopFileProvider.ReadAllBytesAsync(abcProductImagePath);

            if (nopPictureBinary.BinaryData.SequenceEqual(fileSystemBinary))
            {
                _nopFileProvider.DeleteFile(abcProductImagePath);
                await _logger.InformationAsync($"Deleted image `{abcProductImagePath}` (image deleted in NOP)");
            }
        }
        private async Task <string> GetProductDescriptionAsync(Product product)
        {
            var plpDescription = await _genericAttributeService.GetAttributeAsync <Product, string>(
                product.Id, "PLPDescription");

            if (plpDescription != null)
            {
                return(plpDescription);
            }

            var pad = await _productAbcDescriptionService.GetProductAbcDescriptionByProductIdAsync(product.Id);

            return(pad != null ? pad.AbcDescription : product.ShortDescription);
        }
        /*
         * Because of the way AJAX loading of products works, we should always
         * pass in a View instead of an EmptyResult. This ensures the CSS for
         * the modal is always loaded.
         */
        public async Task <IViewComponentResult> InvokeAsync(
            string widgetZone,
            object additionalData = null
            )
        {
            const string productListingCshtml =
                "~/Plugins/Widgets.AbcSynchronyPayments/Views/ProductListing.cshtml";
            SynchronyPaymentModel model = null;

            var productId = GetProductId(additionalData);

            if (productId == -1)
            {
                await _logger.ErrorAsync(
                    "Incorrect data model passed to ABC Warehouse " +
                    "Synchrony Payments widget.");

                return(View(productListingCshtml, model));
            }

            var productAbcDescription = await _productAbcDescriptionService.GetProductAbcDescriptionByProductIdAsync(productId);

            var abcItemNumber = productAbcDescription?.AbcItemNumber;

            // also allow getting info from generic attribute
            var productGenericAttributes = await _genericAttributeService.GetAttributesForEntityAsync(productId, "Product");

            var monthsGenericAttribute = productGenericAttributes.Where(ga => ga.Key == "SynchronyPaymentMonths")
                                         .FirstOrDefault();

            if (abcItemNumber == null && monthsGenericAttribute == null)
            {
                // No ABC Item number (or no months indicator), skip processing
                return(View(productListingCshtml, model));
            }

            var productAbcFinance =
                await _productAbcFinanceService.GetProductAbcFinanceByAbcItemNumberAsync(
                    abcItemNumber
                    );

            if (productAbcFinance == null && monthsGenericAttribute == null)
            {
                // No financing information
                return(View(productListingCshtml, model));
            }

            // generic attribute data
            var isMinimumGenericAttribute = productGenericAttributes.Where(ga => ga.Key == "SynchronyPaymentIsMinimum")
                                            .FirstOrDefault();
            var offerValidFromGenericAttribute = productGenericAttributes.Where(ga => ga.Key == "SynchronyPaymentOfferValidFrom")
                                                 .FirstOrDefault();
            var offerValidToGenericAttribute = productGenericAttributes.Where(ga => ga.Key == "SynchronyPaymentOfferValidTo")
                                               .FirstOrDefault();

            var product = await _productService.GetProductByIdAsync(productId);

            var months = productAbcFinance != null ?
                         productAbcFinance.Months :
                         int.Parse(monthsGenericAttribute.Value);
            var isMinimumPayment = productAbcFinance != null ?
                                   productAbcFinance.IsDeferredPricing :
                                   bool.Parse(isMinimumGenericAttribute.Value);
            var offerValidFrom = productAbcFinance != null ?
                                 productAbcFinance.StartDate.Value :
                                 DateTime.Parse(offerValidFromGenericAttribute.Value);
            var offerValidTo = productAbcFinance != null ?
                               productAbcFinance.EndDate.Value :
                               DateTime.Parse(offerValidToGenericAttribute.Value);

            var price = await _abcMattressListingPriceService.GetListingPriceForMattressProductAsync(productId) ?? product.Price;

            var isMattressProduct = _abcMattressProductService.IsMattressProduct(productId);

            model = new SynchronyPaymentModel
            {
                MonthCount     = months,
                MonthlyPayment = CalculatePayment(
                    price, isMinimumPayment, months
                    ),
                ProductId             = productId,
                ApplyUrl              = await GetApplyUrlAsync(),
                IsMonthlyPaymentStyle = !isMinimumPayment,
                EqualPayment          = CalculateEqualPayments(
                    price, months
                    ),
                ModalHexColor  = await HtmlHelpers.GetPavilionPrimaryColorAsync(),
                StoreName      = (await _storeContext.GetCurrentStoreAsync()).Name,
                ImageUrl       = await GetImageUrlAsync(),
                OfferValidFrom = offerValidFrom.ToShortDateString(),
                OfferValidTo   = offerValidTo.ToShortDateString()
            };

            model.FullPrice    = price;
            model.FinalPayment = model.FullPrice -
                                 (model.MonthlyPayment * (model.MonthCount - 1));
            model.IsHidden = isMattressProduct && price < 697.00M;

            if (model.MonthlyPayment == 0)
            {
                await _logger.WarningAsync(
                    $"ABC Product #{productAbcFinance.AbcItemNumber} has a " +
                    "$0 monthly fee, likely not marked with a correct " +
                    "payment type.");

                return(View(productListingCshtml, model));
            }

            switch (widgetZone)
            {
            case "productbox_addinfo_middle":
                return(View(productListingCshtml, model));

            case CustomPublicWidgetZones.ProductDetailsAfterPrice:
                return(View("~/Plugins/Widgets.AbcSynchronyPayments/Views/ProductDetail.cshtml", model));
            }

            await _logger.WarningAsync(
                "ABC Synchrony Payments: Did not match with any passed " +
                "widgets, skipping display");

            return(View(productListingCshtml, model));
        }
Esempio n. 6
0
        public async Task <IList <YahooDetailRow> > GetYahooDetailRowsAsync(Order order)
        {
            var result             = new List <YahooDetailRow>();
            var pickupLineNumber   = 1;
            var shippingLineNumber = 1;
            var orderItems         = await _customOrderService.GetOrderItemsAsync(order.Id);

            foreach (var orderItem in orderItems)
            {
                int lineNumber = GetLineNumber(ref pickupLineNumber, ref shippingLineNumber, orderItem);

                var product = await _productService.GetProductByIdAsync(orderItem.ProductId);

                var productAbcDescription = await _productAbcDescriptionService.GetProductAbcDescriptionByProductIdAsync(
                    orderItem.ProductId
                    );

                var storeUrl = (await _storeService.GetStoreByIdAsync(order.StoreId))?.Url;
                var warranty = await _customOrderService.GetOrderItemWarrantyAsync(orderItem);

                if (warranty != null)
                {
                    // adjust price for item
                    orderItem.UnitPriceExclTax -= warranty.PriceAdjustment;
                }

                (string code, decimal price)standardItemCodeAndPrice =
                    GetCodeAndPrice(orderItem, product, productAbcDescription);

                result.Add(new YahooDetailRow(
                               _settings.OrderIdPrefix,
                               orderItem,
                               lineNumber,
                               product.Sku,
                               standardItemCodeAndPrice.code,
                               standardItemCodeAndPrice.price,
                               product.Name,
                               $"{storeUrl}{await _urlRecordService.GetSeNameAsync(product)}",
                               await GetPickupStoreAsync(orderItem)
                               ));
                lineNumber++;

                if (warranty != null)
                {
                    result.Add(new YahooDetailRow(
                                   _settings.OrderIdPrefix,
                                   orderItem,
                                   lineNumber,
                                   standardItemCodeAndPrice.code,
                                   _warrantyService.GetWarrantySkuByName(warranty.Name),
                                   warranty.PriceAdjustment,
                                   warranty.Name,
                                   "", // no url for warranty line items
                                   await GetPickupStoreAsync(orderItem)
                                   ));
                    lineNumber++;
                }

                var freeGift = orderItem.GetFreeGift();
                if (freeGift != null)
                {
                    var amg = _abcMattressGiftService.GetAbcMattressGiftByDescription(freeGift);
                    if (amg == null)
                    {
                        throw new Exception($"Unable to match free gift named {freeGift}");
                    }

                    result.Add(new YahooDetailRow(
                                   _settings.OrderIdPrefix,
                                   orderItem,
                                   lineNumber,
                                   "",    // no item ID associated
                                   amg.ItemNo,
                                   0.00M, // free item
                                   freeGift,
                                   "",    // no url for free gifts
                                   await GetPickupStoreAsync(orderItem),
                                   -1
                                   ));
                    lineNumber++;
                }

                var mattressProtector = orderItem.GetMattressProtector();
                if (mattressProtector != null)
                {
                    var size = orderItem.GetMattressSize();
                    var amp  = _abcMattressProtectorService.GetAbcMattressProtectorsBySize(size)
                               .Where(p => p.Name == mattressProtector)
                               .FirstOrDefault();
                    if (amp == null)
                    {
                        throw new Exception($"Unable to match mattress protector named {mattressProtector}");
                    }

                    result.Add(new YahooDetailRow(
                                   _settings.OrderIdPrefix,
                                   orderItem,
                                   lineNumber,
                                   "", // no item ID associated
                                   amp.ItemNo,
                                   amp.Price,
                                   mattressProtector,
                                   "", // no url
                                   await GetPickupStoreAsync(orderItem)
                                   ));
                    lineNumber++;
                }

                lineNumber = await ProcessFrameAsync(orderItem, lineNumber, result);

                SetLineNumber(ref pickupLineNumber, ref shippingLineNumber, orderItem, lineNumber);
            }

            return(result);
        }