コード例 #1
0
ファイル: VentataMapper.cs プロジェクト: vaibkamble/API
        /// <summary>
        /// Converts your internal Product object into a Ventata Product.
        /// </summary>
        /// <param name="product">An instance of your internal Product object</param>
        /// <param name="strategy">What Pricing Strategy would you like to use?</param>
        /// <param name="DateAvailable">[Limited Supply Only] When will the sale start?</param>
        /// <param name="DateExpires">[Limited Supply Only] When will the sale end?</param>
        /// <returns></returns>
        public static VentataProduct ConvertProduct(Product product, string strategy, DateTime?DateAvailable = null, DateTime?DateExpires = null)
        {
            VentataProduct productToReturn = new VentataProduct();

            //This is where we keep your PK in our system for easy lookup
            productToReturn.StoreCode = product.Id.ToString();

            //Map internal Product to VentataProduct
            productToReturn.Cost          = product.Cost;
            productToReturn.CurrentSupply = product.Supply;
            productToReturn.DateCreated   = product.DateCreated;
            productToReturn.Description   = product.DescrLong;
            productToReturn.MANUCODE      = product.ManufacturerNo;
            productToReturn.MaxPrice      = product.Price * 1.5m;
            productToReturn.MinPrice      = product.MAP;
            productToReturn.Name          = product.Name;
            productToReturn.Price         = product.Price;
            productToReturn.SKU           = product.SKU;

            //Set Strategy
            productToReturn.Strategy = strategy.ToString();

            //Limited Supply Mappings
            if (DateAvailable.HasValue && DateExpires.HasValue)
            {
                productToReturn.DateAvailable = DateAvailable.Value;
                productToReturn.DateExpires   = DateExpires.Value;
            }

            return(productToReturn);
        }
コード例 #2
0
        public VentataProduct Update(VentataProduct product)
        {
            VentataProduct productWithId = RestHelper.CallResource(
                "PUT", String.Format("{0}?ApiKey={1}",
                                     "product",
                                     storeApiKey), product.ToJSON() //we are going to PUT to Products with the new product information
                ).FromJSON <VentataProduct>();                      //then we convert it the JSON to a Ventata Product

            return(productWithId);
        }
コード例 #3
0
        public VentataProduct GetProductByStoreCode(string InternalProductId)
        {
            VentataProduct productWithId = RestHelper.CallResource(
                "GET", String.Format("{0}/{1}?ApiKey={2}",
                                     "product/provider/",
                                     InternalProductId,
                                     storeApiKey) //we are going to GET from Products by hitting product/{id}
                ).FromJSON <VentataProduct>();    //then we convert it the JSON to a Ventata Product

            return(productWithId);
        }
コード例 #4
0
        public VentataProduct GetNewPrice(Guid VentataProductId)
        {
            VentataProduct productWithId = RestHelper.CallResource(
                "GET", String.Format("{0}/{1}/price?ApiKey={2}",
                                     "product",
                                     VentataProductId,
                                     storeApiKey) //we are going to GET from Products by hitting product/{id}
                ).FromJSON <VentataProduct>();    //then we convert it the JSON to a Ventata Product

            return(productWithId);
        }
コード例 #5
0
        static void Main(string[] args)
        {
            //1.  Create a store
            VentataStore vStore = new VentataStore()
            {
                Name         = "My Awesome First Store",
                CurrencyCode = "USD",
                ExternalId   = "1",
                URL          = "http://kateCoolToyStore.com/",
                StoreType    = new StoreType()
                {
                    Id   = 1006,
                    Name = "Custom"
                }
            };

            Stores ventataStoreAPI = new Stores(CompanyAPIKey);

            VentataStore newlyCreatedStore = ventataStoreAPI.Create(vStore);

            //You might want to store this Id and the API Key in your database so you can make GET/PUT calls to it
            Guid newStoreId  = newlyCreatedStore.Id;
            Guid storeApiKey = newlyCreatedStore.ApiKey;

            //such as getting the store back out..
            newlyCreatedStore = ventataStoreAPI.Get(newStoreId);

            //or updating the store...
            newlyCreatedStore.Name = "My (Still Very) Awesome Second Store";
            newlyCreatedStore      = ventataStoreAPI.Update(newlyCreatedStore);

            //2.  Now that we've created a store we can add our internal products to that store

            //We'll first start by creating a Product API with that store's security API Key
            Products ventataProductAPI = new Products(storeApiKey);

            //"Product" object is an internal product object, you'll need to edit this class
            //so that it looks like your Product object and also update the Mapper function in Domain
            //but for an example...

            Product prod = new Product()
            {
                Id             = 12345,
                Name           = "New test product",
                Cost           = 4.5m,
                Supply         = 100,
                MAP            = 5,
                DescrLong      = "The most amazing Nirvana t-shirt anyone will ever own",
                DescrShort     = "A Nirvana Shirt",
                ManufacturerNo = "TSHIRT120",
                DateCreated    = DateTime.UtcNow,
                SKU            = "SHIRT-1",
                Price          = 10
            };

            //Use the mapper and pick your pricing strategy:
            //UnlimitedSupply
            //LimitedSupply
            //CapacityControl
            //Appointments
            //RazorPrice
            //Off

            VentataProduct vProduct = VentataMapper.ConvertProduct(prod, "UnlimitedSupply");

            //Send product to Ventata
            vProduct = ventataProductAPI.Create(vProduct);

            //Store this Id in your database so you can make other calls to it
            Guid newlyCreatedProductId = vProduct.Id;

            //such as updating the product information...
            vProduct.MaxPrice = 50;
            vProduct.Cost     = 4.0m;
            vProduct          = ventataProductAPI.Update(vProduct);

            //3.  Now that we've created a product let's make 10 fake orders to associate with that product
            //We first create a ventata order api with the store api key
            Orders ventataOrderAPI = new Orders(storeApiKey);

            for (int i = 0; i < 10; i++)
            {
                //"Order" object is an internal order object, you'll need to edit this class
                //so that it looks like your Order object and also update the Mapper function in Domain
                //but for an example...

                Order o = new Order()
                {
                    Id            = i,
                    DateOrdered   = DateTime.UtcNow,
                    PaymentMethod = "CC",
                    Shipping      = 7,
                    SubTotal      = 80,
                    Taxes         = 0,
                    Total         = 87,
                    OrderDetails  = new List <OrderDetail>()
                };

                //add line items to your internal order object
                o.OrderDetails.Add(new OrderDetail()
                {
                    Cost      = 4,
                    Price     = 10,
                    OrderId   = o.Id,
                    ProductId = prod.Id,
                    Quantity  = 4
                });

                //Convert to a VentataOrder
                VentataOrder vOrder = VentataMapper.ConvertOrder(o);

                //Convert VentataOrderDetails (line items)
                foreach (OrderDetail detail in o.OrderDetails)
                {
                    VentataOrderDetail vDetail = VentataMapper.ConvertOrderDetails(detail);

                    //set the product id to the ventata product id
                    //You could do this more elegantly in your own system
                    //but you can use our API to reconcile the two products Id's with the following call:
                    vDetail.ProductId = ventataProductAPI.GetProductByStoreCode(detail.ProductId.ToString()).Id;

                    //add it to the order
                    vOrder.OrderDetails.Add(vDetail);
                }

                //send it off to Ventata
                vOrder = ventataOrderAPI.Create(vOrder);

                //You can store this Id in your system to make future calls to this resources
                Guid newlyCreatedOrderId = vOrder.Id;
            }

            //4. Call for a new price!
            decimal newPrice = ventataProductAPI.GetNewPrice(newlyCreatedProductId).Price;
        }