skill.getState()

To get the current shopper and page state you can run skill.getState(). For example, to get the current product's ID being looked at you can write: skill.getState().product_id

{
"location": -{
"country_name": "United States",
"country_code": "US",
"region_name": "California",
"region_code": "CA",
"city_name": "Newport Beach",
"city": "Newport Beach",
"latitude": 33.6206839,
"longitude": 117.9065403
},
"session_time": 100,
"time_on_current_page": 50,
"inactive_time_on_current_page": 50,
"interaction_time": 200,
"time_since_first_seen": 500,
"current_page": -{
"url": "https://www.example.com",
"referrer": "https://www.twitter.com",
"title": "Test Page Title"
},
"section": "product_view",
"product_id": "123456789",
"cart": -{
"item_count": 2,
"currency": "USD",
"total": 100,
"total_weight": 2,
"total_discount": 0,
"items": -[
-{
"price": 50,
"total": 50,
"product_id": 123456789,
"variant_id": 987654321,
"quantity": 1
},
-{
"price": 25,
"total": 50,
"product_id": 1234567890,
"variant_id": 9876543210,
"quantity": 2
}
]
}
}

Sample Code: Flash Add To Cart Button if Cart Empty

This sample will flash the add to cart button 3 times if the cart state contains fewer than 1 items (ie if it is empty).

var FeraSkill = function(skill) {
var $addToCartBtn;
var init = function() {
// Locate the add to cart button.
$addToCartBtn = $('form button[type="submit"][name="add"]');
};
/**
* If the cart contains fewer than 1 items (ie, it is empty)
* then flash the add to cart button
*/
this.run = function () {
var cart = skill.getState().cart;
if (cart.item_count < 1) {
flashAddToCartButton();
}
};
/**
* Flash the add to cart button 3 times
*/
var flashAddToCartButton = function() {
$addToCartBtn.fadeOut().fadeIn().fadeOut().fadeIn().fadeOut().fadeIn();
}
init();
};