コード例 #1
0
        public async Task <ActionResult> Index(string shoppingCartId = null)
        {
            ShoppingCart cart = await _shoppingCartPersistence.Retrieve(shoppingCartId);

            IDictionary <string, ProductPart> products =
                await _productService.GetProductDictionary(cart.Items.Select(line => line.ProductSku));

            var items = await _priceService.AddPrices(cart.Items);

            ShoppingCartLineViewModel[] lines = await Task.WhenAll(items.Select(async item =>
            {
                ProductPart product          = products[item.ProductSku];
                Amount price                 = _priceStrategy.SelectPrice(item.Prices);
                ContentItemMetadata metaData = await _contentManager.GetContentItemMetadataAsync(product);
                return(new ShoppingCartLineViewModel
                {
                    Quantity = item.Quantity,
                    ProductSku = item.ProductSku,
                    ProductName = product.ContentItem.DisplayText,
                    UnitPrice = price,
                    LinePrice = item.Quantity *price,
                    ProductUrl = Url.RouteUrl(metaData.DisplayRouteValues),
                    Attributes = item.Attributes.ToDictionary(attr => attr.AttributeName)
                });
            }));

            var model = new ShoppingCartViewModel
            {
                Id     = shoppingCartId,
                Lines  = lines,
                Totals = lines.GroupBy(l => l.LinePrice.Currency).Select(g => new Amount(g.Sum(l => l.LinePrice.Value), g.Key))
            };

            return(View(model));
        }
コード例 #2
0
        private void ProcessSku(ProductPart part)
        {
            if (string.IsNullOrWhiteSpace(part.Sku) ||
                _SKUGenerationServices.Value.GetSettings().AllowCustomPattern)   //AllowCustomPattern is handled inside GenerateSku
            //generate a new sku
            {
                part.Sku = _SKUGenerationServices.Value.GenerateSku(part);
            }

            //if the SKU is empty, generate a new one
            if (string.IsNullOrWhiteSpace(part.Sku))
            {
                _SKUGenerationServices.Value.ProcessSku(part);
                _orchardServices.Notifier.Information(T("A new SKU has been generated: \"{0}\"", part.Sku));
                return;
            }

            //check for SKU conflicts
            var previous = part.Sku;

            if (!_SKUGenerationServices.Value.ProcessSku(part))
            {
                _orchardServices.Notifier.Warning(
                    T("Conflict between SKUs. \"{0}\" is already set for a previously created {2} so now we set it to \"{1}\"",
                      previous, part.Sku, part.ContentItem.ContentType));
            }
        }
コード例 #3
0
        public string GenerateSku(ProductPart part)
        {
            if (part == null)
            {
                throw new ArgumentNullException("part");
            }
            var pattern = GetSettings().SKUPattern;

            if (Settings.AllowCustomPattern && !string.IsNullOrWhiteSpace(part.Sku))
            {
                pattern = part.Sku;
            }
            if (string.IsNullOrWhiteSpace(pattern))
            {
                //use a default pattern
                pattern = DefaultSkuPattern;
            }
            var sku = _tokenizer.Replace(pattern,
                                         BuildTokenContext(part.ContentItem),
                                         new ReplaceOptions {
                Encoding = ReplaceOptions.NoEncode
            });

            return(sku);
        }
コード例 #4
0
ファイル: PartPolicy.cs プロジェクト: wra222/testgit
        public void BindTo(PartUnit part, IPartOwner owner, string station, string editor, string key)
        {
#if DEBUG
            ISaveModule saver = (ISaveModule)GetInstance(_saveModule, typeof(ISaveModule));
#else
            ISaveModule saver = PartSpecialCodeContainer.GetInstance.GetSaveModule(_saveModule);
#endif
            if (saver != null)
            {
                saver.Save(part, owner, station, key);
            }

            if (NeedCommonSave)
            {
                IProductPart newPart = new ProductPart();
                newPart.PartSn = part.Sn;        //sn
                newPart.PartID = part.Pn;       //pn
                newPart.BomNodeType = part.Type; //BomNodeType
                newPart.PartType = part.ValueType; //part.Type
                newPart.CheckItemType = part.ItemType; //CheckItemType
                newPart.CustomerPn = part.CustPn??string.Empty;
                newPart.Iecpn = part.IECPn??string.Empty;
                newPart.Station = station;
                newPart.Editor = editor;
                owner.AddPart(newPart);
            }
        }
