Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,9 @@ shopify.metafield.create({
- `update(productId, id, params)`
- productListing
- `count()`
- `get(id)`
- `create(productId[, params])`
- `delete(productId)`
- `get(productId)`
- `list([params])`
- `productIds([params])`
- productVariant
Expand Down
20 changes: 15 additions & 5 deletions resources/product-listing.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,21 @@ function ProductListing(shopify) {
this.key = 'product_listing';
}

assign(ProductListing.prototype, omit(base, [
'create',
'delete',
'update'
]));
assign(ProductListing.prototype, omit(base, ['create', 'update']));

/**
* Creates a product listing.
*
* @param {Number} productId The ID of the product to publish
* @param {Object} [params] Body parameters
* @return {Promise} Promise that resolves with the result
* @public
*/
ProductListing.prototype.create = function create(productId, params) {
params || (params = { product_id: productId });
const url = this.buildUrl(productId);
return this.shopify.request(url, 'PUT', this.key, params);
};

/**
* Retrieves product IDs that are published to a particular application.
Expand Down
1 change: 1 addition & 0 deletions test/fixtures/product-listing/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
'use strict';

exports.req = require('./req');
exports.res = require('./res');
5 changes: 5 additions & 0 deletions test/fixtures/product-listing/req/create.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"product_listing": {
"product_id": 921728736
}
}
3 changes: 3 additions & 0 deletions test/fixtures/product-listing/req/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
'use strict';

exports.create = require('./create');
59 changes: 59 additions & 0 deletions test/fixtures/product-listing/res/create.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
{
"product_listing": {
"id": 2616506,
"shop_id": 690933842,
"product_id": 921728736,
"channel_id": 1003355581,
"created_at": "2017-10-03T16:36:00-04:00",
"updated_at": "2017-10-03T16:36:00-04:00",
"body_html": "<p>The iPod Touch has the iPhone's multi-touch interface, with a physical home button off the touch screen. The home screen has a list of buttons for the available applications.</p>",
"handle": "ipod-touch",
"product_type": "Cult Products",
"published": true,
"published_at": "2017-08-31T20:00:00-04:00",
"tags": "",
"title": "IPod Touch 8GB",
"vendor": "Apple",
"public_url": "http://apple.myshopify.com/products/ipod-touch",
"variants": [
{
"id": 447654529,
"product_id": 921728736,
"title": "Black",
"price": "199.00",
"sku": "IPOD2009BLACK",
"position": 1,
"grams": 567,
"inventory_policy": "continue",
"compare_at_price": null,
"fulfillment_service": "manual",
"inventory_management": "shopify",
"option1": "Black",
"option2": null,
"option3": null,
"created_at": "2017-10-03T16:36:00-04:00",
"updated_at": "2017-10-03T16:36:00-04:00",
"taxable": true,
"barcode": "1234_black",
"image_id": null,
"inventory_quantity": 13,
"weight": 1.25,
"weight_unit": "lb",
"old_inventory_quantity": 13,
"requires_shipping": true
}
],
"options": [
{
"id": 891236591,
"product_id": 921728736,
"name": "Title",
"position": 1,
"values": [
"Black"
]
}
],
"images": []
}
}
1 change: 1 addition & 0 deletions test/fixtures/product-listing/res/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
'use strict';

exports.productIds = require('./product-ids');
exports.create = require('./create');
exports.list = require('./list');
exports.get = require('./get');
35 changes: 34 additions & 1 deletion test/product-listing.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ describe('Shopify#productListing', () => {
.then(data => expect(data).to.equal(2));
});

it('gets a product listing by its ID', () => {
it('gets a specific product listing', () => {
const output = fixtures.res.get;

scope
Expand All @@ -74,4 +74,37 @@ describe('Shopify#productListing', () => {
return shopify.productListing.get(921728736)
.then(data => expect(data).to.deep.equal(output.product_listing));
});

it('creates a product listing (1/2)', () => {
const input = fixtures.req.create;
const output = fixtures.res.create;

scope
.put('/admin/product_listings/921728736.json', input)
.reply(200, output);

return shopify.productListing.create(921728736)
.then(data => expect(data).to.deep.equal(output.product_listing));
});

it('creates a product listing (2/2)', () => {
const input = fixtures.req.create;
const output = fixtures.res.create;

scope
.put('/admin/product_listings/921728736.json', input)
.reply(200, output);

return shopify.productListing.create(921728736, input.product_listing)
.then(data => expect(data).to.deep.equal(output.product_listing));
});

it('deletes a product listing', () => {
scope
.delete('/admin/product_listings/921728736.json')
.reply(200);

return shopify.productListing.delete(921728736)
.then(data => expect(data).to.deep.equal({}));
});
});