Beispiel #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="InvoiceApiController"/> class.
        /// </summary>
        /// <param name="merchelloContext">
        /// The merchello context.
        /// </param>
        public InvoiceApiController(IMerchelloContext merchelloContext)
            : base(merchelloContext)
        {
            _invoiceService = merchelloContext.Services.InvoiceService;

            _merchello = new MerchelloHelper(merchelloContext.Services);
        }
Beispiel #2
0
        /// <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
            });
        }
Beispiel #3
0
        /// <summary>
        /// The default controller method
        /// </summary>
        /// <param name="model">
        /// The default <see cref="RenderModel"/>
        /// </param>
        /// <returns>
        /// The <see cref="ActionResult"/> to render the product page template view
        /// </returns>
        public override ActionResult Index(RenderModel model)
        {
            var productModel = BuildModel <ProductViewModel>();

            productModel.Thumbnail = productModel.Content.GetSafeImage(Umbraco, "images");
            productModel.Images    = productModel.Content.GetSafeImages(Umbraco, "images", null);

            var merchello = new MerchelloHelper();

            var product = merchello.Query.Product.GetByKey(productModel.Content.GetSafeGuid("product"));

            productModel.ProductKey  = product.Key;
            productModel.Price       = product.Price;
            productModel.HasVariants = product.ProductVariants.Any();
            productModel.Options     = product.ProductOptions;

            productModel.AddItemFormModel = new AddItemFormModel()
            {
                ContentId  = productModel.Content.Id,
                ProductKey = product.Key,
                Product    = product,
                Quantity   = 1
            };

            return(CurrentTemplate(productModel));
        }