コード例 #5
0
        public dynamic CreateShape(IUser user, ProductPart product = null)
        {
            if (user == null)
            {
                throw new ArgumentNullException("user");
            }

            var productId       = 0;
            var attributeShapes = new List <dynamic>();

            if (product != null)
            {
                productId       = product.ContentItem.Id;
                attributeShapes = _attributesDrivers
                                  .Select(p => p.GetAttributeDisplayShape(product.ContentItem, _shapeFactory))
                                  .ToList();
            }
            //get the additional shapes from the extension providers
            var creationShapes = new List <dynamic>();

            //process extensions
            foreach (var ext in _wishListExtensionProviders)
            {
                creationShapes.Add(ext.BuildCreationShape(user, product));
            }

            return(_shapeFactory.CreateNewWishList(
                       ProductId: productId,
                       AttributeShapes: attributeShapes,
                       CreationShapes: creationShapes,
                       WishListTitle: DefaultWishListTitle
                       ));
        }
コード例 #6
0
 public ProductViewModel GetModel(ProductPart part)
 {
     ProductViewModel viewModel = this.GetProductReference(part);
     if (!String.IsNullOrEmpty(viewModel.RequestedCatalogCode) && !String.IsNullOrEmpty(viewModel.RequestedSKU))
     {
         this._webStoreServices.UsingClient(
             c =>
             {
                 String variantProductName = c.CatalogClient.ResolveName(typeof(VariantProduct));
                 viewModel.ReferenceProduct = (c.CatalogClient.Products
                                                             .OfType<ReferenceProduct>() as DataServiceQuery<ReferenceProduct>)
                                                             .Expand(rp => rp.Brand)
                                                             .Expand(String.Format("{0}/VariableProduct/VariantProducts/Attributes/Files", variantProductName))
                                                             .Expand(String.Format("{0}/VariableProduct/VariantProducts/PriceWithLowerQuantity", variantProductName))
                                                             .Expand("Prices/TaxDetails")
                                                             .Expand("Prices/DiscountDetails")
                                                             .Expand(rp => rp.PriceWithLowerQuantity)
                                                             .Expand("Attributes/Files")
                                                             .Where(rp => rp.Catalog.Code == viewModel.RequestedCatalogCode && rp.SKU == viewModel.RequestedSKU)
                                                             .FirstOrDefault();
             }
         );
     }
     return viewModel;
 }
コード例 #7
0
        public void AddProductToWishList(IUser user, WishListListPart wishlist, ProductPart product, IDictionary <int, ProductAttributeValueExtended> attributes)
        {
            if (user == null)
            {
                throw new ArgumentNullException("user");
            }
            //we can add the product to the wishlist
            if (!ValidateAttributes(product.ContentItem.Id, attributes))
            {
                // If attributes don't validate, don't add the product, but notify
                _notifier.Warning(T("Couldn't add this product because of invalid attributes. Please refresh the page and try again."));
                return;
            }
            //compute the ShoppingCartItem for the product we are adding
            var item = new ShoppingCartItem(product.ContentItem.Id, 1, attributes);

            //check whether the product is in the wishlist already
            if (!ItemIsInWishlist(wishlist, item))
            {
                //create a new wishlist item and add it
                var newItem = _contentManager.New <WishListItemPart>("WishListItem");
                newItem.WishListId = wishlist.ContentItem.Id;
                newItem.Item       = item;
                _contentManager.Create(newItem.ContentItem);

                //process extensions
                foreach (var ext in _wishListExtensionProviders)
                {
                    ext.WishListAddedItem(user, wishlist, newItem);
                }
            }
        }
コード例 #8
0
        public ProductPart GetProduct(string path)
        {
            var         Product = _pathResolutionService.GetPath(path);
            ProductPart product = Product.ContentItem.As <ProductPart>();

            return(product);
        }
コード例 #9
0
 private void CreateSku(ProductPart part)
 {
     if (_SKUGenerationServices.Value.GetSettings().GenerateSKUAutomatically)
     {
         ProcessSku(part);
     }
 }
