Skip to content

Instantly share code, notes, and snippets.

View allenmichael's full-sized avatar

Allen-Michael Grobelny allenmichael

  • Amazon Web Services
  • Austin, TX
  • X @amsxbg
View GitHub Profile
@allenmichael
allenmichael / instocksnippet.cs
Last active October 22, 2015 19:00
Get a Instock Notifications Collection and use LINQ to locate all notifications with a ProductCode matching what you specify and log the email address of the user owning that notification.
var instockResource = new Mozu.Api.Resources.Commerce.InStockNotificationSubscriptionResource(_apiContext);
var notifications = instockResource.GetInStockNotificationSubscriptionsAsync().Result;
var notificationsForProduct = notifications.Items.Where(x => x.ProductCode == "MS-BTL-002-1");
foreach(var notification in notificationsForProduct)
{
Console.WriteLine(notification.Email);
}
@allenmichael
allenmichael / GetAllProducts.cs
Created October 23, 2015 18:56
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>
@allenmichael
allenmichael / embedded.commerce.orders.action.before.js
Created November 6, 2015 22:24
Logging the order model from Arc.js
module.exports = function(context, callback) {
console.log(context.get.order().items);
callback();
};
@allenmichael
allenmichael / searchResults.cs
Created December 10, 2015 16:58
Adding a custom field.
[TestMethod]
public void Search_Results()
{
var searchTuningResource = new Mozu.Api.Resources.Commerce.Catalog.Admin.SearchResource(_apiContext);
var settings = searchTuningResource.GetSettingsAsync().Result;
settings.SiteSearchSettings[0].CustomFields.Add(
new SiteSearchRelevancyCustomField()
{
@allenmichael
allenmichael / FulfillDigitial.cs
Last active December 10, 2015 21:41
Fulfill digital items on an Order
[TestMethod]
public void Fulfill_Digital_Order()
{
var orderResource = new Mozu.Api.Resources.Commerce.OrderResource(_apiContext);
var orderCollection = orderResource.GetOrdersAsync(filter: "orderNumber eq 393").Result;
var orderId = orderCollection.Items.Count > 0 ? orderCollection.Items[0].Id : null;
if (orderId != null)
{
@allenmichael
allenmichael / catalogSubnav.cs
Last active December 10, 2015 21:53
Add subnavlink to catalog parent page
public class SubnavLink
{
public string parentId { get; set; }
public string[] path { get; set; }
public string href { get; set; }
public string appId { get; set; }
public string windowTitle { get; set; }
}
[TestMethod]
@allenmichael
allenmichael / deleteSubnavlinks.cs
Created December 10, 2015 21:32
Delete all entities from subnavlinks
@allenmichael
allenmichael / DigitalPackage.cs
Created December 10, 2015 21:42
Create a digital package
var order = orderResource.GetOrderAsync(orderId).Result;
var digitalPackageResource = new Mozu.Api.Resources.Commerce.Orders.DigitalPackageResource(_apiContext);
var digitalPackageItem = new Mozu.Api.Contracts.CommerceRuntime.Fulfillment.DigitalPackageItem()
{
ProductCode = order.Items[0].Product.ProductCode,
Quantity = order.Items[0].Quantity
};
var digitalPackage = new Mozu.Api.Contracts.CommerceRuntime.Fulfillment.DigitalPackage()
@allenmichael
allenmichael / arcjsUnitTestExample.js
Created December 23, 2015 19:23
An example of creating a unit test for an Arc.js action
/**
* This is a scaffold for unit tests for the custom function for
* `embedded.commerce.carts.addItem.before`.
* Modify the test conditions below. You may:
* - add special assertions for code actions from Simulator.assert
* - create a mock context with Simulator.context() and modify it
* - use and modify mock Mozu business objects from Simulator.fixtures
*/
'use strict';
@allenmichael
allenmichael / gruntTaskArcjs.js
Created December 23, 2015 19:23
A Grunt task to add to your Gruntfile.js
grunt.registerTask('delActionDomain', 'Deleting the specified action domain...', function(actionDomainName) {
//Load the Yeoman file as a variable
var yoFile = grunt.file.readJSON('./.yo-rc.json');
//Always delete dist folder and functions.json -- grunt build will recreate these files using manifests
grunt.file.delete('./assets/dist');
grunt.file.delete('./assets/functions.json');
if(actionDomainName) {
//Delete domain folder
grunt.file.delete('./assets/src/domains/' + actionDomainName);
//Retrieve each action listed in the Yeoman file