/// <summary>
 /// Gets the paged collection of products in the collection.
 /// </summary>
 /// <param name="value">
 /// The <see cref="ProductCollection"/>.
 /// </param>
 /// <param name="page">
 /// The page.
 /// </param>
 /// <param name="itemsPerPage">
 /// Number of items per page.
 /// </param>
 /// <param name="sortBy">
 /// The sort field.
 /// </param>
 /// <param name="sortDirection">
 /// The sort direction.
 /// </param>
 /// <param name="enableDataModifiers">
 /// A value indicating whether or not to enable data modifiers in the MerchelloHelper
 /// </param>
 /// <returns>
 /// The <see cref="IEnumerable{IProductContent}"/>.
 /// </returns>
 public static PagedCollection<IProductContent> GetProductsPaged(
     this IProductCollection value,
     long page,
     long itemsPerPage,
     string sortBy = "",
     SortDirection sortDirection = SortDirection.Ascending,
     bool enableDataModifiers = true)
 {
     var merchelloHelper = new MerchelloHelper(enableDataModifiers);
     return value.GetProducts(merchelloHelper, page, itemsPerPage, sortBy, sortDirection);
 }
        /// <summary>
        /// Gets the collection of all products in the collection.
        /// </summary>
        /// <param name="value">
        /// The <see cref="ProductCollection"/>.
        /// </param>
        /// <param name="merchelloHelper">
        /// The <see cref="MerchelloHelper"/>.
        /// </param>
        /// <param name="page">
        /// The page.
        /// </param>
        /// <param name="itemsPerPage">
        /// Number of items per page.
        /// </param>
        /// <param name="sortBy">
        /// The sort field.
        /// </param>
        /// <param name="sortDirection">
        /// The sort direction.
        /// </param>
        /// <returns>
        /// The <see cref="IEnumerable{IProductContent}"/>.
        /// </returns>
        internal static PagedCollection<IProductContent> GetProducts(
            this IProductCollection value,
            MerchelloHelper merchelloHelper,
            long page,
            long itemsPerPage,
            string sortBy = "",
            SortDirection sortDirection = SortDirection.Ascending)
        {
            ProductSortField order;
            switch (sortBy.ToLowerInvariant())
            {
                case "price":
                    order = ProductSortField.Price;
                    break;
                case "sku":
                    order = ProductSortField.Sku;
                    break;
                case "name":
                default:
                    order = ProductSortField.Name;
                    break;
            }

            return
                merchelloHelper.ProductContentQuery()
                    .Page(page)
                    .ConstrainBy(value)
                    .ItemsPerPage(itemsPerPage)
                    .OrderBy(order, sortDirection)
                    .Execute();
        }
Beispiel #3
0
        public override void FixtureSetup()
        {
            base.FixtureSetup();

            this._merchello = new MerchelloHelper();

            this._productOptionService = MerchelloContext.Current.Services.ProductOptionService;

            this._productService = MerchelloContext.Current.Services.ProductService;

            this.DbPreTestDataWorker.DeleteAllProducts();
            this.DbPreTestDataWorker.DeleteAllSharedOptions();

            var option = CreateSavedOption();

            _optionKey = option.Key;

            var product1 = CreateSavedProduct();

            this._product1Key = product1.Key;

            var product2 = DbPreTestDataWorker.MakeExistingProduct();
            product2.ProductOptions.Add(new ProductOption("Size"));
            product2.ProductOptions.First(x => x.Name == "Size").Choices.Add(new ProductAttribute("Small", "sm"));
            product2.ProductOptions.First(x => x.Name == "Size").Choices.Add(new ProductAttribute("Medium", "md"));
            product2.ProductOptions.First(x => x.Name == "Size").Choices.Add(new ProductAttribute("Large", "lg"));

            DbPreTestDataWorker.ProductService.Save(product2);

            _product2Key = product2.Key;

            MerchelloContext.Current.Cache.RuntimeCache.ClearAllCache();
        }