Beispiel #4
0
        /// <summary>
        /// The convert data to source.
        /// </summary>
        /// <param name="propertyType">
        /// The property type.
        /// </param>
        /// <param name="source">
        /// The source.
        /// </param>
        /// <param name="preview">
        /// The preview.
        /// </param>
        /// <returns>
        /// The <see cref="object"/>.
        /// </returns>
        public override object ConvertDataToSource(PublishedPropertyType propertyType, object source, bool preview)
        {
            var merchello = new MerchelloHelper();

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

            var collectionKey = source.ToString();

            if (collectionKey.IsNullOrWhiteSpace())
            {
                var query = merchello.ProductContentQuery().Page(1).ItemsPerPage(10).OrderBy(ProductSortField.Name);

                //var defaultCollection = merchello.Query.Product.TypedProductContentSearch(1, 10);

                return(new ProductContentListView(Guid.Empty, query.Execute().Items));
            }

            try
            {
                var key = new Guid(collectionKey);

                var query = merchello.ProductContentQuery().Page(1).ItemsPerPage(long.MaxValue).ConstrainByCollectionKey(key);

                return(new ProductContentListView(key, query.Execute().Items));
            }
            catch (Exception ex)
            {
                MultiLogHelper.Error <ProductListViewValueConverter>("Failed to Convert Merchello.ProductListView property", ex);
                return(null);
            }
        }
        /// <summary>
        /// Converts property data to <see cref="ProductDisplay"/>.
        /// </summary>
        /// <param name="propertyType">
        /// The property type.
        /// </param>
        /// <param name="source">
        /// The source.
        /// </param>
        /// <param name="preview">
        /// The preview.
        /// </param>
        /// <returns>
        /// The <see cref="object"/>.
        /// </returns>
        public override object ConvertDataToSource(PublishedPropertyType propertyType, object source, bool preview)
        {
            var merchello = new MerchelloHelper();

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

            var productKey = source.ToString();

            if (string.IsNullOrEmpty(productKey))
            {
                return(null);
            }

            try
            {
                var key = new Guid(productKey);
                return(merchello.Query.Product.GetByKey(key));
            }
            catch (Exception ex)
            {
                // MultiLogHelper.Info<ProductDisplayValueConverter>("Failed to Convert ProductDisplay property");
                return(null);
            }
        }
        /// <summary>
        /// The convert data to source.
        /// </summary>
        /// <param name="propertyType">
        /// The property type.
        /// </param>
        /// <param name="source">
        /// The source.
        /// </param>
        /// <param name="preview">
        /// The preview.
        /// </param>
        /// <returns>
        /// The <see cref="object"/>.
        /// </returns>
        public override object ConvertDataToSource(PublishedPropertyType propertyType, object source, bool preview)
        {
            var merchello = new MerchelloHelper();

            if (source == null)
                return null;

            var collectionKey = source.ToString();

            if (collectionKey.IsNullOrWhiteSpace())
            {

                var defaultCollection = merchello.Query.Product.Search(1, 10)
                    .Items.Select(x => merchello.TypedProductContent(((ProductDisplay)x).Key));

                return new ProductContentListView(Guid.Empty, defaultCollection);
            }

            try
            {
                var key = new Guid(collectionKey);
                return new ProductContentListView(key, merchello.TypedProductContentFromCollection(key));
            }
            catch (Exception ex)
            {
                MultiLogHelper.Error<ProductDisplayValueConverter>("Failed to Convert ProductDisplay property", ex);
                return null;
            }
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="OrderApiController"/> class.
 /// </summary>
 /// <param name="merchelloContext">
 /// The merchello context.
 /// </param>
 /// <param name="umbracoContext">
 /// The umbraco context.
 /// </param>
 internal OrderApiController(IMerchelloContext merchelloContext, UmbracoContext umbracoContext)
     : base(merchelloContext, umbracoContext)
 {
     _orderService   = merchelloContext.Services.OrderService;
     _invoiceService = merchelloContext.Services.InvoiceService;
     _merchello      = new MerchelloHelper(merchelloContext, false);
 }
        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();
        }
        /// <summary>
        /// The convert data to source.
        /// </summary>
        /// <param name="propertyType">
        /// The property type.
        /// </param>
        /// <param name="source">
        /// The source.
        /// </param>
        /// <param name="preview">
        /// The preview.
        /// </param>
        /// <returns>
        /// The <see cref="object"/>.
        /// </returns>
        public override object ConvertDataToSource(PublishedPropertyType propertyType, object source, bool preview)
        {
            var merchello = new MerchelloHelper();

            if (source == null)
                return null;

            var collectionKey = source.ToString();

            if (collectionKey.IsNullOrWhiteSpace())
            {
                var query = merchello.ProductContentQuery().Page(1).ItemsPerPage(10).OrderBy(ProductSortField.Name);

               //var defaultCollection = merchello.Query.Product.TypedProductContentSearch(1, 10);

                return new ProductContentListView(Guid.Empty, query.Execute().Items);
            }

            try
            {
                var key = new Guid(collectionKey);

                var query = merchello.ProductContentQuery().Page(1).ItemsPerPage(long.MaxValue).ConstrainByCollectionKey(key);

                return new ProductContentListView(key, query.Execute().Items);
            }
            catch (Exception ex)
            {
                MultiLogHelper.Error<ProductListViewValueConverter>("Failed to Convert Merchello.ProductListView property", ex);
                return null;
            }
        }
