예제 #1
0
        private void OnDeletingContent(object sender, DeleteContentEventArgs e)
        {
            Logger.Debug("OnDeletingContent raised.");

            ContentReference deletingContentLink = e.ContentLink;

            if (ContentReference.IsNullOrEmpty(deletingContentLink) ||
                deletingContentLink.ProviderName != ReferenceConverter.CatalogProviderKey ||
                !_contentLoader.TryGet(deletingContentLink, out CatalogContentBase catalogContentBase))
            {
                Logger.Debug("Deleted content is not catalog content.");
                return;
            }

            switch (catalogContentBase)
            {
            case EntryContentBase entryContent:
                ICollection <EntryContentBase> entries = GetEntriesAffected(entryContent, false, true);

                _productExportService.DeleteProducts(entries);
                _productExportService.DeleteProductAssets(entries);
                _productExportService.DeleteProductRecommendations(entries);
                break;

            case NodeContent nodeContent:
                _productExportService.DeleteChildProducts(nodeContent);
                break;
            }
        }
예제 #2
0
        public void EntryDeleted(CatalogContentUpdateEventArgs e)
        {
            Logger.Debug("EntryDeleted raised.");

            IEnumerable <ContentReference> contentLinks = GetContentLinks(e);


            // Variants
            IEnumerable <ContentReference> variantLinks = GetVariantReferences(contentLinks);

            VariationContent[] variants = _contentLoader.GetItems(variantLinks, CultureInfo.InvariantCulture)
                                          .OfType <VariationContent>()
                                          .ToArray();

            foreach (VariationContent variant in variants)
            {
                foreach (var parent in variant.GetParentProducts())
                {
                    var product = _contentLoader.Get <ProductContent>(parent);

                    IEnumerable <ContentReference> variantRefs = _relationRepository
                                                                 .GetChildren <ProductVariation>(product.ContentLink)
                                                                 .Select(r => r.Child);
                    ICollection <VariationContent> productVariants = _contentLoader
                                                                     .GetItems(variantRefs, LanguageSelector.MasterLanguage())
                                                                     .OfType <VariationContent>()
                                                                     .ToArray();

                    var configuration = KachingConfiguration.Instance;
                    if (productVariants.Count == 1 && configuration.ExportSingleVariantAsProduct)
                    {
                        _productExportService.DeleteSingleVariantProduct(variant);
                    }
                    else
                    {
                        // Since variants are not independent datatypes in Ka-ching
                        // a variant change is always a product update and not a delete
                        _productExportService.ExportProduct(product, variant.Code);
                    }
                }
            }

            // Products
            IEnumerable <ContentReference> productLinks = GetProductReferences(contentLinks);

            ProductContent[] products = _contentLoader.GetItems(productLinks, CultureInfo.InvariantCulture)
                                        .OfType <ProductContent>()
                                        .ToArray();

            _productExportService.DeleteProducts(products);
            _productExportService.DeleteProductAssets(products);
            _productExportService.DeleteProductRecommendations(products);
        }