Ejemplo n.º 1
0
        /// <summary>
        /// Sets the shipping information for a cart in Magento
        /// </summary>
        /// <param name="cartId">Cart to set shipping information on</param>
        /// <param name="shippingInformation">Information to set</param>
        /// <returns>Response from setting information. Includes billing and shipping information</returns>
        public CartShippingResponseResource SetShippingInformation(int cartId, CartSetShippingInformationResource shippingInformation)
        {
            if (shippingInformation == null)
            {
                throw new ArgumentNullException(nameof(shippingInformation));
            }

            var endpoint = UrlFormatter.MagentoSetShippingInformationUrl(cartId);

            var client  = new RestClient(endpoint);
            var request = new RestRequest(Method.POST);

            request.AddHeader("Authorization", string.Format("Bearer {0}", AuthToken));
            request.AddHeader("Content-Type", "application/json");

            request.AddJsonBody(shippingInformation);

            var response = client.Execute(request);

            //Ensure we get the right code
            CheckStatusCode(response.StatusCode);

            return(JsonConvert.DeserializeObject <CartShippingResponseResource>(response.Content));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Sets the shipping and billing information on a Magento cart.
        /// Shipping address used is based on the EA location unless the data needed is not available. In this case, data is pulled from the customer.
        /// Shipping method used will be the one set in App.config. If that shipping method cannot be used for the cart specified, an exception will occur.
        /// </summary>
        /// <param name="cartId">Identifier for cart to set information on.</param>
        /// <param name="magentoRegion">Region information for address</param>
        /// <param name="eaLocation">Location information for address</param>
        /// <param name="customer">Customer for address information</param>
        public void SetShippingAndBillingInformationForCart(int cartId, RegionResource magentoRegion, LocationResource eaLocation, CustomerResource customer)
        {
            AddressResource shippingAddress;

            if (magentoRegion != null)
            {
                shippingAddress = new AddressResource(magentoRegion, eaLocation, customer);
            }
            else
            {
                shippingAddress = new AddressResource(customer);
            }

            //Verfiy that shipping code matches App.config file
            var shippingInformation = new CartSetShippingInformationResource(ConfigReader.MagentoShippingCode, shippingAddress);

            _magentoCartController.SetShippingInformation(cartId, shippingInformation);

            if (_magentoCartController.GetShippingMethods(cartId).FirstOrDefault(x => x.method_code == ConfigReader.MagentoShippingCode) == null)
            {
                throw new Exception(string.Format("Unable to add shipping information to cart {0}. Ensure that shipping code {1} is valid for this cart.",
                                                  cartId, ConfigReader.MagentoShippingCode));
            }
        }