Skip to content

Commit

Permalink
Merged in master and added an example to product-variant-model's form…
Browse files Browse the repository at this point in the history
…attedPrice
  • Loading branch information
mikkoh committed Sep 22, 2016
2 parents 222fcc4 + 6d0f5e2 commit a0d9c3e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
11 changes: 11 additions & 0 deletions src/models/product-variant-model.js
Expand Up @@ -71,6 +71,17 @@ const ProductVariantModel = BaseModel.extend({
return this.attrs.variant.price;
},

/**
* Price of variant, formatted according to shop currency format string.
* For instance `"$10.00"`
*
* @property formattedPrice
* @type {String}
*/
get formattedPrice() {
return this.attrs.variant.formatted_price;
},

/**
* Variant weight in grams. If no weight is defined grams will be `0`.
* @property grams
Expand Down
4 changes: 3 additions & 1 deletion tests/unit/models/product-variant-test.js
Expand Up @@ -33,6 +33,7 @@ const baseAttrs = {
title: 'Long / Less than tons',
compare_at_price: null,
price: '3.00',
formatted_price: '$3.00',
grams: 1000,
available: true,
option_values: [
Expand Down Expand Up @@ -68,14 +69,15 @@ test('it extends from BaseModel', function (assert) {
});

test('it proxies to a composite of product and variant state', function (assert) {
assert.expect(9);
assert.expect(10);

assert.equal(model.id, baseAttrs.variant.id);
assert.equal(model.productId, baseAttrs.product.id);
assert.equal(model.title, baseAttrs.variant.title);
assert.equal(model.productTitle, baseAttrs.product.title);
assert.equal(model.compareAtPrice, baseAttrs.variant.compare_at_price);
assert.equal(model.price, baseAttrs.variant.price);
assert.equal(model.formattedPrice, baseAttrs.variant.formatted_price);
assert.equal(model.grams, baseAttrs.variant.grams);
assert.equal(model.available, baseAttrs.variant.available);
assert.deepEqual(model.optionValues, baseAttrs.variant.option_values);
Expand Down

0 comments on commit a0d9c3e

Please sign in to comment.