uCommerce multiple shipping address per customer/member
Hi,
I'm using uCommerce 6.7.2 for Umbraco 7.2.6 and have searched high and low on the forum for adding multiple shipping addresses per customer/member.
I have a scenario where the returning customer is already an Umbraco Member (and signed in) and when they visit the Address page of the order process, I want to retrieve all previous shipping addresses that the customer has used in the past. At this point, the member is invited to select an address or "Enter a new address" which will then save the one that they enter for next time.
I can't figure out where in the API docs this is?
I can see in "_Address.cshtml":
var shipmentAddress = TransactionLibrary.GetShippingInformation();
... which retrieves the previously used shipping address (if there is one), however, I want to return a list of all shipping addresses that matches against the currently logged in member.
var shipmentAddress = TransactionLibrary.GetShippingInformation();
Will give you the default shipping address set on your current basket. If you want to fetch all previous shipping addresses that a Umbraco Member has placed.
So you have to do a custom Query against uCommerce where you fetch all orders where Customer.MemberId is equal to the current logged in member.
You can do this in different ways but simpliest will be using PurchaseOrder.All().Where().
If you need more directions please say so and I will try to guide you :)
If you want to use distinct you have to write a custom class that implements IEqualityComparer
I'm not positive but I recall that by default it compares at the class HashCode which in your case is different since it's diffrent objects getting compared.
uCommerce multiple shipping address per customer/member
Hi,
I'm using uCommerce 6.7.2 for Umbraco 7.2.6 and have searched high and low on the forum for adding multiple shipping addresses per customer/member.
I have a scenario where the returning customer is already an Umbraco Member (and signed in) and when they visit the Address page of the order process, I want to retrieve all previous shipping addresses that the customer has used in the past. At this point, the member is invited to select an address or "Enter a new address" which will then save the one that they enter for next time.
I can't figure out where in the API docs this is?
I can see in "_Address.cshtml":
... which retrieves the previously used shipping address (if there is one), however, I want to return a list of all shipping addresses that matches against the currently logged in member.
Can someone please help?
Thanks,
Rick
Hi Rick,
Will give you the default shipping address set on your current basket. If you want to fetch all previous shipping addresses that a Umbraco Member has placed.
So you have to do a custom Query against uCommerce where you fetch all orders where Customer.MemberId is equal to the current logged in member.
You can do this in different ways but simpliest will be using PurchaseOrder.All().Where().
If you need more directions please say so and I will try to guide you :)
Best regards Martin
Hi Martin,
This is great - thanks - here is what I have so far:
As you can see I am getting the Shipment address from the order and adding it to my own list.
However, when I call the Distinct() method, it is still getting all shipment addresses - even duplicate shipping addresses.
Thanks,
Rick
Hi Rick,
If you want to use distinct you have to write a custom class that implements IEqualityComparer
I'm not positive but I recall that by default it compares at the class HashCode which in your case is different since it's diffrent objects getting compared.
Best regards Martin
Hi Martin,
Thanks very much for the pointers - for anyone else that needs this:
I created my custom address comparer in a separate class:
You can see from the above that I wanted to match on postcode and email address.
Then I am doing the following to get distinct addresses:
Thanks again,
Rick
Hi Rick,
Glad to hear that the pointers guided you. H5YR! for posting your solution to help others.
Cheers!
Best regards Martin
is working on a reply...