コード例 #10
0
 private void SynchronizeInventory(ProductPart part, IEnumerable <ProductPart> targets)
 {
     foreach (var target in targets)
     {
         target.Inventory = part.Inventory;
     }
 }
        // check if products are discounted
        public bool HasDiscount(ProductPart part)
        {
            var discountPrice = part.ProductPriceService.GetDiscountPrice(part);
            var fullPrice     = part.ProductPriceService.GetPrice(part);
            var hasDiscount   = discountPrice > 0M && discountPrice < fullPrice;

            return(hasDiscount);
        }
コード例 #12
0
    protected void RadTreeView1_NodeBound(object o, RadTreeNodeEventArgs e)
    {
        ProductManager manager     = new ProductManager(this);
        ProductPart    productPart = manager.GetProductPart(Convert.ToInt32(e.Node.Value));

        e.Node.Text    += " (" + productPart.Quantity + ")";
        e.Node.Expanded = true;
    }
コード例 #13
0
        public override IEnumerable <ProductPart> GetProductsWithSameInventory(ProductPart part)
        {
            var sSet = base.GetProductsWithSameInventory(part).ToList();

            sSet.AddRange(_contentManager
                          .Query <ProductPart, ProductPartVersionRecord>(VersionOptions.Latest)
                          .Where(pa => pa.Sku == part.Record.Sku && pa.ContentItemRecord.Id != part.Record.ContentItemRecord.Id)
                          .List());
            return(sSet);
        }
コード例 #14
0
        private void ScheduleUnpublish(PublishContentContext ctx, ProductPart part) {
            _scheduledTaskManager.DeleteTasks(part.ContentItem, t => t.TaskType == Constants.UnpublishTaskName);

            var settings = _workContextAccessor.GetContext().CurrentSite.Get<ProductSettingsPart>();
            if (settings.HideProductDelay > 0) {
                // Schedule the unpublish moment
                var dateToUnpublish = DateTime.UtcNow.AddDays(settings.HideProductDelay);
                _scheduledTaskManager.CreateTask(Constants.UnpublishTaskName, dateToUnpublish, part.ContentItem);
            }
        }
コード例 #15
0
 public virtual IEnumerable<ProductPart> GetProductsWithSameInventory(ProductPart part)
 {
     //return Latest and Published versions, unless they coincide or are the same as part
     var sSet = new ProductPart[] {
         _contentManager.Query<ProductPart>(VersionOptions.Published, part.ContentItem.ContentType)
             .Where<ProductPartVersionRecord>(ppvr => ppvr.ContentItemRecord == part.Record.ContentItemRecord).List().FirstOrDefault(),
         _contentManager.Query<ProductPart>(VersionOptions.Latest, part.ContentItem.ContentType)
             .Where<ProductPartVersionRecord>(ppvr => ppvr.ContentItemRecord == part.Record.ContentItemRecord).List().FirstOrDefault()
     };
     return sSet.Distinct().Where(lp => lp != null && lp.Record.Id != part.Record.Id);
 }
コード例 #16
0
        public IEnumerable <int> GetIdsOfValidSKUDuplicates(ProductPart part)
        {
            LocalizationPart lPart = part.ContentItem.As <LocalizationPart>();

            if (lPart == null)
            {
                //the ContentItem is not Localizabel so this does not apply
                return(new int[0]);
            }
            return(_localizationService.GetLocalizations(part.ContentItem, VersionOptions.Latest).Select(ci => ci.Id));
        }
コード例 #17
0
        public override void SynchronizeInventories(ProductPart part)
        {
            base.SynchronizeInventories(part); //call this to synchronize bundles
            int inv = GetInventory(part);

            foreach (var pp in
                     GetProductsWithSameInventory(part)
                     .Where(pa => GetInventory(pa) != inv)) //condition to avoid infinite recursion
            {
                SetInventory(pp, GetInventory(part));       //call methods from base class
            }
        }
コード例 #18
0
ファイル: PriceService.cs プロジェクト: YSRE/SuperRocket
        public IEnumerable <PriceTier> GetDiscountedPriceTiers(ProductPart product)
        {
            var priceTiers = _tieredPriceProvider != null?_tieredPriceProvider.GetPriceTiers(product) : null;

            if (priceTiers != null)
            {
                priceTiers = priceTiers.Select(t => new PriceTier()
                {
                    Quantity = t.Quantity, Price = GetDiscountedPrice(new ShoppingCartQuantityProduct(t.Quantity, product)).Price
                });
            }
            return(priceTiers);
        }
