Skip to content

Instantly share code, notes, and snippets.

View Mozu-CS's full-sized avatar

Mozu CS Mozu-CS

  • Volusion Inc.
  • 1835 Kramer Ln #100, Austin, TX 78758
View GitHub Profile
@Mozu-CS
Mozu-CS / AddAttributeListOption.cs
Last active December 9, 2015 07:49
Creating a Mozu Product Attribute List Option
public void Add_A_Product_Attribute_List_Option()
{
//enter your context info
var apiContext = new Mozu.Api.ApiContext(tenantId: 14617, masterCatalogId: 1, catalogId: 1);
//create a new attribute resource
var attributeResource = new Mozu.Api.Resources.Commerce.Catalog.Admin.Attributedefinition.AttributeResource(apiContext);
//define the attribute name
var attributeName = "Purse-Size";
@Mozu-CS
Mozu-CS / ImportCustomers_CompleteExample.cs
Last active December 9, 2015 07:47
Create Mozu Customer Accounts From A DataTable
private System.Collections.Concurrent.ConcurrentDictionary<string,string> ImportCustomers(IEnumerable<Mozu.Api.Contracts.Customer.CustomerAccountAndAuthInfo> accountAuthCollection)
{
var accountResource = new Mozu.Api.Resources.Commerce.Customer.CustomerAccountResource(_apiContext);
var contactResource = new Mozu.Api.Resources.Commerce.Customer.Accounts.CustomerContactResource(_apiContext);
var accountExternalIds = new System.Collections.Concurrent.ConcurrentDictionary<string, string>();
Parallel.ForEach(accountAuthCollection, new System.Threading.Tasks.ParallelOptions() { MaxDegreeOfParallelism = 1 }, accountAuthInfo =>
{
var filter = string.Format("ExternalId eq '{0}'", accountAuthInfo.Account.ExternalId);
@Mozu-CS
Mozu-CS / ImportCustomers.cs
Created December 8, 2015 19:24
A method organizing other calls to import customers into Mozu
private System.Collections.Concurrent.ConcurrentDictionary<string,string> ImportCustomers(IEnumerable<Mozu.Api.Contracts.Customer.CustomerAccountAndAuthInfo> accountAuthCollection)
{
var accountResource = new Mozu.Api.Resources.Commerce.Customer.CustomerAccountResource(_apiContext);
var contactResource = new Mozu.Api.Resources.Commerce.Customer.Accounts.CustomerContactResource(_apiContext);
var accountExternalIds = new System.Collections.Concurrent.ConcurrentDictionary<string, string>();
Parallel.ForEach(accountAuthCollection, new System.Threading.Tasks.ParallelOptions() { MaxDegreeOfParallelism = 1 }, accountAuthInfo =>
{
var filter = string.Format("ExternalId eq '{0}'", accountAuthInfo.Account.ExternalId);
@Mozu-CS
Mozu-CS / MapCustomerAccount.cs
Created December 8, 2015 20:44
Method for mapping customer account data to a customer object.
private Mozu.Api.Contracts.Customer.CustomerAccount MapCustomerAccount(System.Data.DataRow drAccount)
{
var mappedAccount = new Mozu.Api.Contracts.Customer.CustomerAccount()
{
ExternalId = drAccount["Id"].ToString(),
EmailAddress = drAccount["Email"].ToString(),
FirstName = drAccount["FirstName"].ToString(),
LastName = drAccount["LastNameOrSurname"].ToString(),
CompanyOrOrganization = drAccount["CompanyOrOrganization"].ToString(),
TaxExempt = Convert.ToBoolean(drAccount["TaxExempt"]),
@Mozu-CS
Mozu-CS / MapCustomerLoginInfo.cs
Created December 8, 2015 20:45
Method for mapping customer login info to a customer object
private Mozu.Api.Contracts.Customer.CustomerLoginInfo MapCustomerLoginInfo(System.Data.DataRow drAccount)
{
var mappedAccountAndAuthInfo = new Mozu.Api.Contracts.Customer.CustomerLoginInfo()
{
IsImport = true,
EmailAddress = drAccount["Email"].ToString(),
Password = drAccount["Password"].ToString(),
Username = drAccount["Username"].ToString(),
};
@Mozu-CS
Mozu-CS / MapCustomerContact.cs
Created December 8, 2015 20:45
Method for mapping a customer contact to a customer object
private Mozu.Api.Contracts.Customer.CustomerContact MapCustomerContact(System.Data.DataRow drContact)
{
var mappedContact = new Mozu.Api.Contracts.Customer.CustomerContact()
{
CompanyOrOrganization = drContact["CompanyOrOrganization"].ToString(),
Email = drContact["Email"].ToString(),
FaxNumber = drContact["FaxNumber"].ToString(),
FirstName = drContact["FirstName"].ToString(),
LastNameOrSurname = drContact["LastNameOrSurname"].ToString(),
MiddleNameOrInitial = drContact["MiddleNameOrInitial"].ToString(),
@Mozu-CS
Mozu-CS / GetAccountTestData.cs
Created December 8, 2015 20:47
Method used for retrieving test data that then gets mapped to a customer object in Mozu
private System.Data.DataTable GetAccountTestData()
{
var tblAccount = new System.Data.DataTable();
tblAccount.Columns.Add("Id");
tblAccount.Columns.Add("AccountID");
tblAccount.Columns.Add("UserName");
tblAccount.Columns.Add("Email");
tblAccount.Columns.Add("Password");
tblAccount.Columns.Add("FirstName");
tblAccount.Columns.Add("LastNameOrSurname");
@Mozu-CS
Mozu-CS / GetContactTestData.cs
Created December 8, 2015 20:48
Method for retrieving test data that then gets mapped to a customer object in Mozu
private System.Data.DataTable GetContactTestData()
{
var tblContact = new System.Data.DataTable();
tblContact.Columns.Add("Id");
tblContact.Columns.Add("Type");
tblContact.Columns.Add("IsPrimary");
tblContact.Columns.Add("CompanyOrOrganization");
tblContact.Columns.Add("FirstName");
tblContact.Columns.Add("MiddleNameorInitial");
tblContact.Columns.Add("LastNameOrSurname");
@Mozu-CS
Mozu-CS / MainTestMethod_AddCustomer.cs
Last active December 16, 2015 23:13
A unit test that displays the various customer import methods at work
[TestMethod]
public void Add_Customer_Accounts_Test()
{
var tblAccounts = GetAccountTestData();
var tblContacts = GetContactTestData();
var accountAndAuths = new List<Mozu.Api.Contracts.Customer.CustomerAccountAndAuthInfo>();
foreach(System.Data.DataRow drAcct in tblAccounts.Rows)
{
var customerLoginInfo = MapCustomerLoginInfo(drAcct);
@Mozu-CS
Mozu-CS / GetAllProducts.cs
Created December 8, 2015 20:53
A Mozu extension method for ProductResource to retrieve all products from a master catalog
namespace MozuExtensions
{
public static class MozuExtensions
{
/// <summary>
/// Retrieves all products from the master catalog using the tenant that was supplied when Mozu.Api.Resources.Commerce.Catalog.Admin.ProductResource was created.
/// <para />
/// Accepts an optional pageSize parameter -- pageSize is set to 200 by default.
/// </summary>
/// <param name="productResource"></param>