CustomerID jumps from 1 to 591 for only 8 registred users

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
11 years ago
Even within the class (public partial class WebWorkContext)create these two methods

   public  bool HasCustomerCookie()
        {
            if (_httpContext == null || _httpContext.Request == null)
                return false;
            var customerCookie = GetCustomerCookie();
            if (customerCookie != null && !String.IsNullOrEmpty(customerCookie.Value))
                 return true;
            else return false;
        }
        public Customer AddGuestCustomer()
        {
            var customer = _customerService.InsertGuestCustomer();
            SetCustomerCookie(customer.CustomerGuid);
            return customer;
        }

Dont foget to add too in IWorkContext
  
  
bool HasCustomerCookie();
  Customer AddGuestCustomer();

And finally change the methods public virtual IList <string> AddToCart (...)
after the line below
 if (productVariant == null)
                throw new ArgumentNullException("productVariant");

    

Add
  
        if (_workContext.HasCustomerCookie() && customer.IsSearchEngineAccount())
            {
         var guestCutomer   =    _workContext.AddGuestCustomer();
         if (guestCutomer != null)
             customer = guestCutomer;
            
            }
11 years ago
I add too  in customerservice to ensure that these users will not do updates

  public virtual void UpdateCustomer(Customer customer)
{
if (!customer.IsSearchEngineAccount())
            {
          
                _customerRepository.Update(customer);

            }

}


I think you guys will have to do something similar to what was added in addToCart method, other methods that you guys want that unregistered users do things like product review.



The solution is not to create users for each access site, only if it is adding an item in the cart and accepts cookies, preventing users from being created unnecessarily.

Otherwise it is treated as a search engine, which is considered a guest by default

However, use at your own risk, if it works do not forget to vote in my posts!
11 years ago
leandromugnol wrote:
Even within the class (public partial class WebWorkContext)create these two methods

   public  bool HasCustomerCookie()
        {
            if (_httpContext == null || _httpContext.Request == null)
                return false;
            var customerCookie = GetCustomerCookie();
            if (customerCookie != null && !String.IsNullOrEmpty(customerCookie.Value))
                 return true;
            else return false;
        }
        public Customer AddGuestCustomer()
        {
            var customer = _customerService.InsertGuestCustomer();
            SetCustomerCookie(customer.CustomerGuid);
            return customer;
        }

Dont foget to add too in IWorkContext
  
Your Solutions is really very good,But I think by this way we wont be able to keep log for the guest who have just visited our site
  
bool HasCustomerCookie();
  Customer AddGuestCustomer();

And finally change the methods public virtual IList <string> AddToCart (...)
after the line below
 if (productVariant == null)
                throw new ArgumentNullException("productVariant");

    

Add
  
        if (_workContext.HasCustomerCookie() && customer.IsSearchEngineAccount())
            {
         var guestCutomer   =    _workContext.AddGuestCustomer();
         if (guestCutomer != null)
             customer = guestCutomer;
            
            }
11 years ago
ndvarpe wrote:

  
Your Solutions is really very good,But I think by this way we wont be able to keep log for the guest who have just visited our site
  
bool HasCustomerCookie();
  Customer AddGuestCustomer();



That's the intention, not save the information of who simply accesses the site. Currently what kind of information is stored only on who accesses the site? Perhaps only the ip? To obtain information of the visits we have tools like Google Analytics, which has a tab just for ecommerce.
Ty
11 years ago
I dont know why it bםthers me, but it does.

so I have decided to disable the insertGuestCustomer

1. created a systemCustomerName.GuestCustomer

2. replace the insertGuestCusromer and customerByCookie with customer = _customerService.GetCustomerBySystemName(SystemCustomerNames.GuestCustomer);
11 years ago
hezyz wrote:
I dont know why it bםthers me, but it does.

so I have decided to disable the insertGuestCustomer

1. created a systemCustomerName.GuestCustomer

2. replace the insertGuestCusromer and customerByCookie with customer = _customerService.GetCustomerBySystemName(SystemCustomerNames.GuestCustomer);


but how this works with shopcarts?

If someone is using my solution, add the following line to allow registration, in customercontroller in

 [HttpPost]
        [CaptchaValidator]
        [ValidateAntiForgeryToken]
        public ActionResult Register(RegisterModel model, string returnUrl, bool captchaValid)

after
 
var customer = _workContext.CurrentCustomer;

add

if (customer.IsSearchEngineAccount())
{
var guestCutomer = _workContext.AddGuestCustomer();
if (guestCutomer != null)
customer = guestCutomer;
}
11 years ago
if someone wishes to bu something he will register
11 years ago
if someone wishes to buy something he will register
ant attempt to go to cart will redirect to login page
11 years ago
leandromugnol wrote:

  That's the intention, not save the information of who simply accesses the site. Currently what kind of information is stored only on who accesses the site? Perhaps only the ip? To obtain information of the visits we have tools like Google Analytics, which has a tab just for ecommerce.
Ty


But when i add to cart method customer.IsSearchEngineAccount() returns false so guest customer is not created..note that i have created new var customer=new customer()..... otherwise it gives error that customer does not exist in the current context

And i am adding guest customer in catalogcontroller right?

Thanks In Advance
11 years ago
Ohh Sorry,


I was wrong i had to change shopping cart service,,,,
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.