コード例 #19
0
        public ProductViewModel GetModel(ProductPart part)
        {
            ProductViewModel viewModel = this.GetProductReference(part);

            if (!String.IsNullOrEmpty(viewModel.RequestedCatalogCode) && !String.IsNullOrEmpty(viewModel.RequestedSKU))
            {
                this._webStoreServices.UsingClient(
                    c =>
                {
                    IQueryable <ReferenceProduct> productsQuery = c.CatalogClient.Products.OfType <ReferenceProduct>()
                                                                  .Include(rp => rp.Brand)
                                                                  .Include(rp => rp.AttributeValues.Select(av => av.Files))
                                                                  .Include(rp => rp.AttributeValues.Select(av => av.Attribute))
                                                                  .Include(rp => rp.PriceWithLowerQuantity.TaxDetails)
                                                                  .Include(rp => rp.PriceWithLowerQuantity.DiscountDetails)
                                                                  .Include(rp => (rp as VariantProduct).VariableProduct.AttributeValues.Select(av => av.Files))
                                                                  .Include(rp => (rp as VariantProduct).VariableProduct.AttributeValues.Select(av => av.Attribute))
                                                                  .Include(rp => (rp as VariantProduct).VariableProduct.VariantProducts.Select(vp => vp.Brand))
                                                                  .Include(rp => (rp as VariantProduct).VariableProduct.VariantProducts.Select(vp => vp.AttributeValues.Select(av => av.Files)))
                                                                  .Include(rp => (rp as VariantProduct).VariableProduct.VariantProducts.Select(vp => vp.AttributeValues.Select(av => av.Attribute)))
                                                                  .Include(rp => (rp as VariantProduct).VariableProduct.VariantProducts.Select(vp => vp.PriceWithLowerQuantity.TaxDetails))
                                                                  .Include(rp => (rp as VariantProduct).VariableProduct.VariantProducts.Select(vp => vp.PriceWithLowerQuantity.DiscountDetails));

                    foreach (ICatalogEventHandler catalogEventHandler in this._catalogEventHandlers)
                    {
                        foreach (Expression <Func <ReferenceProduct, Object> > include in catalogEventHandler.GetProductInclusions())
                        {
                            productsQuery = productsQuery.Include(include);
                        }
                    }

                    viewModel.ReferenceProduct = productsQuery.FirstOrDefault(rp => rp.Catalog.Code == viewModel.RequestedCatalogCode && rp.SKU == viewModel.RequestedSKU);

                    if (viewModel.ReferenceProduct != null)
                    {
                        viewModel.Inventories = c.StoreClient.GetInventory(
                            new[] { viewModel.ReferenceProduct.ProductId },
                            new Location
                        {
                            RegionId  = this._webStoreServices.CurrentRegionId,
                            CountryId = this._webStoreServices.CurrentCountryId
                        }
                            );
                    }
                }
                    );
            }

            return(viewModel);
        }
コード例 #20
0
 public virtual int GetInventory(ProductPart part)
 {
     IBundleService bundleService;
     var inventory = part.Inventory;
     if (_workContextAccessor.GetContext().TryResolve(out bundleService) && part.Has<BundlePart>()) {
         var bundlePart = part.As<BundlePart>();
         var ids = bundlePart.ProductIds.ToList();
         if (!ids.Any()) return 0;
         inventory =
             bundleService
                 .GetProductQuantitiesFor(bundlePart)
                 .Min(p => p.Product.Inventory / p.Quantity);
     }
     return inventory;
 }
コード例 #21
0
 private ProductViewModel GetProductReference(ProductPart part)
 {
     ProductViewModel viewModel = new ProductViewModel();
     if (part.FromUrl && !String.IsNullOrEmpty(part.CatalogCodeUrlParameterKey) && !String.IsNullOrEmpty(part.SKUUrlParameterKey))
     {
         viewModel.RequestedCatalogCode = HttpContext.Current.Request.QueryString[part.CatalogCodeUrlParameterKey];
         viewModel.RequestedSKU = HttpContext.Current.Request.QueryString[part.SKUUrlParameterKey];
     }
     else if (!part.FromUrl)
     {
         viewModel.RequestedCatalogCode = part.CatalogCode;
         viewModel.RequestedSKU = part.SKU;
     }
     return viewModel;
 }
