producteca-sdk
Advanced tools
Comparing version 0.0.36 to 0.0.37
@@ -0,0 +0,0 @@ (function() { |
@@ -0,0 +0,0 @@ (function() { |
@@ -123,3 +123,3 @@ (function() { | ||
Adjustment.prototype.productData = function() { | ||
return _.omit(_.omit(this, ['price', 'prices', 'stock', 'stocks', 'identifier', 'sku', 'name']), _.isFunction); | ||
return _.omit(_.omit(this, ['price', 'prices', 'stock', 'stocks', 'identifier', 'sku', 'name', 'pictures', 'code']), _.isFunction); | ||
}; | ||
@@ -126,0 +126,0 @@ |
@@ -11,10 +11,9 @@ (function() { | ||
AdjustmentToNewProductTransformer.prototype.transform = function(adjustment) { | ||
var product, variation; | ||
product = adjustment.productData(); | ||
product.description = product.description || adjustment.name; | ||
if (this.settings.identifier === "sku") { | ||
product.sku = adjustment.identifier; | ||
} | ||
product.prices = adjustment.forEachPrice((function(_this) { | ||
AdjustmentToNewProductTransformer.prototype.transform = function(adjustments) { | ||
var firstAdjustment, product; | ||
firstAdjustment = adjustments[0]; | ||
product = firstAdjustment.productData(); | ||
product.description = product.description || firstAdjustment.name; | ||
product.sku = this.settings.identifier === "sku" ? firstAdjustment.identifier : firstAdjustment.code; | ||
product.prices = firstAdjustment.forEachPrice((function(_this) { | ||
return function(value, priceList) { | ||
@@ -30,19 +29,23 @@ if (priceList == null) { | ||
})(this)); | ||
variation = { | ||
stocks: adjustment.forEachStock((function(_this) { | ||
return function(stock, warehouse) { | ||
if (warehouse == null) { | ||
warehouse = _this.settings.warehouse; | ||
} | ||
return { | ||
quantity: stock, | ||
warehouse: warehouse | ||
}; | ||
product.variations = adjustments.map((function(_this) { | ||
return function(adjustment) { | ||
var variation; | ||
variation = { | ||
pictures: adjustment.pictures, | ||
stocks: adjustment.forEachStock(function(stock, warehouse) { | ||
if (warehouse == null) { | ||
warehouse = _this.settings.warehouse; | ||
} | ||
return { | ||
quantity: stock, | ||
warehouse: warehouse | ||
}; | ||
}) | ||
}; | ||
})(this)) | ||
}; | ||
if (this.settings.identifier === "barcode") { | ||
variation.barcode = adjustment.identifier; | ||
} | ||
product.variations = [variation]; | ||
if (_this.settings.identifier === "barcode") { | ||
variation.barcode = adjustment.identifier; | ||
} | ||
return variation; | ||
}; | ||
})(this)); | ||
return product; | ||
@@ -49,0 +52,0 @@ }; |
@@ -10,7 +10,14 @@ (function() { | ||
it("should create a product with sku when the identifier is set as sku", function() { | ||
var adjustment, transformer; | ||
adjustment = new Adjustment({ | ||
identifier: "915004085101 ", | ||
name: "COLGANTE CLEMENT 3 X E27 MÁX. 23W NEGRO TELA " | ||
}); | ||
var adjustments, transformer; | ||
adjustments = [ | ||
new Adjustment({ | ||
identifier: "915004085101 ", | ||
name: "COLGANTE CLEMENT 3 X E27 MÁX. 23W NEGRO TELA ", | ||
pictures: [ | ||
{ | ||
url: "http://pictures.com" | ||
} | ||
] | ||
}) | ||
]; | ||
transformer = new Transformer({ | ||
@@ -21,3 +28,3 @@ identifier: "sku", | ||
}); | ||
return transformer.transform(adjustment).should.eql({ | ||
return transformer.transform(adjustments).should.eql({ | ||
description: "COLGANTE CLEMENT 3 X E27 MÁX. 23W NEGRO TELA", | ||
@@ -33,2 +40,7 @@ sku: "915004085101", | ||
{ | ||
pictures: [ | ||
{ | ||
url: "http://pictures.com" | ||
} | ||
], | ||
stocks: [ | ||
@@ -44,8 +56,15 @@ { | ||
}); | ||
it("should create a product with barcode when the identifier is set as sku", function() { | ||
var adjustment, transformer; | ||
adjustment = new Adjustment({ | ||
identifier: "915004085101 ", | ||
name: "COLGANTE CLEMENT 3 X E27 MÁX. 23W NEGRO TELA " | ||
}); | ||
it("should create a product with barcode when the identifier is set as barcode", function() { | ||
var adjustments, transformer; | ||
adjustments = [ | ||
new Adjustment({ | ||
identifier: "915004085101 ", | ||
name: "COLGANTE CLEMENT 3 X E27 MÁX. 23W NEGRO TELA ", | ||
pictures: [ | ||
{ | ||
url: "http://pictures.com" | ||
} | ||
] | ||
}) | ||
]; | ||
transformer = new Transformer({ | ||
@@ -56,4 +75,5 @@ identifier: "barcode", | ||
}); | ||
return transformer.transform(adjustment).should.eql({ | ||
return transformer.transform(adjustments).should.eql({ | ||
description: "COLGANTE CLEMENT 3 X E27 MÁX. 23W NEGRO TELA", | ||
sku: void 0, | ||
prices: [ | ||
@@ -68,2 +88,7 @@ { | ||
barcode: "915004085101", | ||
pictures: [ | ||
{ | ||
url: "http://pictures.com" | ||
} | ||
], | ||
stocks: [ | ||
@@ -79,24 +104,119 @@ { | ||
}); | ||
return it("should create a product with prices", function() { | ||
var adjustment, transformer; | ||
adjustment = new Adjustment({ | ||
identifier: "915004085101 ", | ||
name: "COLGANTE CLEMENT 3 X E27 MÁX. 23W NEGRO TELA ", | ||
it("should create a product with prices", function() { | ||
var adjustments, transformer; | ||
adjustments = [ | ||
new Adjustment({ | ||
identifier: "915004085101 ", | ||
name: "COLGANTE CLEMENT 3 X E27 MÁX. 23W NEGRO TELA ", | ||
pictures: [ | ||
{ | ||
url: "http://pictures.com" | ||
} | ||
], | ||
prices: [ | ||
{ | ||
priceList: "Mayorista", | ||
value: 50 | ||
}, { | ||
priceList: "Minorista", | ||
value: 70 | ||
} | ||
] | ||
}) | ||
]; | ||
transformer = new Transformer({ | ||
identifier: "sku", | ||
warehouse: "Default" | ||
}); | ||
return transformer.transform(adjustments).should.eql({ | ||
description: "COLGANTE CLEMENT 3 X E27 MÁX. 23W NEGRO TELA", | ||
sku: "915004085101", | ||
prices: [ | ||
{ | ||
priceList: "Mayorista", | ||
value: 50 | ||
amount: 50 | ||
}, { | ||
priceList: "Minorista", | ||
value: 70 | ||
amount: 70 | ||
} | ||
], | ||
variations: [ | ||
{ | ||
pictures: [ | ||
{ | ||
url: "http://pictures.com" | ||
} | ||
], | ||
stocks: [ | ||
{ | ||
warehouse: "Default", | ||
quantity: 0 | ||
} | ||
] | ||
} | ||
] | ||
}); | ||
}); | ||
return it("can create a product definition with variations", function() { | ||
var adjustments, product, transformer; | ||
adjustments = [ | ||
new Adjustment({ | ||
code: "12345", | ||
identifier: "915004085101 ", | ||
name: "COLGANTE CLEMENT 3 X E27 MÁX. 23W NEGRO TELA ", | ||
pictures: [ | ||
{ | ||
url: "http://picture1.com" | ||
} | ||
], | ||
prices: [ | ||
{ | ||
priceList: "Mayorista", | ||
value: 50 | ||
}, { | ||
priceList: "Minorista", | ||
value: 70 | ||
} | ||
], | ||
stocks: [ | ||
{ | ||
warehouse: "Default", | ||
quantity: 3 | ||
} | ||
] | ||
}), new Adjustment({ | ||
code: "12345", | ||
identifier: "915004085102 ", | ||
name: "COLGANTE CLEMENT 3 X E27 MÁX. 23W NEGRO TELA ", | ||
pictures: [ | ||
{ | ||
url: "http://picture2.com" | ||
} | ||
], | ||
prices: [ | ||
{ | ||
priceList: "Mayorista", | ||
value: 50 | ||
}, { | ||
priceList: "Minorista", | ||
value: 70 | ||
} | ||
], | ||
stocks: [ | ||
{ | ||
warehouse: "Default", | ||
quantity: 4 | ||
} | ||
] | ||
}) | ||
]; | ||
transformer = new Transformer({ | ||
identifier: "sku", | ||
identifier: "barcode", | ||
warehouse: "Default" | ||
}); | ||
return transformer.transform(adjustment).should.eql({ | ||
product = transformer.transform(adjustments); | ||
console.log(product); | ||
return product.should.eql({ | ||
description: "COLGANTE CLEMENT 3 X E27 MÁX. 23W NEGRO TELA", | ||
sku: "915004085101", | ||
sku: "12345", | ||
prices: [ | ||
@@ -113,8 +233,27 @@ { | ||
{ | ||
pictures: [ | ||
{ | ||
url: "http://picture1.com" | ||
} | ||
], | ||
stocks: [ | ||
{ | ||
warehouse: "Default", | ||
quantity: 0 | ||
quantity: 3 | ||
} | ||
] | ||
], | ||
barcode: "915004085101" | ||
}, { | ||
pictures: [ | ||
{ | ||
url: "http://picture2.com" | ||
} | ||
], | ||
stocks: [ | ||
{ | ||
warehouse: "Default", | ||
quantity: 4 | ||
} | ||
], | ||
barcode: "915004085102" | ||
} | ||
@@ -121,0 +260,0 @@ ] |
@@ -186,7 +186,17 @@ (function() { | ||
Syncer.prototype._createProducts = function(unlinkeds) { | ||
var transformer; | ||
var adjustments, groupedAdjustmentsObj, noCodeAdjustments, transformer, withCodeAdjustments, _ref; | ||
transformer = new AdjustmentToNewProductTransformer(this.settings); | ||
return unlinkeds.map((function(_this) { | ||
return function(unlinked) { | ||
return _this.productecaApi.createProduct(transformer.transform(unlinked.adjustment)); | ||
adjustments = unlinkeds.map(function(it) { | ||
return it.adjustment; | ||
}); | ||
groupedAdjustmentsObj = _.groupBy(adjustments, 'code'); | ||
noCodeAdjustments = (_ref = groupedAdjustmentsObj[void 0]) != null ? _ref.map(function(it) { | ||
return [it]; | ||
}) : void 0; | ||
withCodeAdjustments = _.values(_.omit(groupedAdjustmentsObj, function(it) { | ||
return it === void 0; | ||
})); | ||
return withCodeAdjustments.concat(noCodeAdjustments || []).map((function(_this) { | ||
return function(adjustments) { | ||
return _this.productecaApi.createProduct(transformer.transform(adjustments)); | ||
}; | ||
@@ -193,0 +203,0 @@ })(this)); |
@@ -289,2 +289,3 @@ (function() { | ||
description: "Campera de lana para losers", | ||
sku: void 0, | ||
prices: [ | ||
@@ -299,2 +300,3 @@ { | ||
barcode: "NuevoProducto", | ||
pictures: void 0, | ||
stocks: [ | ||
@@ -301,0 +303,0 @@ { |
@@ -8,3 +8,3 @@ { | ||
}, | ||
"version": "0.0.36", | ||
"version": "0.0.37", | ||
"main": "build/sdk.js", | ||
@@ -11,0 +11,0 @@ "dependencies": { |
# Producteca SDK |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
80221
1438