Beispiel #1
0
 public static int CreateOrUpdate(this IRepository <OrderAddressRecord> repository, OrderAddressRecord record)
 {
     if (record != null)
     {
         if (record.Id > 0)
         {
             repository.Update(record);
         }
         else
         {
             repository.Create(record);
         }
         return(record.Id);
     }
     else
     {
         return(0);
     }
 }
Beispiel #2
0
        public void BuildOrder(IShoppingCartService ShoppingCartService, IContent Order)
        {
            var customer = _customersService.GetCustomer();

            if (customer == null)
            {
                return;
            }

            OrderAddressRecord billingAddress = null, shippingAddress = null;
            Int32 billingAddressId = ShoppingCartService.GetProperty <int>("BillingAddressId");

            if (billingAddressId > 0)
            {
                var customerBillingAddress = customer.Addresses.Where(a => a.Id == billingAddressId).FirstOrDefault();
                if (customerBillingAddress != null)
                {
                    billingAddress = new OrderAddressRecord();
                    customerBillingAddress.CopyTo(billingAddress);
                }
            }
            Int32 shippingAddressId = ShoppingCartService.GetProperty <int>("ShippingAddressId");

            if (shippingAddressId > 0)
            {
                if (shippingAddressId == billingAddressId)
                {
                    shippingAddress = billingAddress;
                }
                else
                {
                    var customerShippingAddress = customer.Addresses.Where(a => a.Id == shippingAddressId).FirstOrDefault();
                    if (customerShippingAddress != null)
                    {
                        shippingAddress = new OrderAddressRecord();
                        customerShippingAddress.CopyTo(shippingAddress);
                    }
                }
            }

            var customerOrderPart = Order.As <CustomerOrderPart>();

            if (customerOrderPart != null)
            {
                customerOrderPart.Customer = customer;
            }

            var orderPart = Order.As <OrderPart>();

            if (orderPart != null && billingAddress != null)
            {
                orderPart.BillingAddress = billingAddress;
            }

            var shippingPart = Order.As <OrderShippingPart>();

            if (shippingPart != null)
            {
                //  Shipping address
                if (shippingAddress != null)
                {
                    // Set address
                    shippingPart.ShippingAddress = shippingAddress;

                    // Set shipping zone
                    var workContext = _workContextAccessor.GetContext();
                    if (shippingAddress.State != null && shippingAddress.State.Enabled && shippingAddress.State.ShippingZoneRecord != null)
                    {
                        workContext.SetState("OShop.Orders.ShippingZone", shippingAddress.State.ShippingZoneRecord);
                    }
                    else if (shippingAddress.Country != null && shippingAddress.Country.Enabled && shippingAddress.Country.ShippingZoneRecord != null)
                    {
                        workContext.SetState("OShop.Orders.ShippingZone", shippingAddress.Country.ShippingZoneRecord);
                    }
                }
            }
        }