コード例 #22
0
        private string GenerateUniqueSku(ProductPart part, IEnumerable <string> existingSkus)
        {
            if (existingSkus == null || !existingSkus.Contains(part.Sku))
            {
                return(part.Sku);
            }

            int?version = existingSkus
                          .Select(s => GetSkuVersion(part.Sku, s))
                          .OrderBy(i => i).LastOrDefault();

            return(version != null?
                   string.Format("{0}-{!}", part.Sku, version) :
                       part.Sku);
        }
コード例 #23
0
        private void SetCategory(CreateContentContext ctx, ProductPart part) {

            var settings = part.Settings.GetModel<ProductPartSettings>();

            var category = settings.CategoryId;
            int categoryId;
            if (category == "0" || !int.TryParse(category, out categoryId))
                return;

            var term = _taxonomyService.GetTerm(categoryId);

            // Store category in part
            part.Category = term.Name;

            // As well as in the termspart, to make use of the taxonomies
            _taxonomyService.UpdateTerms(part.ContentItem, new List<TermPart>{term}, Constants.CategoryTaxonomyName);
        }
コード例 #24
0
        private ProductViewModel GetProductReference(ProductPart part)
        {
            ProductViewModel viewModel = new ProductViewModel();

            if (part.FromUrl && !String.IsNullOrEmpty(part.CatalogCodeUrlParameterKey) && !String.IsNullOrEmpty(part.SKUUrlParameterKey))
            {
                viewModel.RequestedCatalogCode = this._orchardServices.WorkContext.HttpContext.Request.QueryString[part.CatalogCodeUrlParameterKey];
                viewModel.RequestedSKU         = this._orchardServices.WorkContext.HttpContext.Request.QueryString[part.SKUUrlParameterKey];
            }
            else if (!part.FromUrl)
            {
                viewModel.RequestedSKU         = part.SKU;
                viewModel.RequestedCatalogCode = part.CatalogCode;
            }

            return(viewModel);
        }
コード例 #25
0
        public ActionResult Create()
        {
            if (!Services.Authorizer.Authorize(Permissions.ManageProduct, T("Not allowed to create products")))
            {
                return(new HttpUnauthorizedResult());
            }

            ProductPart product = Services.ContentManager.New <ProductPart>("Product");

            if (product == null)
            {
                return(HttpNotFound());
            }

            var model = Services.ContentManager.BuildEditor(product);

            return(View(model));
        }
コード例 #26
0
        public static ProductPart ToProductPart(this demoCatalogDto.DemoProductPart productPartDto, string currentLanguage)
        {
            var result = new ProductPart
            {
                Id          = productPartDto.Id,
                Name        = productPartDto.Name,
                Description = productPartDto.Description,
                Image       = new Image {
                    Url = productPartDto.ImgSrc.RemoveLeadingUriScheme(), LanguageCode = currentLanguage
                },
                IsRequired     = productPartDto.IsRequired ?? true,
                MinQuantity    = productPartDto.MinQuantity ?? 0,
                MaxQuantity    = productPartDto.MaxQuantity ?? 0,
                SelectedItemId = productPartDto.DefaultItemId,
            };

            return(result);
        }
コード例 #27
0
    protected void btnUpdate_Click(object sender, EventArgs e)
    {
        if (RadTreeView1.SelectedNode == null)
        {
            ShowError("Selecione uma categoria!");
            return;
        }

        ProductManager manager     = new ProductManager(this);
        ProductPart    productPart = manager.GetProductPart(Convert.ToInt32(RadTreeView1.SelectedNode.Value));

        productPart.Name     = txtProductPart.Text;
        productPart.Quantity = Convert.ToInt16(txtQuantity.Text);
        manager.DbContext.SubmitChanges();
        //DataManager.CurrentContext.SubmitChanges();

        BindTree();
    }
コード例 #28
0
        public void TestSend()
        {
            MessageQueueing <ProductPart> queueing = new MessageQueueing <ProductPart>();

            ProductPart product = new ProductPart();

            product.Description   = "This is a test 1";
            product.ProductNumber = "CAPLIN-01";
            product.ProductPartId = 1;
            product.UnitPrice     = 50.00M;
            queueing.SendMessage("ProductExchange", "Product", product);

            product               = new ProductPart();
            product.Description   = "This is a test 2";
            product.ProductNumber = "CAPLIN-02";
            product.ProductPartId = 2;
            product.UnitPrice     = 75.00M;
            queueing.SendMessage("ProductExchange", "Product", product);
        }
