コード例 #1
0
 public Product ProcessCatalog(Product product, int testOfferRuleId = 0)
 {
     product = _catalogOfferProcessor.ProcessCatalog(product, testOfferRuleId);
     return(product);
 }
コード例 #2
0
        public Product Build(Product product)
        {
            if (product == null)
            {
                throw new ArgumentNullException("product");
            }
            string key = string.Format(CacheKey.PRODUCT_BY_ID_KEY, product.Id);

            product = _cacheManager.GetWithExpiry(key, delegate()
            {
                // Get tax category
                product.TaxCategory = _taxCategoryMappingRepository.Table
                                      .Join(_taxCategoryRepository.Table, m => m.TaxCategoryId, t => t.Id, (m, t) => new { m, t })
                                      .Where(x => x.m.ProductId == product.Id)
                                      .Select(x => x.t)
                                      .FirstOrDefault();

                // Get product prices
                product.ProductPrices = _productPriceRepository.TableNoTracking.Where(x => x.ProductId == product.Id).ToList();

                // Get price option
                // Set default offer price
                for (int i = 0; i < product.ProductPrices.Count; i++)
                {
                    product.ProductPrices[i].Option = product.ProductPrices[i].GetOption((OptionType)product.OptionType, _cacheManager, _colourRepository);

                    if (_taxSettings.PricesIncludeTax)
                    {
                        product.ProductPrices[i].PriceInclTax = product.ProductPrices[i].Price;
                        product.ProductPrices[i].PriceExclTax = product.ProductPrices[i].Price * 100M / (100 + product.TaxCategory.Rate);

                        product.ProductPrices[i].OfferPriceInclTax = product.ProductPrices[i].PriceInclTax;
                        product.ProductPrices[i].OfferPriceExclTax = product.ProductPrices[i].PriceExclTax;
                    }
                    else
                    {
                        product.ProductPrices[i].PriceInclTax = product.ProductPrices[i].Price * 100M / (100 + product.TaxCategory.Rate);
                        product.ProductPrices[i].PriceExclTax = product.ProductPrices[i].Price;

                        product.ProductPrices[i].OfferPriceInclTax = product.ProductPrices[i].PriceInclTax;
                        product.ProductPrices[i].OfferPriceExclTax = product.ProductPrices[i].PriceExclTax;
                    }
                }

                // Sort prices in ascending order
                product.ProductPrices.ToList().Sort(delegate(ProductPrice price1, ProductPrice price2)
                                                    { return(price1.PriceExclTax.CompareTo(price2.PriceExclTax)); });

                // Get all reviews (including not approved ones)
                product.ProductReviews = _productReviewRepository.Table.Where(r => r.ProductId == product.Id).ToList();

                // Get product tags
                product.ProductTags = _productTagRepository.Table.Where(pt => pt.ProductId == product.Id).ToList();

                // Get restricted groups
                product.RestrictedGroups = _restrictedGroupMappingRepository.Table
                                           .Join(_restrictedGroupRepository.Table, m => m.RestrictedGroupId, g => g.Id, (m, g) => new { m, g })
                                           .Where(x => x.m.ProductId == product.Id)
                                           .Select(x => x.g)
                                           .ToList();

                // Get delivery
                product.Delivery = _deliveryRepository.Return(product.DeliveryId);

                // Get brand
                product.Brand = _brandService.GetBrandById(product.BrandId);

                // Get media
                product.ProductMedias = _productMediaRepository.TableNoTracking.Where(m => m.ProductId == product.Id).ToList();

                // TODO: To implement Google Shopping custom label
                // Get Google Shopping custom label group
                product.ProductGoogleCustomLabelGroup = _productGoogleCustomLabelGroupMappingRepository.Table
                                                        .Where(x => x.ProductId == product.Id)
                                                        .FirstOrDefault();

                // Process catalog offer
                if (product.OpenForOffer)
                {
                    product = _offerProcessor.ProcessCatalog(product);
                }

                return(product);
            });

            return(product);
        }