Beispiel #10
0
 /// <summary>
 /// Initializes a new instance of the <see cref="NoteApiController"/> class.
 /// </summary>
 /// <param name="merchelloContext">
 /// The merchello context.
 /// </param>
 public NoteApiController(IMerchelloContext merchelloContext)
     : base(merchelloContext)
 {
     Mandate.ParameterNotNull(merchelloContext, "merchelloContext");
     _noteService = merchelloContext.Services.NoteService;
     _merchelloHelper = new MerchelloHelper(merchelloContext.Services);
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="OrderApiController" /> class.
 /// </summary>
 /// <param name="merchelloContext">The merchello context.</param>        
 public OrderApiController(IMerchelloContext merchelloContext)
     : base(merchelloContext)
 {
     _orderService = merchelloContext.Services.OrderService;
     _invoiceService = merchelloContext.Services.InvoiceService;
     _merchello = new MerchelloHelper(merchelloContext.Services);
 }
Beispiel #12
0
        public void Can_Retrieve_A_Product_From_The_Index_By_Sku()
        {
            //// Arrange

            var merchello = new MerchelloHelper(MerchelloContext.Current.Services, 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);
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="OrderApiController" /> class.
 /// </summary>
 /// <param name="merchelloContext">The merchello context.</param>
 public OrderApiController(IMerchelloContext merchelloContext)
     : base(merchelloContext)
 {
     _orderService   = merchelloContext.Services.OrderService;
     _invoiceService = merchelloContext.Services.InvoiceService;
     _merchello      = new MerchelloHelper(merchelloContext, false);
 }
Beispiel #14
0
        /// <summary>
        /// The convert data to source.
        /// </summary>
        /// <param name="propertyType">
        /// The property type.
        /// </param>
        /// <param name="source">
        /// The source.
        /// </param>
        /// <param name="preview">
        /// The preview.
        /// </param>
        /// <returns>
        /// The <see cref="object"/>.
        /// </returns>
        public override object ConvertDataToSource(PublishedPropertyType propertyType, object source, bool preview)
        {
            var merchello = new MerchelloHelper();

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

            var collectionKey = source.ToString();

            if (collectionKey.IsNullOrWhiteSpace())
            {
                var defaultCollection = merchello.Query.Product.TypedProductContentSearch(1, 10);

                return(new ProductContentListView(Guid.Empty, defaultCollection));
            }

            try
            {
                var key = new Guid(collectionKey);
                return(new ProductContentListView(key, merchello.TypedProductContentFromCollection(key)));
            }
            catch (Exception ex)
            {
                MultiLogHelper.Error <ProductDisplayValueConverter>("Failed to Convert ProductDisplay property", ex);
                return(null);
            }
        }
Beispiel #15
0
 /// <summary>
 /// Initializes a new instance of the <see cref="NoteApiController"/> class.
 /// </summary>
 /// <param name="merchelloContext">
 /// The merchello context.
 /// </param>
 public NoteApiController(IMerchelloContext merchelloContext)
     : base(merchelloContext)
 {
     Mandate.ParameterNotNull(merchelloContext, "merchelloContext");
     _noteService     = merchelloContext.Services.NoteService;
     _merchelloHelper = new MerchelloHelper(merchelloContext.Services);
 }
Beispiel #16
0
        /// <summary>
        /// Maps an <see cref="IInvoice"/> to <see cref="CustomerOrder"/>.
        /// </summary>
        /// <param name="invoice">
        /// The invoice.
        /// </param>
        /// <returns>
        /// The <see cref="CustomerOrder"/>.
        /// </returns>
        public static CustomerOrder AsCustomerOrder(this IInvoice invoice)
        {
            var shippingLineItem = invoice.ShippingLineItems().FirstOrDefault();

            var shippingAdr = shippingLineItem != null
                                  ? shippingLineItem.ExtendedData.GetShipment <InvoiceLineItem>()
                              .GetDestinationAddress()
                              .AsAddressModel()
                                  : new AddressModel();

            var billingAdr = invoice.GetBillingAddress().AsAddressModel();

            var merchello = new MerchelloHelper();

            return(new CustomerOrder
            {
                BillingAddress = billingAdr,
                ShippingAddress = shippingAdr,
                FormattedDiscountTotal = StoreHelper.FormatCurrency(0),
                FormattedShippingTotal = StoreHelper.FormatCurrency(invoice.TotalShipping()),
                FormattedSubTotal = StoreHelper.FormatCurrency(invoice.TotalItemPrice()),
                FormattedTotal = StoreHelper.FormatCurrency(invoice.Total),
                InvoiceDate = invoice.InvoiceDate,
                InvoiceNumber = invoice.PrefixedInvoiceNumber(),
                InvoiceStatus = invoice.InvoiceStatus.Name,
                OrderStatus = invoice.Orders.Any() ? invoice.Orders.First().OrderStatus.Name : "Being prepared",
                Key = invoice.Key,
                Products = invoice.ProductLineItems().Select(x => x.AsBasketItem(merchello))
            });
        }
Beispiel #17
0
 /// <summary>
 /// Initializes a new instance of the <see cref="AuditLogApiController"/> class.
 /// </summary>
 /// <param name="merchelloContext">
 /// The merchello context.
 /// </param>
 public AuditLogApiController(IMerchelloContext merchelloContext)
     : base(merchelloContext)
 {
     Mandate.ParameterNotNull(merchelloContext, "merchelloContext");
     _auditLogService = merchelloContext.Services.AuditLogService;
     _merchelloHelper = new MerchelloHelper(merchelloContext.Services);
 }
Beispiel #18
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()));
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="AuditLogApiController"/> class.
 /// </summary>
 /// <param name="merchelloContext">
 /// The merchello context.
 /// </param>
 public AuditLogApiController(IMerchelloContext merchelloContext)
     : base(merchelloContext)
 {
     Mandate.ParameterNotNull(merchelloContext, "merchelloContext");
     _auditLogService = merchelloContext.Services.AuditLogService;
     _merchelloHelper = new MerchelloHelper(merchelloContext.Services);
 }