コード例 #29
0
    protected void btnDelete_Click(object sender, EventArgs e)
    {
        if (RadTreeView1.SelectedNode == null)
        {
            ShowError("Selecione uma categoria!");
            return;
        }
        ProductManager manager     = new ProductManager(this);
        ProductPart    productPart = manager.GetProductPart(Convert.ToInt32(RadTreeView1.SelectedNode.Value));

        try
        {
            manager.DeleteProductPart(productPart);
        }
        catch (Exception ex)
        {
            ShowError(ex.Message.ToString());
            return;
        }

        BindTree();
    }
コード例 #30
0
        public ProductPriceEditorViewModel(
            ProductVatConfigurationPart vatPart,
            ProductPart product,
            IProductPriceService productPriceService)
            : this(vatPart) {
            ShowShape   = true;
            HasDiscount = true;
            BasePrice   = product != null
                    ? product.Price
                    : 0.0m;
            DiscountPrice = product != null
                ? product.DiscountPrice
                : -1.0m;
            BaseTaxedPrice = product != null && productPriceService != null
                ? productPriceService.GetPrice(product)
                : 0.0m;

            DiscountTaxedPrice = product != null && productPriceService != null
                ? productPriceService.GetDiscountPrice(product) >= 0
                    ? productPriceService.GetDiscountPrice(product) : -1.0m
                : -1.0m;
        }
コード例 #31
0
 /// <summary>
 /// Uses the inventory of the ProductPart parameter to update the ProductParts whose inventory
 /// has to be kept in synch with the parameter's.
 /// </summary>
 /// <param name="part">The ProductPart whose inventory will be copied over.</param>
 public virtual void SynchronizeInventories(ProductPart part)
 {
     //Synchronize inventory between Latest and Published versions
     int inv = GetInventory(part);
     foreach (var pp in
        GetProductsWithSameInventory(part)
            .Where(pa => GetInventory(pa) != inv)) { //condition to avoid infinite recursion
         SetInventory(pp, GetInventory(part)); //call methods from base class
     }
     //Synchronize the inventory for the eventual bundles that contain the product
     IBundleService bundleService;
     if (_workContextAccessor.GetContext().TryResolve(out bundleService)) {
         var affectedBundles = _contentManager.Query<BundlePart, BundlePartRecord>()
             .Where(b => b.Products.Any(p => p.ContentItemRecord.Id == part.Id))
             .WithQueryHints(new QueryHints().ExpandParts<ProductPart>())
             .List();
         foreach (var bundle in affectedBundles.Where(b => b.ContentItem.As<ProductPart>() != null)) {
             var prod = bundle.ContentItem.As<ProductPart>();
             SetInventory(prod, GetInventory(prod));
         }
     }
 }
コード例 #32
0
        public IEnumerable <PriceTier> GetPriceTiers(ProductPart product)
        {
            var productSettings = _wca.GetContext().CurrentSite.As <ProductSettingsPart>();
            IEnumerable <PriceTier> priceTiers         = null;
            List <PriceTier>        adjustedPriceTiers = new List <PriceTier>();

            if (productSettings.AllowProductOverrides && product.OverrideTieredPricing)
            {
                priceTiers = product.PriceTiers;
            }
            else if (productSettings.DefineSiteDefaults && (!productSettings.AllowProductOverrides || !product.OverrideTieredPricing))
            {
                priceTiers = productSettings.PriceTiers;
            }

            if (priceTiers == null)
            {
                return(priceTiers);
            }

            foreach (var tier in priceTiers)
            {
                var adjustedPrice = tier.Price;

                if (tier.Price == null && tier.PricePercent != null)
                {
                    // Calculate absolute price from percentage value
                    adjustedPrice = product.Price * (double)tier.PricePercent / 100;
                }

                adjustedPriceTiers.Add(new PriceTier {
                    Price        = adjustedPrice,
                    Quantity     = tier.Quantity,
                    PricePercent = tier.PricePercent
                });
            }
            return(adjustedPriceTiers.OrderBy(t => t.Quantity));
        }