Beispiel #4
0
        /// <summary>
        /// Gets the collection of all products in the collection.
        /// </summary>
        /// <param name="value">
        /// The <see cref="ProductCollection"/>.
        /// </param>
        /// <param name="merchelloHelper">
        /// The <see cref="MerchelloHelper"/>.
        /// </param>
        /// <param name="page">
        /// The page.
        /// </param>
        /// <param name="itemsPerPage">
        /// Number of items per page.
        /// </param>
        /// <param name="sortBy">
        /// The sort field.
        /// </param>
        /// <param name="sortDirection">
        /// The sort direction.
        /// </param>
        /// <returns>
        /// The <see cref="IEnumerable{IProductContent}"/>.
        /// </returns>
        internal static PagedCollection <IProductContent> GetProducts(
            this IProductCollection value,
            MerchelloHelper merchelloHelper,
            long page,
            long itemsPerPage,
            string sortBy = "",
            SortDirection sortDirection = SortDirection.Ascending)
        {
            ProductSortField order;

            switch (sortBy.ToLowerInvariant())
            {
            case "price":
                order = ProductSortField.Price;
                break;

            case "sku":
                order = ProductSortField.Sku;
                break;

            case "name":
            default:
                order = ProductSortField.Name;
                break;
            }

            return
                (merchelloHelper.ProductContentQuery()
                 .Page(page)
                 .ConstrainBy(value)
                 .ItemsPerPage(itemsPerPage)
                 .OrderBy(order, sortDirection)
                 .Execute());
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="ExportOrdersReportApiController"/> class.
        /// </summary>
        /// <param name="merchelloContext">
        /// The merchello context.
        /// </param>
        public ExportOrdersReportApiController(IMerchelloContext merchelloContext)
            : base(merchelloContext)
        {
            _invoiceService = merchelloContext.Services.InvoiceService;

            _merchello = new MerchelloHelper(merchelloContext.Services);
        }
Beispiel #6
0
        //[Test]
        public void DailyAuditLogs()
        {
            var list = new List<AuditLogDisplay>();
            var merchello = new MerchelloHelper();
            var invoice = merchello.Query.Invoice.GetByKey(new Guid("85F6F194-2F74-4CD5-9CE8-98723B50E719"));
            var _auditLogService = MerchelloContext.Current.Services.AuditLogService;

            if (invoice != null)
            {
                Console.WriteLine("Got an invoice");
                var invoiceLogs = _auditLogService.GetAuditLogsByEntityKey(invoice.Key).Select(x => x.ToAuditLogDisplay()).ToArray();

                if (invoiceLogs.Any()) list.AddRange(invoiceLogs);

                foreach (var orderLogs in invoice.Orders.Select(order => _auditLogService.GetAuditLogsByEntityKey(order.Key).Select(x => x.ToAuditLogDisplay()).ToArray()).Where(orderLogs => orderLogs.Any()))
                {
                    list.AddRange(orderLogs);
                }

                var paymentKeys = MerchelloContext.Current.Services.PaymentService.GetPaymentsByInvoiceKey(invoice.Key).Select(x => x.Key);

                foreach (var paymentLogs in paymentKeys.Select(x => _auditLogService.GetAuditLogsByEntityKey(x).Select(log => log.ToAuditLogDisplay())).ToArray())
                {
                    list.AddRange(paymentLogs);
                }
            }
            Console.WriteLine(JsonConvert.SerializeObject(list.ToSalesHistoryDisplay()));
        }
        public ActionResult AddToBasket(AddToBasket model)
        {
            // Disable VAT in initial lookup so we don't double tax
            var merchello = new MerchelloHelper(false);

            // we want to include VAT
            Basket.EnableDataModifiers = true;

            var product = merchello.Query.Product.GetByKey(model.ProductKey);

            if (model.OptionChoice != Guid.Empty)
            {
                var extendedData = new ExtendedDataCollection();
                var variant = product.GetProductVariantDisplayWithAttributes(new[] { model.OptionChoice });
                //// serialize the attributes here as they are need in the design
                extendedData.SetValue(Constants.ExtendedDataKeys.BasketItemAttributes, JsonConvert.SerializeObject(variant.Attributes));
                Basket.AddItem(variant, variant.Name, 1, extendedData);
            }
            else
            {
                Basket.AddItem(product, product.Name, 1);
            }

            Basket.Save();

            if (Request.IsAjaxRequest())
            {
                // this would be the partial for the pop window
                return Content("Form submitted");
            }

            return RedirectToUmbracoPage(ContentResolver.Instance.GetBasketContent());
        }
Beispiel #8
0
        //[Test]
        public void InvoiceJsonResults()
        {
            var merchello = new MerchelloHelper();

            var invoices = merchello.Query.Invoice.Search(1, 10).Items;

            Console.WriteLine(JsonConvert.SerializeObject(invoices));
        }
Beispiel #9
0
        public void Can_RetrieveProductOptions_From_ProductInIndex()
        {
            //// Arrange

            var merchello = new MerchelloHelper(MerchelloContext.Current, false);

            var productService = this.PreTestDataWorker.ProductService;

            var product = MockProductDataMaker.MockProductCollectionForInserting(1).First();
            product.ProductOptions.Add(new ProductOption("Color"));
            product.ProductOptions.First(x => x.Name == "Color").Choices.Add(new ProductAttribute("Blue", "Blue"));
            product.ProductOptions.First(x => x.Name == "Color").Choices.Add(new ProductAttribute("Red", "Red"));
            product.ProductOptions.First(x => x.Name == "Color").Choices.Add(new ProductAttribute("Green", "Green"));
            product.ProductOptions.Add(new ProductOption("Size"));
            product.ProductOptions.First(x => x.Name == "Size").Choices.Add(new ProductAttribute("Small", "Sm"));
            product.ProductOptions.First(x => x.Name == "Size").Choices.Add(new ProductAttribute("Medium", "Med"));
            product.ProductOptions.First(x => x.Name == "Size").Choices.Add(new ProductAttribute("Large", "Lg"));
            product.ProductOptions.First(x => x.Name == "Size").Choices.Add(new ProductAttribute("X-Large", "XL"));
            product.Height = 11M;
            product.Width = 11M;
            product.Length = 11M;
            product.CostOfGoods = 15M;
            product.OnSale = true;
            product.SalePrice = 18M;
            product.TrackInventory = true;
            product.AddToCatalogInventory(this._warehouse.WarehouseCatalogs.First());
            productService.Save(product);

            foreach (var variant in product.ProductVariants)
            {
                variant.CatalogInventories.First().Count = 1;
            }
            productService.Save(product);

            foreach (var p in product.ProductVariants)
            {
                Assert.AreEqual(1, p.TotalInventoryCount, "Preindexed product variant count");
            }

            this._provider.AddProductToIndex(product);

            //// Act
            var productDisplay = merchello.Query.Product.GetByKey(product.Key);

            //// Assert
            Assert.NotNull(productDisplay);
            Assert.IsTrue(productDisplay.ProductOptions.Any());

            //http://issues.merchello.com/youtrack/issue/M-604
            foreach (var variant in productDisplay.ProductVariants)
            {
                Assert.AreEqual(1, variant.TotalInventoryCount);
            }
            Assert.AreEqual(12, productDisplay.TotalInventoryCount, "Total inventory count failed");
        }
        public void Can_GetAllProducts_From_Index()
        {
            //// Arrange
            var merchello = new MerchelloHelper();

            //// Act
            var products = merchello.AllProducts();

            //// Assert
            Assert.IsTrue(products.Any());
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="BazaarSiteApiController"/> class.
        /// </summary>
        /// <param name="merchelloContext">
        /// The merchello context.
        /// </param>
        public BazaarSiteApiController(IMerchelloContext merchelloContext)
        {
            Mandate.ParameterNotNull(merchelloContext, "merchelloContext");

            _merchelloContext = merchelloContext;

            _storeSettingService = _merchelloContext.Services.StoreSettingService;

            _merchello = new MerchelloHelper(_merchelloContext.Services);

            this.Initialize();
        }
Beispiel #12
0
        /// <summary>
        /// Gets the paged collection of products in the collection.
        /// </summary>
        /// <param name="value">
        /// The <see cref="ProductCollection"/>.
        /// </param>
        /// <param name="page">
        /// The page.
        /// </param>
        /// <param name="itemsPerPage">
        /// Number of items per page.
        /// </param>
        /// <param name="sortBy">
        /// The sort field.
        /// </param>
        /// <param name="sortDirection">
        /// The sort direction.
        /// </param>
        /// <param name="enableDataModifiers">
        /// A value indicating whether or not to enable data modifiers in the MerchelloHelper
        /// </param>
        /// <returns>
        /// The <see cref="IEnumerable{IProductContent}"/>.
        /// </returns>
        public static PagedCollection <IProductContent> GetProductsPaged(
            this IProductCollection value,
            long page,
            long itemsPerPage,
            string sortBy = "",
            SortDirection sortDirection = SortDirection.Ascending,
            bool enableDataModifiers    = true)
        {
            var merchelloHelper = new MerchelloHelper(enableDataModifiers);

            return(value.GetProducts(merchelloHelper, page, itemsPerPage, sortBy, sortDirection));
        }
        /// <summary>
        /// Maps <see cref="IItemCacheLineItem"/> to <see cref="BasketItem"/>.
        /// </summary>
        /// <param name="item">
        /// The item.
        /// </param>
        /// <param name="merchello">
        /// The <see cref="MerchelloHelper"/>.
        /// </param>
        /// <returns>
        /// The <see cref="BasketItem"/>.
        /// </returns>
        public static BasketItem AsBasketItem(this ILineItem item, MerchelloHelper merchello)
        {
            var product = merchello.TypedProductContent(item.ExtendedData.GetProductKey());

            var productItem = item.AsProductLineItem(merchello);

            var basketItem = AutoMapper.Mapper.Map<BasketItem>(productItem);
            basketItem.ProductKey = product.Key;
            basketItem.ProductUrl = product.Url;

            return basketItem;
        }
        public void Can_Get_Product_From_Helper_With_Tax_Included()
        {
            //// Arrange
            var merchello = new MerchelloHelper();

            //// Act
            var product = merchello.Query.Product.GetByKey(_productKey);

            //// Assert
            Assert.NotNull(product);
            Assert.AreEqual(20, product.Price);
            Assert.AreEqual(15, product.SalePrice);
        }
        public ActionResult AddToBasket(AddItemModel model)
        {
            // This is an example of using the ExtendedDataCollection to add some custom functionality.
            // In this case, we are creating a direct reference to the content (Product Detail Page) so
            // that we can provide a link, thumbnail and description in the cart per this design.  In other
            // designs, there may not be thumbnails or descriptions and the link could be to a completely
            // different website.
            var extendedData = new ExtendedDataCollection();
            extendedData.SetValue("umbracoContentId", model.ContentId.ToString(CultureInfo.InvariantCulture));

            // NEW IN 1.9.1
            // We've added some data modifiers that can handle such things as including taxes in product
            // pricing.  The data modifiers can either get executed when the item is added to the basket or
            // as a result from a MerchelloHelper query - you just don't want them to execute twice.

            // Calls directly to the ProductService are not modified
            // var product = this.MerchelloServices.ProductService.GetByKey(model.Product.Key);

            // Calls to using the MerchelloHelper WILL be modified
            // var merchello = new MerchelloHelper();
            //
            // if you want to do this you should tell the basket not to modify the data again when adding the item
            //this.Basket.EnableDataModifiers = false;

            // In this case we want to get the product without any data modification
            var merchello = new MerchelloHelper(false);

            var product = merchello.Query.Product.GetByKey(model.Product.Key);

            // In the event the product has options we want to add the "variant" to the basket.
            // -- If a product that has variants is defined, the FIRST variant will be added to the cart.
            // -- This was done so that we did not have to throw an error since the Master variant is no
            // -- longer valid for sale.
            if (model.OptionChoices != null && model.OptionChoices.Any())
            {
                // NEW in 1.9.1
                // ProductDisplay and ProductVariantDisplay classes can be added directly to the Basket
                // so you don't have to query the service.
                var variant = product.GetProductVariantDisplayWithAttributes(model.OptionChoices);
                this.Basket.AddItem(variant, variant.Name, 1, extendedData);
            }
            else
            {
                this.Basket.AddItem(product, product.Name, 1, extendedData);
            }

            this.Basket.Save();

            return this.RedirectToUmbracoPage(model.BasketPageId);
        }
Beispiel #16
0
        public IEnumerable<ProductVariantDisplay> FilterOptionsBySelectedChoices(Guid productKey, string optionChoices)
        {
            var merchello = new MerchelloHelper();

            var optionsArray = string.IsNullOrEmpty(optionChoices) ? new string[] { } : optionChoices.Split(',');
            var guidOptionChoices = new List<Guid>();
            foreach (var option in optionsArray)
            {
                if (!String.IsNullOrEmpty(option))
                {
                    guidOptionChoices.Add(new Guid(option));
                }
            }

            var variants = merchello.GetValidProductVariants(productKey, guidOptionChoices.ToArray());
            return variants;
        }
        /// <summary>
        /// The as product line item.
        /// </summary>
        /// <param name="item">
        /// The item.
        /// </param>
        /// <param name="merchello">
        /// The merchello.
        /// </param>
        /// <returns>
        /// The <see cref="ProductLineItem"/>.
        /// </returns>
        public static ProductLineItem AsProductLineItem(this ILineItem item, MerchelloHelper merchello)
        {
            if (!item.ExtendedData.ContainsProductKey()) return null;
            var product = merchello.TypedProductContent(item.ExtendedData.GetProductKey());
            if (product == null) return null;

            var images = product.GetPropertyValue<IEnumerable<IPublishedContent>>("images").ToArray();

            return new ProductLineItem()
            {
                Key = item.Key,
                FormattedUnitPrice = StoreHelper.FormatCurrency(item.Price),
                FormattedPrice = StoreHelper.FormatCurrency(item.TotalPrice),
                Image = images.Any() ? images.First().GetCropUrl(50, 50) : string.Empty,
                Name = item.Name,
                Quantity = item.Quantity
            };
        }
        public void Can_RetrieveProductOptions_From_ProductInIndex()
        {
            //// Arrange

            var merchello = new MerchelloHelper();

            var productVariantService = PreTestDataWorker.ProductVariantService;
            var productService = PreTestDataWorker.ProductService;

            var product = MockProductDataMaker.MockProductCollectionForInserting(1).First();
            product.ProductOptions.Add(new ProductOption("Color"));
            product.ProductOptions.First(x => x.Name == "Color").Choices.Add(new ProductAttribute("Blue", "Blue"));
            product.ProductOptions.First(x => x.Name == "Color").Choices.Add(new ProductAttribute("Red", "Red"));
            product.ProductOptions.First(x => x.Name == "Color").Choices.Add(new ProductAttribute("Green", "Green"));
            product.ProductOptions.Add(new ProductOption("Size"));
            product.ProductOptions.First(x => x.Name == "Size").Choices.Add(new ProductAttribute("Small", "Sm"));
            product.ProductOptions.First(x => x.Name == "Size").Choices.Add(new ProductAttribute("Medium", "Med"));
            product.ProductOptions.First(x => x.Name == "Size").Choices.Add(new ProductAttribute("Large", "Lg"));
            product.ProductOptions.First(x => x.Name == "Size").Choices.Add(new ProductAttribute("X-Large", "XL"));
            product.Height = 11M;
            product.Width = 11M;
            product.Length = 11M;
            product.CostOfGoods = 15M;
            product.OnSale = true;
            product.SalePrice = 18M;
            productService.Save(product);

            var attributes = new ProductAttributeCollection()
            {
                product.ProductOptions.First(x => x.Name == "Color").Choices.First(x => x.Sku == "Blue" ),
                product.ProductOptions.First(x => x.Name == "Size").Choices.First(x => x.Sku == "XL")
            };

            productVariantService.CreateProductVariantWithKey(product, attributes);

            _provider.AddProductToIndex(product);

            //// Act
            var productDisplay = merchello.Product(product.Key);

            //// Assert
            Assert.NotNull(productDisplay);
            Assert.IsTrue(productDisplay.ProductOptions.Any());
        }
Beispiel #19
0
        public override void FixtureSetup()
        {
            base.FixtureSetup();

            var invoices = ((InvoiceService)MerchelloContext.Current.Services.InvoiceService).GetAll();
            MerchelloContext.Current.Services.InvoiceService.Delete(invoices);

            // add 60 invoices starting 60 days back
            var start = DateTime.Today.AddDays(-30);
            var end = DateTime.Today;

            while (start != end)
            {
                var inv = MockInvoiceDataMaker.GetMockInvoiceForTaxation();
                inv.InvoiceDate = start;
                MerchelloContext.Current.Services.InvoiceService.Save(inv);
                start = start.AddDays(1);
            }

            _merchello = new MerchelloHelper(MerchelloContext.Current, false);
        }
Beispiel #20
0
        public void Can_Retrieve_Invoices_By_Customer_From_The_Index()
        {
            //// Arrange

            var customer = PreTestDataWorker.CustomerService.CreateCustomerWithKey(
                "rusty",
                "firstName",
                "lastName",
                "*****@*****.**");

            var invoice1 = MockInvoiceDataMaker.InvoiceForInserting(_address, 300);

            invoice1.Items.Add(new InvoiceLineItem(LineItemType.Product, "test", "test", 1, 100));
            invoice1.Items.Add(new InvoiceLineItem(LineItemType.Product, "test2", "test2", 2, 100));
            ((Invoice)invoice1).CustomerKey = customer.Key;

            var invoice2 = MockInvoiceDataMaker.InvoiceForInserting(_address, 100);

            invoice2.Items.Add(new InvoiceLineItem(LineItemType.Product, "test", "test", 1, 100));
            ((Invoice)invoice2).CustomerKey = customer.Key;

            var invoice3 = MockInvoiceDataMaker.InvoiceForInserting(_address, 300);

            invoice3.Items.Add(new InvoiceLineItem(LineItemType.Product, "test2", "test2", 3, 100));
            ((Invoice)invoice3).CustomerKey = customer.Key;

            PreTestDataWorker.InvoiceService.Save(invoice1);
            PreTestDataWorker.InvoiceService.Save(invoice2);
            PreTestDataWorker.InvoiceService.Save(invoice3);

            //// Act
            var merchello = new Merchello.Web.MerchelloHelper();

            var invoices = merchello.Query.Invoice.GetByCustomerKey(customer.Key);

            //// Assert
            Assert.NotNull(invoices, "invoices was null");
            Assert.IsTrue(invoices.Any());
            Assert.AreEqual(3, invoices.Count());
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="BazaarAccountHistoryController"/> class.
 /// </summary>
 public BazaarAccountHistoryController()
 {
     _merchello = new MerchelloHelper(MerchelloServices);
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="SalesOverTimeReportApiController"/> class.
 /// </summary>
 /// <param name="merchelloContext">
 /// The merchello context.
 /// </param>
 public SalesOverTimeReportApiController(IMerchelloContext merchelloContext)
     : base(merchelloContext)
 {
     _storeSettingService = MerchelloContext.Services.StoreSettingService as StoreSettingService;
     _merchello = new MerchelloHelper(merchelloContext.Services);
 }
Beispiel #23
0
        /// <summary>
        /// Initializes a new instance of the <see cref="SalesByItemVisitor"/> class.
        /// </summary>
        /// <param name="merchello">
        /// The merchello.
        /// </param>
        /// <exception cref="NullReferenceException">
        /// Throws an exception if the MerchelloHelper is null
        /// </exception>
        public SalesByItemVisitor(MerchelloHelper merchello)
        {
            if (merchello == null) throw  new NullReferenceException("The Merchello helper cannot be null");

            _merchello = merchello;
        }
 /// <summary>
 /// Get the list of <see cref="IProductContent"/> by a collection of keys (ids).
 /// </summary>
 /// <param name="merchello">
 /// The <see cref="MerchelloHelper"/>.
 /// </param>
 /// <param name="keys">
 /// The keys.
 /// </param>
 /// <returns>
 /// The <see cref="IEnumerable{IProductContent}"/>.
 /// </returns>
 public static IEnumerable <IProductContent> TypeProductContent(this MerchelloHelper merchello, IEnumerable <Guid> keys) // productKeys not productVariantKeys
 {
     return(keys.Select(merchello.TypedProductContent));
 }
 /// <summary>
 /// Gets a <see cref="IProductContent"/> by it's key.
 /// </summary>
 /// <param name="merchello">
 /// The <see cref="MerchelloHelper"/>.
 /// </param>
 /// <param name="key">
 /// The key (id) of the product.
 /// </param>
 /// <returns>
 /// The <see cref="IProductContent"/>.
 /// </returns>
 public static IProductContent TypedProductContent(this MerchelloHelper merchello, Guid key)
 {
     return(merchello.Query.Product.TypedProductContent(key));
 }
 /// <summary>
 /// Get the list of <see cref="IProductContent"/> associated with the static product collection with key (id).
 /// </summary>
 /// <param name="merchello">
 /// The <see cref="MerchelloHelper"/>.
 /// </param>
 /// <param name="collectionKey">
 /// The key (id) of the collection.
 /// </param>
 /// <returns>
 /// The <see cref="IEnumerable{IProductContent}"/>.
 /// </returns>
 public static IEnumerable <IProductContent> TypedProductContentFromCollection(this MerchelloHelper merchello, Guid collectionKey)
 {
     return(merchello.Query.Product.TypedProductContentFromCollection(collectionKey));
 }
Beispiel #27
0
        private void ProductServiceDeleted(IProductService sender, DeleteEventArgs <IProduct> e)
        {
            var merchello = new MerchelloHelper();

            ((ProductFilterGroupQuery)merchello.Filters.Product).ClearFilterTreeCache();
        }
        public override void FixtureSetup()
        {
            base.FixtureSetup();
            DbPreTestDataWorker.DeleteAllProducts();

            var defaultWarehouse = DbPreTestDataWorker.WarehouseService.GetDefaultWarehouse();

            _merchello = new MerchelloHelper(MerchelloContext.Current, false);

            var productService = MerchelloContext.Current.Services.ProductService;
            var entityCollectionService = MerchelloContext.Current.Services.EntityCollectionService;

            _collection = entityCollectionService.CreateEntityCollectionWithKey(
                EntityType.Product,
                Constants.ProviderKeys.EntityCollection.StaticProductCollectionProviderKey,
                "Test Merchello Helper Collection");

            var product = MockProductDataMaker.MockProductCollectionForInserting(1).First();
            product.ProductOptions.Add(new ProductOption("Color"));
            product.ProductOptions.First(x => x.Name == "Color").Choices.Add(new ProductAttribute("Blue", "Blue"));
            product.ProductOptions.First(x => x.Name == "Color").Choices.Add(new ProductAttribute("Red", "Red"));
            product.ProductOptions.First(x => x.Name == "Color").Choices.Add(new ProductAttribute("Green", "Green"));
            product.ProductOptions.Add(new ProductOption("Size"));
            product.ProductOptions.First(x => x.Name == "Size").Choices.Add(new ProductAttribute("Small", "Sm"));
            product.ProductOptions.First(x => x.Name == "Size").Choices.Add(new ProductAttribute("Medium", "Med"));
            product.ProductOptions.First(x => x.Name == "Size").Choices.Add(new ProductAttribute("Large", "Lg"));
            product.ProductOptions.First(x => x.Name == "Size").Choices.Add(new ProductAttribute("X-Large", "XL"));
            product.Height = 11M;
            product.Price = 30M;
            product.Width = 11M;
            product.Weight = 2M;
            product.Length = 11M;
            product.Barcode = "barcode1";
            product.Manufacturer = "Manufacturer1";
            product.CostOfGoods = 15M;
            product.OnSale = true;
            product.SalePrice = 25M;
            productService.Save(product);

            product.AddToCollection(_collection);

            var product2 = MockProductDataMaker.MockProductCollectionForInserting(1).First();
            product2.ProductOptions.Add(new ProductOption("Color"));
            product2.ProductOptions.First(x => x.Name == "Color").Choices.Add(new ProductAttribute("Purple", "purple"));
            product2.ProductOptions.Add(new ProductOption("Size"));
            product2.ProductOptions.First(x => x.Name == "Size").Choices.Add(new ProductAttribute("Small", "Sm"));
            product2.Price = 40M;
            product2.Height = 11M;
            product2.Width = 11M;
            product2.Length = 11M;
            product2.Weight = 1M;
            product2.CostOfGoods = 15M;
            product2.Barcode = "barcode2";
            product2.Manufacturer = "Manufacturer2";
            product2.OnSale = false;
            product2.SalePrice = 35M;
            product2.AddToCatalogInventory(defaultWarehouse.DefaultCatalog());
            productService.Save(product2);
            product2.CatalogInventories.First().Count = 10;
            productService.Save(product2);

            product2.AddToCollection(_collection);

            var product3 = MockProductDataMaker.MockProductCollectionForInserting(1).First();
            product3.ProductOptions.Add(new ProductOption("Color"));
            product3.ProductOptions.First(x => x.Name == "Color").Choices.Add(new ProductAttribute("Blue", "Blue"));
            product3.ProductOptions.First(x => x.Name == "Color").Choices.Add(new ProductAttribute("Red", "Red"));
            product3.ProductOptions.First(x => x.Name == "Color").Choices.Add(new ProductAttribute("Green", "Green"));
            product3.Price = 20M;
            product3.Height = 11M;
            product3.Width = 11M;
            product3.Length = 11M;
            product3.Weight = 2M;
            product3.CostOfGoods = 15M;
            product3.Barcode = "barcode3";
            product3.Manufacturer = "Manufacturer2";
            product3.OnSale = false;
            product3.SalePrice = 20M;
            product3.AddToCatalogInventory(defaultWarehouse.DefaultCatalog());
            productService.Save(product3);
            product3.CatalogInventories.First().Count = 10;
            productService.Save(product3);

            var product4 = MockProductDataMaker.MockProductCollectionForInserting(1).First();
            product4.ProductOptions.Add(new ProductOption("Size"));
            product4.ProductOptions.First(x => x.Name == "Size").Choices.Add(new ProductAttribute("Small", "Sm"));
            product4.ProductOptions.Add(new ProductOption("Material"));
            product4.ProductOptions.First(x => x.Name == "Material").Choices.Add(new ProductAttribute("Wood", "wood"));
            product4.ProductOptions.First(x => x.Name == "Material").Choices.Add(new ProductAttribute("Plastic", "plastic"));
            product4.Price = 21M;
            product4.Height = 11M;
            product4.Width = 11M;
            product4.Length = 11M;
            product4.Weight = 3M;
            product4.CostOfGoods = 15M;
            product4.Barcode = "barcode4";
            product4.Manufacturer = "Manufacturer3";
            product4.OnSale = true;
            product4.SalePrice = 18M;
            product4.AddToCatalogInventory(defaultWarehouse.DefaultCatalog());
            productService.Save(product4);
            product4.CatalogInventories.First().Count = 10;
            productService.Save(product4);

            product4.AddToCollection(_collection);
        }
 private void ProductServiceDeleted(IProductService sender, DeleteEventArgs<IProduct> e)
 {
     var merchello = new MerchelloHelper();
     ((ProductFilterGroupQuery)merchello.Filters.Product).ClearFilterTreeCache();
 }   
 /// <summary>
 /// Gets a <see cref="IProductContent"/> by it's SKU.
 /// </summary>
 /// <param name="merchello">
 /// The <see cref="MerchelloHelper"/>.
 /// </param>
 /// <param name="sku">
 /// The SKU.
 /// </param>
 /// <returns>
 /// The <see cref="IProductContent"/>.
 /// </returns>
 public static IProductContent TypeProductContentBySku(this MerchelloHelper merchello, string sku)
 {
     return(merchello.Query.Product.TypedProductContentBySku(sku));
 }
 /// <summary>
 /// Gets a <see cref="IProductContent"/> by it's slug.
 /// </summary>
 /// <param name="merchello">
 /// The <see cref="MerchelloHelper"/>.
 /// </param>
 /// <param name="slug">
 /// The slug.
 /// </param>
 /// <returns>
 /// The <see cref="IProductContent"/>.
 /// </returns>
 public static IProductContent TypedProductContentBySlug(this MerchelloHelper merchello, string slug)
 {
     return(merchello.Query.Product.TypedProductContentBySlug(slug));
 }
        public void Can_Retrieve_Invoices_By_Customer_From_The_Index()
        {
            //// Arrange

            var customer = PreTestDataWorker.CustomerService.CreateCustomerWithKey(
                "rusty",
                "firstName",
                "lastName",
                "*****@*****.**");

            var invoice1 = MockInvoiceDataMaker.InvoiceForInserting(_address, 300);
            invoice1.Items.Add(new InvoiceLineItem(LineItemType.Product, "test", "test", 1, 100));
            invoice1.Items.Add(new InvoiceLineItem(LineItemType.Product, "test2", "test2", 2, 100));
            ((Invoice)invoice1).CustomerKey = customer.Key;

            var invoice2 = MockInvoiceDataMaker.InvoiceForInserting(_address, 100);
            invoice2.Items.Add(new InvoiceLineItem(LineItemType.Product, "test", "test", 1, 100));
            ((Invoice)invoice2).CustomerKey = customer.Key;

            var invoice3 = MockInvoiceDataMaker.InvoiceForInserting(_address, 300);
            invoice3.Items.Add(new InvoiceLineItem(LineItemType.Product, "test2", "test2", 3, 100));
            ((Invoice)invoice3).CustomerKey = customer.Key;

            PreTestDataWorker.InvoiceService.Save(invoice1);
            PreTestDataWorker.InvoiceService.Save(invoice2);
            PreTestDataWorker.InvoiceService.Save(invoice3);

            //// Act
            var merchello = new MerchelloHelper();

            var invoices = merchello.InvoicesByCustomer(customer.Key);

            //// Assert
            Assert.NotNull(invoices, "invoices was null");
            Assert.IsTrue(invoices.Any());
            Assert.AreEqual(3, invoices.Count());
        }
        /// <summary>
        /// Get the list of <see cref="IProductContent"/> associated with the static product collection with key (id) for a give page of results.
        /// </summary>
        /// <param name="merchello">
        /// The <see cref="MerchelloHelper"/>.
        /// </param>
        /// <param name="collectionKey">
        /// The collection key.
        /// </param>
        /// <param name="page">
        /// The current page.
        /// </param>
        /// <param name="itemsPerPage">
        /// The items Per Page.
        /// </param>
        /// <param name="sortBy">
        /// The sort field (valid values are "sku", "name", "price").
        /// </param>
        /// <param name="sortDirection">
        /// The sort direction.
        /// </param>
        /// <returns>
        /// The <see cref="IEnumerable{IProductContent}"/>.
        /// </returns>
        public static IEnumerable <IProductContent> TypedProductContentFromCollection(this MerchelloHelper merchello, Guid collectionKey, long page, long itemsPerPage, string sortBy = "", SortDirection sortDirection = SortDirection.Ascending)
        {
            if (page <= 0)
            {
                page = 1;
            }

            return(merchello.Query.Product.TypedProductContentFromCollection(collectionKey, page, itemsPerPage, sortBy, sortDirection));
        }
Beispiel #34
0
        private void EntityCollectionDeleted(IEntityCollectionService sender, DeleteEventArgs <Core.Models.Interfaces.IEntityCollection> e)
        {
            var merchello = new MerchelloHelper();

            ((ProductFilterGroupQuery)merchello.Filters.Product).ClearFilterTreeCache();
        }
 /// <summary>
 /// Gets the <see cref="IProductContentQueryBuilder"/>.
 /// </summary>
 /// <param name="merchello">
 /// The <see cref="MerchelloHelper"/>.
 /// </param>
 /// <returns>
 /// The <see cref="IProductContentQueryBuilder"/>.
 /// </returns>
 public static IProductContentQueryBuilder ProductContentQuery(this MerchelloHelper merchello)
 {
     return(new ProductContentQueryBuilder(merchello.Query.Product));
 }
Beispiel #36
0
        private void ProductServiceAddedToCollection(object sender, EventArgs e)
        {
            var merchello = new MerchelloHelper();

            ((ProductFilterGroupQuery)merchello.Filters.Product).ClearFilterTreeCache();
        }
Beispiel #37
0
        public void Can_Retrieve_A_Product_From_The_Index_By_Sku()
        {
            //// Arrange

            var merchello = new MerchelloHelper(MerchelloContext.Current, false);

            var productService = this.PreTestDataWorker.ProductService;

            var product = MockProductDataMaker.MockProductCollectionForInserting(1).First();
            product.Height = 11M;
            product.Width = 11M;
            product.Length = 11M;
            product.CostOfGoods = 15M;
            product.OnSale = true;
            product.SalePrice = 18M;
            productService.Save(product);

            this._provider.AddProductToIndex(product);

            //// Act
            var productDisplay = merchello.Query.Product.GetBySku(product.Sku);

            //// Assert
            Assert.NotNull(productDisplay);
            Assert.AreEqual(product.Key, productDisplay.Key);
        }
        public override void FixtureSetup()
        {
            base.FixtureSetup();

            DbPreTestDataWorker.DeleteAllEntityCollections();

            _service = MerchelloContext.Current.Services.EntityCollectionService;

            this._query = ProxyQueryManager.Current.Instance<ProductCollectionTreeQuery>();

            var providerKey = Constants.ProviderKeys.EntityCollection.StaticProductCollectionProviderKey;

            root1 = _service.CreateEntityCollectionWithKey(EntityType.Product, providerKey, "root1", false);

            root2 = _service.CreateEntityCollectionWithKey(EntityType.Product, providerKey, "root2", false);

            a = _service.CreateEntityCollection(EntityType.Product, providerKey, "a", false);
            a.ParentKey = root1.Key;

            b = _service.CreateEntityCollection(EntityType.Product, providerKey, "b", false);
            b.ParentKey = root1.Key;

            c = _service.CreateEntityCollection(EntityType.Product, providerKey, "c", false);
            c.ParentKey = root1.Key;

            _service.Save(new [] { a, b, c });

            a1 = _service.CreateEntityCollection(EntityType.Product, providerKey, "a1", false);
            a1.ParentKey = a.Key;

            a2 = _service.CreateEntityCollection(EntityType.Product, providerKey, "a2", false);
            a2.ParentKey = a.Key;

            _service.Save(new[] { a1, a2 });

            a1a = _service.CreateEntityCollection(EntityType.Product, providerKey, "a1a", false);
            a1a.ParentKey = a1.Key;

            a1b = _service.CreateEntityCollection(EntityType.Product, providerKey, "a1b", false);
            a1b.ParentKey = a1.Key;

            _service.Save(new[] { a1a, a1b });

            c1 = _service.CreateEntityCollection(EntityType.Product, providerKey, "c1", false);
            c1.ParentKey = c.Key;

            c2 = _service.CreateEntityCollection(EntityType.Product, providerKey, "c2", false);
            c2.ParentKey = c.Key;

            _service.Save(new[] { c1, c2 });

            c2a = _service.CreateEntityCollection(EntityType.Product, providerKey, "c2a", false);
            c2a.ParentKey = c2.Key;

            _service.Save(c2a);

            _merchello = new MerchelloHelper();
        }
 private void EntityCollectionDeleted(IEntityCollectionService sender, DeleteEventArgs<Core.Models.Interfaces.IEntityCollection> e)
 {
     var merchello = new MerchelloHelper();
     ((ProductFilterGroupQuery)merchello.Filters.Product).ClearFilterTreeCache();
 }
Beispiel #40
0
        public void Can_Retrieve_A_ProductVariant_From_The_Index()
        {
            //// Arrange
            var merchello = new MerchelloHelper(MerchelloContext.Current, false);

            var productService = this.PreTestDataWorker.ProductService;

            var product = MockProductDataMaker.MockProductCollectionForInserting(1).First();
            product.ProductOptions.Add(new ProductOption("Color"));
            product.ProductOptions.First(x => x.Name == "Color").Choices.Add(new ProductAttribute("Blue", "Blue"));
            product.ProductOptions.First(x => x.Name == "Color").Choices.Add(new ProductAttribute("Red", "Red"));
            product.ProductOptions.First(x => x.Name == "Color").Choices.Add(new ProductAttribute("Green", "Green"));
            product.ProductOptions.Add(new ProductOption("Size"));
            product.ProductOptions.First(x => x.Name == "Size").Choices.Add(new ProductAttribute("Small", "Sm"));
            product.ProductOptions.First(x => x.Name == "Size").Choices.Add(new ProductAttribute("Medium", "Med"));
            product.ProductOptions.First(x => x.Name == "Size").Choices.Add(new ProductAttribute("Large", "Lg"));
            product.ProductOptions.First(x => x.Name == "Size").Choices.Add(new ProductAttribute("X-Large", "XL"));
            product.Height = 11M;
            product.Width = 11M;
            product.Length = 11M;
            product.CostOfGoods = 15M;
            product.OnSale = true;
            product.SalePrice = 18M;
            productService.Save(product);
            this._provider.AddProductToIndex(product);

            Assert.IsTrue(product.ProductVariants.Any());
            var variant = product.ProductVariants.First();

            //// Act
            var productVariantDisplay = merchello.Query.Product.GetProductVariantBySku(variant.Sku);

            //// Assert
            Assert.NotNull(productVariantDisplay);
            Assert.AreEqual(variant.Key, productVariantDisplay.Key);
        }
 private void ProductServiceAddedToCollection(object sender, EventArgs e)
 {
     var merchello = new MerchelloHelper();
     ((ProductFilterGroupQuery)merchello.Filters.Product).ClearFilterTreeCache();
 }
Beispiel #42
0
        /// <summary>
        /// Gets the list of recently viewed items.
        /// </summary>
        /// <param name="context">
        /// The context.
        /// </param>
        /// <param name="siteAlias">
        /// The site alias.
        /// </param>
        /// <returns>
        /// The <see>
        ///         <cref>IEnumerable</cref>
        ///     </see>
        ///     .
        /// </returns>
        internal static IEnumerable<ProductBoxModel> GetRecentlyViewedProducts(this ICustomerContext context, string siteAlias = "Bazaar")
        {
            var keys = context.DeserializeRecentlyViewed().Keys;

            // Get the Merchello helper
            var merchelloHelper = new MerchelloHelper();

            // Get the products as IProductContent
            var listOfIProductContent = keys.Select(
                                            x =>
                                            merchelloHelper.TypedProductContent(x))
                                                .Reverse();

            return BazaarContentHelper.GetProductBoxModels(listOfIProductContent);
        }
Beispiel #43
0
        //[Test]
        public void OrderJsonResults()
        {
            var merchello = new MerchelloHelper();
            var notFulfilled = Core.Constants.DefaultKeys.OrderStatus.NotFulfilled;
            Console.WriteLine(notFulfilled);

            var orders = merchello.Query.Order.SearchByOrderStatus(
                Core.Constants.DefaultKeys.OrderStatus.NotFulfilled,
                1,
                10).Items;

            Console.Write(JsonConvert.SerializeObject(orders));
        }