Beispiel #20
0
        //[Test]
        public void InvoiceJsonResults()
        {
            var merchello = new MerchelloHelper();

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

            Console.WriteLine(JsonConvert.SerializeObject(invoices));
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="InvoiceApiController"/> class.
 /// </summary>
 /// <param name="merchelloContext">
 /// The merchello context.
 /// </param>
 public InvoiceApiController(IMerchelloContext merchelloContext)
     : base(merchelloContext)
 {
     _storeSettingService = MerchelloContext.Services.StoreSettingService as StoreSettingService;
     _invoiceService      = merchelloContext.Services.InvoiceService;
     _noteService         = merchelloContext.Services.NoteService;
     _merchello           = new MerchelloHelper(merchelloContext.Services, false);
 }
        /// <summary>
        /// Initializes the visitor.
        /// </summary>
        private void Initialize()
        {
            _taxationContext        = MerchelloContext.Current.Gateways.Taxation;
            _productTaxationEnabled = _taxationContext.ProductPricingEnabled;

            // we do not want to modify data here
            _merchello = new MerchelloHelper(false);
        }
        /// <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;
            _storeSettingService = MerchelloContext.Services.StoreSettingService as StoreSettingService;

            _merchello = new MerchelloHelper(merchelloContext.Services);
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="ProductApiController"/> class.
 /// This is a helper constructor for unit testing
 /// </summary>
 /// <param name="merchelloContext">
 /// The merchello Context.
 /// </param>
 /// <param name="umbracoContext">
 /// The umbraco Context.
 /// </param>
 internal ProductApiController(IMerchelloContext merchelloContext, UmbracoContext umbracoContext)
     : base(merchelloContext, umbracoContext)
 {
     _productService        = MerchelloContext.Services.ProductService;
     _productVariantService = MerchelloContext.Services.ProductVariantService;
     _warehouseService      = MerchelloContext.Services.WarehouseService;
     _merchello             = new MerchelloHelper(MerchelloContext, false, DetachedValuesConversionType.Editor);
 }
Beispiel #25
0
 /// <summary>
 /// Initializes a new instance of the <see cref="InvoiceApiController"/> class.
 /// </summary>
 /// <param name="merchelloContext">
 /// The merchello context.
 /// </param>
 public InvoiceApiController(IMerchelloContext merchelloContext)
     : base(merchelloContext)
 {
     _storeSettingService = MerchelloContext.Services.StoreSettingService as StoreSettingService;
     _invoiceService = merchelloContext.Services.InvoiceService;
     _noteService = merchelloContext.Services.NoteService;
     _merchello = new MerchelloHelper(merchelloContext, false);
 }
Beispiel #26
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ProductApiController"/> class.
 /// This is a helper constructor for unit testing
 /// </summary>
 /// <param name="merchelloContext">
 /// The merchello Context.
 /// </param>
 /// <param name="umbracoContext">
 /// The umbraco Context.
 /// </param>
 internal ProductApiController(IMerchelloContext merchelloContext, UmbracoContext umbracoContext)
     : base(merchelloContext, umbracoContext)
 {
     _productService        = MerchelloContext.Services.ProductService;
     _productVariantService = MerchelloContext.Services.ProductVariantService;
     _warehouseService      = MerchelloContext.Services.WarehouseService;
     _merchello             = new MerchelloHelper(MerchelloContext.Services, false);
 }
        /// <summary>
        /// The resolve value.
        /// </summary>
        /// <returns>
        /// The <see cref="object"/>.
        /// </returns>
        public override object ResolveValue()
        {
            var merchello = new MerchelloHelper();

            return(!this.Context.SalePreparation.IsReadyToInvoice() ?
                   this.Context.Basket.Items.Select(x => x.AsProductLineItem(merchello)) :
                   this.Context.SalePreparation.PrepareInvoice().ProductLineItems().Select(x => x.AsProductLineItem(merchello)));
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="ProductApiController"/> class. 
        /// Constructor
        /// </summary>
        /// <param name="merchelloContext">
        /// The <see cref="IMerchelloContext"/>
        /// </param>
        public ProductApiController(IMerchelloContext merchelloContext)
            : base(merchelloContext)
        {
            _productService = MerchelloContext.Services.ProductService;
            _productVariantService = MerchelloContext.Services.ProductVariantService;
            _warehouseService = MerchelloContext.Services.WarehouseService;

            _merchello = new MerchelloHelper(MerchelloContext.Services, false);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="ProductApiController"/> class. 
        /// Constructor
        /// </summary>
        /// <param name="merchelloContext">
        /// The <see cref="IMerchelloContext"/>
        /// </param>
        public ProductApiController(IMerchelloContext merchelloContext)
            : base(merchelloContext)
        {
            _productService = MerchelloContext.Services.ProductService;
            _productVariantService = MerchelloContext.Services.ProductVariantService;
            _warehouseService = MerchelloContext.Services.WarehouseService;

            _merchello = new MerchelloHelper(MerchelloContext.Services, false, DetachedValuesConversionType.Editor);
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="ShipmentApiController"/> class.
 /// </summary>
 /// <param name="merchelloContext">
 /// The merchello context.
 /// </param>
 public ShipmentApiController(IMerchelloContext merchelloContext)
     : base(merchelloContext)
 {
     _shipmentService = merchelloContext.Services.ShipmentService;
     _invoiceService = merchelloContext.Services.InvoiceService;
     _orderService = merchelloContext.Services.OrderService;
     _shipMethodService = ((ServiceContext)merchelloContext.Services).ShipMethodService;
     _merchello = new MerchelloHelper(merchelloContext.Services);
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="ShipmentApiController"/> class.
 /// </summary>
 /// <param name="merchelloContext">
 /// The merchello context.
 /// </param>
 public ShipmentApiController(IMerchelloContext merchelloContext)
     : base(merchelloContext)
 {
     _shipmentService = merchelloContext.Services.ShipmentService;
     _invoiceService = merchelloContext.Services.InvoiceService;
     _orderService = merchelloContext.Services.OrderService;
     _shipMethodService = ((ServiceContext)merchelloContext.Services).ShipMethodService;
     _merchello = new MerchelloHelper(merchelloContext.Services);
 }
        /// <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>
        /// Initializes a new instance of the <see cref="ProductApiController"/> class.
        /// Constructor
        /// </summary>
        /// <param name="merchelloContext">
        /// The <see cref="IMerchelloContext"/>
        /// </param>
        public ProductApiController(IMerchelloContext merchelloContext)
            : base(merchelloContext)
        {
            _productService        = MerchelloContext.Services.ProductService;
            _productVariantService = MerchelloContext.Services.ProductVariantService;
            _warehouseService      = MerchelloContext.Services.WarehouseService;

            _merchello = new MerchelloHelper(MerchelloContext.Services);
        }
Beispiel #34
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ShipmentApiController"/> class.
 /// This is a helper constructor for unit testing
 /// </summary>
 /// <param name="merchelloContext">
 /// The merchello Context.
 /// </param>
 /// <param name="umbracoContext">
 /// The umbraco Context.
 /// </param>
 internal ShipmentApiController(IMerchelloContext merchelloContext, UmbracoContext umbracoContext)
     : base(merchelloContext, umbracoContext)
 {
     _shipmentService   = merchelloContext.Services.ShipmentService;
     _invoiceService    = merchelloContext.Services.InvoiceService;
     _orderService      = merchelloContext.Services.OrderService;
     _shipMethodService = ((ServiceContext)merchelloContext.Services).ShipMethodService;
     _merchello         = new MerchelloHelper(merchelloContext.Services, false);
 }
Beispiel #35
0
        public void Can_RetrieveProductOptions_From_ProductInIndex()
        {
            //// Arrange

            var merchello = new MerchelloHelper(MerchelloContext.Current.Services, 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");
        }
Beispiel #36
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ProductDataTableApiControllerBase{TTable,TRow}"/> class.
        /// </summary>
        /// <param name="merchelloHelper">
        /// The <see cref="MerchelloHelper"/>.
        /// </param>
        /// <param name="productDataTableFactory">
        /// The <see cref="ProductDataTableFactory{TTable, TTableRow}"/>.
        /// </param>
        protected ProductDataTableApiControllerBase(
            MerchelloHelper merchelloHelper,
            ProductDataTableFactory <TTable, TRow> productDataTableFactory)
        {
            Mandate.ParameterNotNull(merchelloHelper, "merchell");
            Mandate.ParameterNotNull(productDataTableFactory, "productDataTableFactory");

            this._merchelloHelper         = merchelloHelper;
            this._productDataTableFactory = productDataTableFactory;
        }
        /// <summary>
        /// Returns All Products
        ///
        /// GET /umbraco/Merchello/ProductApi/GetProducts
        /// </summary>
        /// <param name="keys"></param>
        public IEnumerable <ProductDisplay> GetAllProducts()
        {
            MerchelloHelper merchello = new MerchelloHelper();

            var criteria = ExamineManager.Instance.CreateSearchCriteria();

            criteria.Field("master", "True");

            return(merchello.SearchProducts(criteria));
        }
Beispiel #38
0
        /// <summary>
        /// Initializes a new instance of the <see cref="SalesSearchReportApiController"/> class.
        /// </summary>
        /// <param name="merchelloContext">
        /// The merchello context.
        /// </param>
        /// <param name="umbracoContext">
        /// The umbraco Context.
        /// </param>
        public SalesSearchReportApiController(IMerchelloContext merchelloContext, UmbracoContext umbracoContext)
            : base(merchelloContext)
        {
            _culture = LocalizationHelper.GetCultureFromUser(umbracoContext.Security.CurrentUser);

            _invoiceService = merchelloContext.Services.InvoiceService;

            _merchello = new MerchelloHelper();

            _textService = umbracoContext.Application.Services.TextService;
        }
        /// <summary>
        /// The default controller method
        /// </summary>
        /// <param name="model">
        /// The default <see cref="RenderModel"/>
        /// </param>
        /// <returns>
        /// The <see cref="ActionResult"/> to render the product listing page template view
        /// </returns>
        public override ActionResult Index(RenderModel model)
        {
            var productListing = BuildModel <ProductListingViewModel>();

            var merchello = new MerchelloHelper();

            productListing.Products = productListing.Content.Descendants("Product").ToList().Where(x => x.IsVisible())
                                      .Select(x => x.ToProductListItem(Umbraco, merchello.Query.Product.GetByKey(x.GetSafeGuid("product"))));

            return(CurrentTemplate(productListing));
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="CustomerApiController"/> class.
        /// </summary>
        /// <param name="merchelloContext">
        /// The merchello context.
        /// </param>
        /// <param name="memberService">
        /// The member Service.
        /// </param>
        public CustomerApiController(IMerchelloContext merchelloContext, IMemberService memberService)
            : base(merchelloContext)
        {
            Mandate.ParameterNotNull(merchelloContext, "merchelloContext");
            Mandate.ParameterNotNull(memberService, "memberService");

            _customerService = merchelloContext.Services.CustomerService;
            _customerAddressService = ((Core.Services.ServiceContext)merchelloContext.Services).CustomerAddressService;
            _memberService = memberService;

            _merchello = new MerchelloHelper(merchelloContext.Services, false);
        }
        /// <summary>
        /// Converts property data to <see cref="ProductDisplay"/>.
        /// </summary>
        /// <param name="propertyType">
        /// The property type.
        /// </param>
        /// <param name="source">
        /// The source.
        /// </param>
        /// <param name="preview">
        /// The preview.
        /// </param>
        /// <returns>
        /// The <see cref="object"/>.
        /// </returns>
        public override object ConvertDataToSource(PublishedPropertyType propertyType, object source, bool preview)
        {
            var merchello = new MerchelloHelper();

            if (source == null)
                return null;

            var productKey = source.ToString();

            try
            {
                var key = new Guid(productKey);
                return merchello.Query.Product.GetByKey(key);
            }
            catch (Exception)
            {
                return null;
            }
        }
        /// <summary>
        /// Converts property data to <see cref="ProductDisplay"/>.
        /// </summary>
        /// <param name="propertyType">
        /// The property type.
        /// </param>
        /// <param name="source">
        /// The source.
        /// </param>
        /// <param name="preview">
        /// The preview.
        /// </param>
        /// <returns>
        /// The <see cref="object"/>.
        /// </returns>
        public override object ConvertDataToSource(PublishedPropertyType propertyType, object source, bool preview)
        {
            var merchello = new MerchelloHelper();

            if (source == null)
                return null;

            var productKey = source.ToString();

            try
            {
                var key = new Guid(productKey);
                return merchello.Query.Product.GetByKey(key);
            }
            catch (Exception ex)
            {
                MultiLogHelper.Error<ProductDisplayValueConverter>("Failed to Convert ProductDisplay property", ex);
                return null;
            }
        }
        /// <summary>
        /// The convert data to source.
        /// </summary>
        /// <param name="propertyType">
        /// The property type.
        /// </param>
        /// <param name="source">
        /// The source.
        /// </param>
        /// <param name="preview">
        /// The preview.
        /// </param>
        /// <returns>
        /// The <see cref="object"/>.
        /// </returns>
        public override object ConvertDataToSource(PublishedPropertyType propertyType, object source, bool preview)
        {
            var merchello = new MerchelloHelper();

            if (source == null)
                return null;

            var productKeys = JsonConvert.DeserializeObject<IEnumerable<Guid>>(source.ToString());

            try
            {
                var products = productKeys.Select(key => merchello.TypedProductContent(key)).ToList();

                return products;

            }
            catch (Exception ex)
            {
                LogHelper.Error<ProductDisplayValueConverter>("Failed to Convert ProductDisplay property", ex);
                return null;
            }
        }
        /// <summary>
        /// Returns All Products
        /// 
        /// GET /umbraco/Merchello/ProductApi/GetFilteredProducts
        /// </summary>
        /// <param name="term"></param>
        public IEnumerable<ProductDisplay> GetFilteredProducts(string term)
        {
            MerchelloHelper merchello = new MerchelloHelper();

            return merchello.SearchProducts(term);
        }
Beispiel #45
0
 public static ProductDisplay GetByKey(string key)
 {
     var merchello = new MerchelloHelper(GetMerchelloContext().Services);
     return merchello.Query.Product.GetByKey(key.EncodeAsGuid());
 }
        /// <summary>
        /// Returns All Products
        /// 
        /// GET /umbraco/Merchello/ProductApi/GetFilteredProducts
        /// </summary>
        /// <param name="term"></param>
        public IEnumerable<ProductDisplay> GetFilteredProducts(string term, int page, int perPage)
        {
            MerchelloHelper merchello = new MerchelloHelper();

            return merchello.SearchProducts(term).Skip((page - 1) * perPage).Take(perPage);
        }
Beispiel #47
0
 public static ProductVariantDisplay GetVariantDisplayByKey(string key)
 {
     var merchello = new MerchelloHelper(GetMerchelloContext().Services);
     return null;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="OrderApiController"/> class.
 /// </summary>
 /// <param name="merchelloContext">
 /// The merchello context.
 /// </param>
 /// <param name="umbracoContext">
 /// The umbraco context.
 /// </param>
 internal OrderApiController(IMerchelloContext merchelloContext, UmbracoContext umbracoContext)
     : base(merchelloContext, umbracoContext)
 {
     _orderService = merchelloContext.Services.OrderService;
     _invoiceService = merchelloContext.Services.InvoiceService;
     _merchello = new MerchelloHelper(merchelloContext.Services);
 }
        /// <summary>
        /// Returns All Products
        /// 
        /// GET /umbraco/Merchello/ProductApi/GetProducts
        /// </summary>
        /// <param name="keys"></param>
        public IEnumerable<ProductDisplay> GetAllProducts()
        {
            MerchelloHelper merchello = new MerchelloHelper();

            var criteria = ExamineManager.Instance.CreateSearchCriteria();
            criteria.Field("master", "True");

            return merchello.SearchProducts(criteria);
        }
        public IEnumerable<CustomerDisplay> GetAllCustomers()
        {
            var merchello = new MerchelloHelper();

            return merchello.AllCustomers();
        }
Beispiel #51
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ProductApiController"/> class. 
 /// This is a helper constructor for unit testing
 /// </summary>
 /// <param name="merchelloContext">
 /// The merchello Context.
 /// </param>
 /// <param name="umbracoContext">
 /// The umbraco Context.
 /// </param>
 internal ProductApiController(IMerchelloContext merchelloContext, UmbracoContext umbracoContext)
     : base(merchelloContext, umbracoContext)
 {
     _productService = MerchelloContext.Services.ProductService;
     _productVariantService = MerchelloContext.Services.ProductVariantService;
     _warehouseService = MerchelloContext.Services.WarehouseService;
     _merchello = new MerchelloHelper(MerchelloContext.Services);
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="ShipmentApiController"/> class. 
 /// This is a helper constructor for unit testing
 /// </summary>
 /// <param name="merchelloContext">
 /// The merchello Context.
 /// </param>
 /// <param name="umbracoContext">
 /// The umbraco Context.
 /// </param>
 internal ShipmentApiController(IMerchelloContext merchelloContext, UmbracoContext umbracoContext)
     : base(merchelloContext, umbracoContext)
 {
     _shipmentService = merchelloContext.Services.ShipmentService;
     _invoiceService = merchelloContext.Services.InvoiceService;
     _orderService = merchelloContext.Services.OrderService;
     _shipMethodService = ((ServiceContext)merchelloContext.Services).ShipMethodService;
     _customerService = merchelloContext.Services.CustomerService;
     _merchello = new MerchelloHelper(merchelloContext.Services, false);
 }
        /// <summary>
        /// Initializes the visitor.
        /// </summary>
        private void Initialize()
        {
            _taxationContext = MerchelloContext.Current.Gateways.Taxation;
            _productTaxationEnabled = _taxationContext.ProductPricingEnabled;

            // we do not want to modify data here
            _merchello = new MerchelloHelper(false);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="ProductInventoryValidationVisitor"/> class.
        /// </summary>
        /// <param name="merchello">
        /// The merchello.
        /// </param>
        public ProductInventoryValidationVisitor(MerchelloHelper merchello)
        {
            Mandate.ParameterNotNull(merchello, "merchello");

            _merchello = merchello;
        }
Beispiel #55
0
        public static IEnumerable<ProductDisplay> GetAllProducts()
        {
            var merchello = new MerchelloHelper(GetMerchelloContext().Services);

            return merchello.Query.Product.Search(0, int.MaxValue).Items.Select(x => (ProductDisplay)x);
        }
 /// <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 IEnumerable<IProductContent> GetProducts(
     this ProductCollection value,
     MerchelloHelper merchelloHelper,
     long page,
     long itemsPerPage,
     string sortBy = "",
     SortDirection sortDirection = SortDirection.Ascending)
 {
     return merchelloHelper.Query.Product.TypedProductContentFromCollection(
         value.CollectionKey,
         page,
         itemsPerPage,
         sortBy,
         sortDirection);
 }
        /// <summary>
        /// Initializes a new instance of the <see cref="EntityCollectionApiController"/> class.
        /// </summary>
        /// <param name="merchelloContext">
        /// The merchello context.
        /// </param>
        /// <param name="umbracoContext">
        /// The umbraco context.
        /// </param>
        public EntityCollectionApiController(IMerchelloContext merchelloContext, UmbracoContext umbracoContext)
            : base(merchelloContext, umbracoContext)
        {
            Mandate.ParameterNotNull(merchelloContext, "merchelloContext");

            _entityCollectionService = merchelloContext.Services.EntityCollectionService;

            _resolver = EntityCollectionProviderResolver.Current;

            _merchello = new MerchelloHelper(merchelloContext, false);

            this.Initialize();
        }
        public IEnumerable<CustomerDisplay> GetAllCustomers(int page, int perPage)
        {
            var merchello = new MerchelloHelper();

            return merchello.AllCustomers().Skip((page - 1) * perPage).Take(perPage);
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="BackOfficeCheckoutApiController"/> class.
 /// </summary>
 /// <param name="merchelloContext">
 /// The merchello context.
 /// </param>
 public BackOfficeCheckoutApiController(IMerchelloContext merchelloContext)
     : base(merchelloContext)
 {
     _customerService = merchelloContext.Services.CustomerService;
     _merchello = new MerchelloHelper(merchelloContext.Services);
 }
 /// <summary>
 /// Gets the collection of all 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>
 /// <returns>
 /// The <see cref="IEnumerable{IProductContent}"/>.
 /// </returns>
 public static IEnumerable<IProductContent> GetProducts(
     this ProductCollection value,
     long page,
     long itemsPerPage,
     string sortBy = "",
     SortDirection sortDirection = SortDirection.Ascending)
 {
     var merchelloHelper = new MerchelloHelper();
     return value.GetProducts(merchelloHelper, page, itemsPerPage, sortBy, sortDirection);
 }