Ejemplo n.º 1
0
        public async Task UpdateCustomerAsync(CustomerInfo customer)
        {
            var contact = customer.ToServiceModel();
            await _customerApi.CustomerModuleUpdateContactAsync(contact);

            _cacheManager.Remove(GetCacheKey(customer.Id), "ApiRegion");
        }
Ejemplo n.º 2
0
        public async Task <ActionResult> CreateOrderJson(VirtoCommerceDomainPaymentModelBankCardInfo bankCardInfo)
        {
            EnsureThatCartExist();

            //Need lock to prevent concurrent access to same cart
            using (var lockObject = await AsyncLock.GetLockByKey(GetAsyncLockCartKey(WorkContext.CurrentCart.Id)).LockAsync())
            {
                var order = await _orderApi.OrderModuleCreateOrderFromCartAsync(_cartBuilder.Cart.Id);

                //Raise domain event
                await _orderPlacedEventPublisher.PublishAsync(new OrderPlacedEvent(order.ToWebModel(base.WorkContext.AllCurrencies, base.WorkContext.CurrentLanguage), _cartBuilder.Cart));

                await _cartBuilder.RemoveCartAsync();

                if (HttpContext.User.Identity.IsAuthenticated)
                {
                    var contact = await _customerApi.CustomerModuleGetContactByIdAsync(WorkContext.CurrentCustomer.Id);

                    var orderAddresses = GetOrderAddresses(order);
                    foreach (var orderAddress in orderAddresses)
                    {
                        contact.Addresses.Add(orderAddress.ToCustomerModel());
                    }

                    await _customerApi.CustomerModuleUpdateContactAsync(contact);
                }

                var processingResult = await GetOrderProcessingResultAsync(order, bankCardInfo);

                return(Json(new { order = order, orderProcessingResult = processingResult }, JsonRequestBehavior.AllowGet));
            }
        }
Ejemplo n.º 3
0
        public async Task UpdateCustomerAsync(CustomerInfo customer)
        {
            var contact = customer.ToServiceModel();
            await _customerApi.CustomerModuleUpdateContactAsync(contact);

            //Invalidate cache
            _cacheManager.ClearRegion(string.Format(_customerCacheRegionFormat, customer.Id));
        }
Ejemplo n.º 4
0
        public async Task <ActionResult> UpdateAddress(string id, shopifyModel.Address formModel)
        {
            var contact = await _customerApi.CustomerModuleGetContactByIdAsync(WorkContext.CurrentCustomer.Id);

            var updateContact = false;

            if (contact != null)
            {
                if (string.IsNullOrEmpty(id))
                {
                    // Add new address
                    contact.Addresses.Add(formModel.ToServiceModel(WorkContext.AllCountries));
                    updateContact = true;
                }
                else
                {
                    int addressIndex;
                    if (int.TryParse(id, NumberStyles.Integer, CultureInfo.InvariantCulture, out addressIndex))
                    {
                        if (addressIndex > 0 && addressIndex <= contact.Addresses.Count)
                        {
                            if (string.Equals(formModel.Method, "delete", StringComparison.OrdinalIgnoreCase))
                            {
                                // Delete address
                                contact.Addresses.RemoveAt(addressIndex - 1);
                                updateContact = true;
                            }
                            else
                            {
                                // Update address
                                contact.Addresses[addressIndex].CopyFrom(formModel, WorkContext.AllCountries);
                                updateContact = true;
                            }
                        }
                    }
                }

                if (updateContact)
                {
                    await _customerApi.CustomerModuleUpdateContactAsync(contact);
                }
            }

            return(StoreFrontRedirect("~/account/addresses"));
        }
Ejemplo n.º 5
0
        public async Task <ActionResult> CreateOrderJson(VirtoCommerceDomainPaymentModelBankCardInfo bankCardInfo)
        {
            await _cartBuilder.GetOrCreateNewTransientCartAsync(WorkContext.CurrentStore, WorkContext.CurrentCustomer, WorkContext.CurrentLanguage, WorkContext.CurrentCurrency);

            var order = await _orderApi.OrderModuleCreateOrderFromCartAsync(_cartBuilder.Cart.Id);

            await _cartBuilder.RemoveCartAsync();

            if (HttpContext.User.Identity.IsAuthenticated)
            {
                var contact = await _customerApi.CustomerModuleGetContactByIdAsync(WorkContext.CurrentCustomer.Id);

                foreach (var orderAddress in order.Addresses)
                {
                    contact.Addresses.Add(orderAddress.ToCustomerModel());
                }

                await _customerApi.CustomerModuleUpdateContactAsync(contact);
            }

            var processingResult = await GetOrderProcessingResultAsync(order, bankCardInfo);

            return(Json(new { order = order, orderProcessingResult = processingResult }, JsonRequestBehavior.AllowGet));
        }