[SOLVED] What is the proper way of passing information between checkout steps? (NOP 1.90)

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
11 yıl önce
Hello again.

I'm trying to add a new checkout step to NOP, so that when customer selects Parcel Machine as delivery option, new step appear. I was able to add new step, and now I can select the options I want in there... but they are not saved after I click the Next button. I modified Customer class by adding two custom attributes like this:

#region Custom Properties

public string LastPrimaryParcelMachine { get; set; }
public string LastSecondaryParcelMachine { get; set; }


but when I use the following code:

protected void btnNextStep_Click(object sender, EventArgs e)
{
  if (Page.IsValid)
  {
    NopContext.Current.User.LastPrimaryParcelMachine = ddlPreferedParcelMachine.SelectedValue;
    NopContext.Current.User.LastSecondaryParcelMachine = ddlAlternateParcelMachine.SelectedValue;
    this.CustomerService.UpdateCustomer(NopContext.Current.User);

    var args1 = new CheckoutStepEventArgs() { PrimaryAndSecondaryPaczkomatSet = true };
    OnCheckoutStepChanged(args1);
    if (!this.OnePageCheckout)
      Response.Redirect("~/checkoutpaymentmethod.aspx");
  }
}


the NopContext.Current.User.LastPrimaryParcelMachine and NopContext.Current.User.LastSecondaryParcelMachine properties are null inside the next step, while others (ShippingAddressId for example) are not null.

What am I doing wrong?

Thanks in advance
11 yıl önce
OK, I figured it out - simple {get;set;} won't do, something like this:

public string LastPreferedParcelMachine
        {
            get
            {
                string lastPreferedParcelMachine = null;
                CustomerAttribute lastPreferedParcelMachineAttr = this.CustomerAttributes.FindAttribute("LastPreferedParcelMachine", this.CustomerId);
                if (lastPreferedParcelMachineAttr != null)
                {
                    lastPreferedParcelMachine = lastPreferedParcelMachineAttr.Value;
                }

                return lastPreferedParcelMachine;
            }
            set
            {
                CustomerAttribute lastPreferedParcelMachineAttr = this.CustomerAttributes.FindAttribute("LastPreferedParcelMachine", this.CustomerId);
                if (value != null)
                {
                    if (lastPreferedParcelMachineAttr != null)
                    {
                        lastPreferedParcelMachineAttr.Value = value;
                        IoC.Resolve<ICustomerService>().UpdateCustomerAttribute(lastPreferedParcelMachineAttr);
                    }
                    else
                    {
                        lastPreferedParcelMachineAttr = new CustomerAttribute()
                        {
                            CustomerId = this.CustomerId,
                            Key = "LastPreferedParcelMachine",
                            Value = value
                        };
                        IoC.Resolve<ICustomerService>().InsertCustomerAttribute(lastPreferedParcelMachineAttr);
                    }
                }
            }
        }
        public string LastAlternateParcelMachine
        {
            get
            {
                string lastAlternateParcelMachine = null;
                CustomerAttribute lastAlternateParcelMachineAttr = this.CustomerAttributes.FindAttribute("LastAlternateParcelMachine", this.CustomerId);
                if (lastAlternateParcelMachineAttr != null)
                {
                    lastAlternateParcelMachine = lastAlternateParcelMachineAttr.Value;
                }

                return lastAlternateParcelMachine;
            }
            set
            {
                CustomerAttribute lastAlternateParcelMachineAttr = this.CustomerAttributes.FindAttribute("LastAlternateParcelMachine", this.CustomerId);
                if (value != null)
                {
                    if (lastAlternateParcelMachineAttr != null)
                    {
                        lastAlternateParcelMachineAttr.Value = value;
                        IoC.Resolve<ICustomerService>().UpdateCustomerAttribute(lastAlternateParcelMachineAttr);
                    }
                    else
                    {
                        lastAlternateParcelMachineAttr = new CustomerAttribute()
                        {
                            CustomerId = this.CustomerId,
                            Key = "LastAlternateParcelMachine",
                            Value = value
                        };
                        IoC.Resolve<ICustomerService>().InsertCustomerAttribute(lastAlternateParcelMachineAttr);
                    }
                }
            }
        }
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.