コード例 #33
0
        public bool ProcessSku(ProductPart part)
        {
            var similarSkuParts = GetSimilarSkus(part.Sku);

            //dont include the part we are processing
            similarSkuParts = similarSkuParts.Where(pp => pp.ContentItem.Id != part.ContentItem.Id);
            //consider exceptions to uniqueness
            if (_SKUUniquenessHelpers.Any())
            {
                var exceptionIds = _SKUUniquenessHelpers.SelectMany(p => p.GetIdsOfValidSKUDuplicates(part));
                similarSkuParts = similarSkuParts.Where(pp => !exceptionIds.Contains(pp.Id));
            }

            if (similarSkuParts.Any())
            {
                var oldSku = part.Sku;
                part.Sku = GenerateUniqueSku(part, similarSkuParts.Select(p => p.Sku));

                return(part.Sku == oldSku);
            }

            return(true);
        }
コード例 #34
0
 private Task BuildViewModel(OrderPartViewModel model, OrderPart part)
 => Task.Run(async() =>
 {
     model.ContentItem = part.ContentItem;
     IDictionary <string, ProductPart> products =
         await _productService.GetProductDictionary(part.LineItems.Select(line => line.ProductSku));
     OrderLineItemViewModel[] lineItems = await Task.WhenAll(part.LineItems.Select(async lineItem =>
     {
         ProductPart product          = products[lineItem.ProductSku];
         ContentItemMetadata metaData = await _contentManager.GetContentItemMetadataAsync(product);
         return(new OrderLineItemViewModel
         {
             Quantity = lineItem.Quantity,
             ProductSku = lineItem.ProductSku,
             ProductName = product.ContentItem.DisplayText,
             UnitPrice = lineItem.UnitPrice,
             LinePrice = lineItem.LinePrice,
             ProductRouteValues = metaData.DisplayRouteValues,
             Attributes = lineItem.Attributes.ToDictionary(attr => attr.Key, attr => attr.Value)
         });
     }));
     model.LineItems = lineItems;
     model.OrderPart = part;
 });
コード例 #35
0
 public ShoppingCartQuantityProduct(int quantity, ProductPart product) {
     Quantity = quantity;
     Product = product;
     Price = product.Price.Value;
 }
コード例 #36
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="product"></param>
        public void Edit(IProduct product)
        {
            if (product is IPackage)
            {
                Package productParent = null;
                if (!(product is Package))
                {
                    productParent = _Mapper.Map <Package>(product);
                }
                else
                {
                    productParent = (Package)product;
                }

                var parts = productParent.Parts;
                productParent.PartOfProducts = new List <ProductPart>();

                if (parts != null)
                {
                    foreach (var part in parts)
                    {
                        var parProduct = _Current.Where(x => x.Code == part.Code).FirstOrDefault();
                        if (parProduct == null)
                        {
                            part.Id = 0;
                            if (part is IPackage)
                            {
                                if (!(part is Package))
                                {
                                    parProduct = _Mapper.Map <Package>(part);
                                }
                            }
                            else
                            {
                                if (!(part is Product))
                                {
                                    parProduct = _Mapper.Map <Product>(part);
                                }
                            }
                        }
                        ProductPart related = new ProductPart
                        {
                            ParentProduct = productParent,
                            Product       = (IProduct)parProduct
                        };

                        productParent.PartOfProducts.Add(related);
                    }
                }

                base.Edit((Package)productParent);
            }
            else if (product is Product)
            {
                base.Edit((Product)product);
            }
            else if (product is IProduct)
            {
                var par = _Mapper.Map <Product>(product);
                base.Edit(par);
            }
        }
コード例 #37
0
 /// <summary>
 /// Basic delete method
 /// </summary>
 /// <param name="entity"></param>
 public void DeleteProductPart(ProductPart entity)
 {
     DbContext.ProductParts.Attach(entity);
     DbContext.ProductParts.DeleteOnSubmit(entity);
     DbContext.SubmitChanges();
 }
コード例 #38
0
 /// <summary>
 /// Basic inser method
 /// </summary>
 /// <param name="entity"></param>
 public void InsertProductPart(ProductPart entity)
 {
     DbContext.ProductParts.InsertOnSubmit(entity);
     DbContext.SubmitChanges();
 }