public static ProductBundleItemOrderData ToOrderData(this ProductBundleItemData bundleItemData, decimal priceWithDiscount = decimal.Zero,
                                                             string attributesXml = null, string attributesInfo = null)
        {
            if (!bundleItemData.IsValid())
            {
                return(null);
            }

            var    item           = bundleItemData.Item;
            string bundleItemName = item.GetLocalized(x => x.Name);

            var bundleData = new ProductBundleItemOrderData()
            {
                BundleItemId        = item.Id,
                ProductId           = item.ProductId,
                Sku                 = item.Product.Sku,
                ProductName         = (bundleItemName ?? item.Product.GetLocalized(x => x.Name)),
                ProductSeName       = item.Product.GetSeName(),
                VisibleIndividually = item.Product.VisibleIndividually,
                Quantity            = item.Quantity,
                DisplayOrder        = item.DisplayOrder,
                PriceWithDiscount   = priceWithDiscount,
                AttributesXml       = attributesXml,
                AttributesInfo      = attributesInfo,
                PerItemShoppingCart = item.BundleProduct.BundlePerItemShoppingCart
            };

            return(bundleData);
        }
Пример #2
0
        protected virtual async Task <object> CreateModelPartAsync(ProductBundleItemOrderData part, OrderItem orderItem, Product product, MessageContext messageContext)
        {
            Guard.NotNull(part, nameof(part));
            Guard.NotNull(orderItem, nameof(orderItem));
            Guard.NotNull(product, nameof(product));
            Guard.NotNull(messageContext, nameof(messageContext));

            var priceWithDiscount = FormatPrice(part.PriceWithDiscount, orderItem.Order, messageContext);

            var m = new Dictionary <string, object>
            {
                { "AttributeDescription", part.AttributesInfo.NullEmpty() },
                { "Quantity", part.Quantity > 1 && part.PerItemShoppingCart ? part.Quantity.ToString() : null },
                { "PerItemShoppingCart", part.PerItemShoppingCart },
                { "PriceWithDiscount", priceWithDiscount },
                { "Product", await CreateModelPartAsync(product, messageContext, part.AttributeSelection) }
            };

            await PublishModelPartCreatedEventAsync(part, m);

            return(m);
        }