AngularJS: Calculating the sum of values in a 2d array model
I have a complex form model which holds a sale order. The model has the following construction:
order {
id: int,
lines: [], // array of orderLine objects
}
orderLine {
id: int,
lineItems: [], // array of lineItem objects
}
lineItem {
id: int,
sku: {},
material: {},
skuModel: {},
}
sku {
id: int,
name: '',
retailPrice: float,
dynamicPricing: bool,
materials: [],
models: [],
}
The price of Sku's can be either the retailPrice or calculated based on the material and model depending whether dynamicPricing is set to true. I've written the following code to calculate the sub total of the sku's:
$scope.subTotal = function (lineIndex, index) {
if ($scope.order.lines[lineIndex].lineItems[index].material == null
|| $scope.order.lines[lineIndex].lineItems[index].skuModel == null) {
return 0;
}
var total = $scope.order.lines[lineIndex].lineItems[index].material.unitPrice
* $scope.order.lines[lineIndex].lineItems[index].skuModel.unitValue;
return total;
};
See the HTML below. THIS WORKS! When I select the material and model the price is correctly calculate and renders on the page.
Although I'm not 100% sure whether my if statement is correct, maybe someone advices a better method?
Now to the big problem.
I'm unable to calculate the total. So I want to calculate the sum of all the sku's prices (dynamic or not) of all the lines in the order. Here's the code I got:
$scope.total = function () {
var total = 0;
console.log($scope.order.lines);
for (var i = 0; i < $scope.order.lines.length; i++) {
console.log($scope.order.lines[i]);
angular.forEach ($scope.order.lines[i].lineItems, function (lineItem) {
if (lineItem.sku.dynamicPricing) {
if (lineItem.material == null || lineItem.skuModel == null) {
console.log("found null in material or skuModel");
return 0;
}
total = total + lineItem.material.unitPrice * lineItem.skuModel.unitValue;
} else {
total = total + lineItem.sku.retailPrice;
}
});
};
return total;
};
This console output:
- Resource {id: 1, name: "ProductEen", defaultSku: Object, optionalSkus: Array[4], $promise: Object…}
- [Object]
- [Object]
- line found
- Object {id: null, product: Resource, lineItems: Array[5], $$hashKey: "024"}
- [Object]
- line found
- Object {id: null, product: Resource, lineItems: Array[5], $$hashKey: "024"}
- [Object]
- line found
- Object {id: null, product: Resource, lineItems: Array[5], $$hashKey: "024"}
- [Object]
- line found
- Object {id: null, product: Resource, lineItems: Array[5], $$hashKey: "024"}
The function just outputs null on the HTML and the function ends successful.
To provide the complete code here is the function that adds the product to the model and the HTML.
$scope.selectProduct = function (row) {
$scope.product = Product.get({id: row.entity.id});
$scope.product.$promise.then(function (data) {
var orderLine = {id: null, product: data, lineItems: []};
var item = {id: null, sku: null, material: null, skuModel: null};
item.sku = orderLine.product.defaultSku;
for (var i = 0; i < orderLine.product.optionalSkus.length; i++) {
var item = {id: null, sku: null, material: null, skuModel: null};
item.sku = orderLine.product.optionalSkus[i];
orderLine.lineItems.push(item);
}
$scope.order.lines.push(orderLine);
console.log($scope.order.lines);
});
$('#saveProductModal').modal('hide');
};
<table>
<thead>
<tr>
<th class="text-center">QTY</th>
<th>ITEM</th>
<th>DESCRIPTION</th>
<th>PRICE</th>
<th>SUBTOTAL</th>
</tr>
</thead>
<tbody ng-repeat="orderLine in order.lines">
<tr>
<td class="text-center"><strong>1</strong>{{$index}}</td>
<td colspan="3">
{{orderLine.product.name}}
</td>
<td id="subTotalProduct($index)"></td>
</tr>
<tr ng-repeat="lineItem in orderLine.lineItems" ng-init="lineIdx = $parent.$index">
<td></td>
<td>
{{lineItem.sku.name}}
</td>
<td>
<select ng-show="lineItem.sku.dynamicPricing" ng-model="order.lines[$parent.$index].lineItems[$index].material" ng-options="material as material.name for material in lineItem.sku.materials"></select>
<select ng-show="lineItem.sku.dynamicPricing" ng-model="order.lines[$parent.$index].lineItems[$index].skuModel" ng-options="skuModel as skuModel.name for skuModel in lineItem.sku.skuModels"></select>
</td>
<td ng-if="!lineItem.sku.dynamicPricing">
{{lineItem.sku.retailPrice}}
</td>
<td ng-if="lineItem.sku.dynamicPricing">
{{subTotal(lineIdx, $index)}}
</td>
<td ng-if="!lineItem.sku.dynamicPricing">
{{lineItem.sku.retailPrice}}
</td>
<td ng-if="lineItem.sku.dynamicPricing">
<!-- {{calculateSubTotal($parent.$index, $index)}} -->
</td>
</tr>
</tbody>
<tbody>
<tr>
<td colspan="3">
<button class="btn btn-primary btn-xs" ng-click="openProductModal()">
<span class="glyphicon glyphicon-flash"></span> Add Product
</button>
</td>
</tr>
<tr>
<td colspan="4">Total</td>
<td><strong>{{total()}}</strong></td>
</tr>
<tr>
<td colspan="4">HST/GST</td>
<td><strong>21%</strong></td>
</tr>
</tbody>
</table>
console.log(JSON.stringify($scope.order)
:
{"id":null,"lines":[{"id":null,"product":{"id":1,"name":"ProductEen","defaultSku":{"id":1,"name":"SkuEen","retailPrice":9.99,"dynamicPricing":true,"available":true,"sellable":true,"materials":[{"id":1,"name":"MaterialEen","unitPrice":1.99,"unitOfMeasurement":{"id":1,"symbol":"G","name":"Gram"}},{"id":1,"name":"MaterialEen","unitPrice":1.99,"unitOfMeasurement":{"id":1,"symbol":"G","name":"Gram"}},{"id":1,"name":"MaterialEen","unitPrice":1.99,"unitOfMeasurement":{"id":1,"symbol":"G","name":"Gram"}},{"id":1,"name":"MaterialEen","unitPrice":1.99,"unitOfMeasurement":{"id":1,"symbol":"G","name":"Gram"}},{"id":1,"name":"MaterialEen","unitPrice":1.99,"unitOfMeasurement":{"id":1,"symbol":"G","name":"Gram"}},{"id":5,"name":"Material5","unitPrice":1.99,"unitOfMeasurement":{"id":5,"symbol":"M3","name":"Kubieke Meter"}},{"id":5,"name":"Material5","unitPrice":1.99,"unitOfMeasurement":{"id":5,"symbol":"M3","name":"Kubieke Meter"}},{"id":5,"name":"Material5","unitPrice":1.99,"unitOfMeasurement":{"id":5,"symbol":"M3","name":"Kubieke Meter"}},{"id":5,"name":"Material5","unitPrice":1.99,"unitOfMeasurement":{"id":5,"symbol":"M3","name":"Kubieke Meter"}},{"id":5,"name":"Material5","unitPrice":1.99,"unitOfMeasurement":{"id":5,"symbol":"M3","name":"Kubieke Meter"}},{"id":7,"name":"Material7","unitPrice":1.99,"unitOfMeasurement":{"id":5,"symbol":"M3","name":"Kubieke Meter"}},{"id":7,"name":"Material7","unitPrice":1.99,"unitOfMeasurement":{"id":5,"symbol":"M3","name":"Kubieke Meter"}},{"id":7,"name":"Material7","unitPrice":1.99,"unitOfMeasurement":{"id":5,"symbol":"M3","name":"Kubieke Meter"}},{"id":7,"name":"Material7","unitPrice":1.99,"unitOfMeasurement":{"id":5,"symbol":"M3","name":"Kubieke Meter"}},{"id":7,"name":"Material7","unitPrice":1.99,"unitOfMeasurement":{"id":5,"symbol":"M3","name":"Kubieke Meter"}},{"id":20,"name":"Material20","unitPrice":1.99,"unitOfMeasurement":{"id":3,"symbol":"M","name":"Meter"}},{"id":20,"name":"Material20","unitPrice":1.99,"unitOfMeasurement":{"id":3,"symbol":"M","name":"Meter"}},{"id":20,"name":"Material20","unitPrice":1.99,"unitOfMeasurement":{"id":3,"symbol":"M","name":"Meter"}},{"id":20,"name":"Material20","unitPrice":1.99,"unitOfMeasurement":{"id":3,"symbol":"M","name":"Meter"}},{"id":20,"name":"Material20","unitPrice":1.99,"unitOfMeasurement":{"id":3,"symbol":"M","name":"Meter"}},{"id":24,"name":"Material24","unitPrice":1.99,"unitOfMeasurement":{"id":6,"symbol":"Stuk","name":"Per Stuk"}},{"id":24,"name":"Material24","unitPrice":1.99,"unitOfMeasurement":{"id":6,"symbol":"Stuk","name":"Per Stuk"}},{"id":24,"name":"Material24","unitPrice":1.99,"unitOfMeasurement":{"id":6,"symbol":"Stuk","name":"Per Stuk"}},{"id":24,"name":"Material24","unitPrice":1.99,"unitOfMeasurement":{"id":6,"symbol":"Stuk","name":"Per Stuk"}},{"id":24,"name":"Material24","unitPrice":1.99,"unitOfMeasurement":{"id":6,"symbol":"Stuk","name":"Per Stuk"}}],"skuModels":[{"id":1,"name":"ProductEenModel","width":null,"length":null,"height":null,"weight":null,"unitValue":95,"unitOfMeasurement":{"id":5,"symbol":"M3","name":"Kubieke Meter"}},{"id":5,"name":"Product5Model","width":null,"length":null,"height":null,"weight":null,"unitValue":95,"unitOfMeasurement":{"id":5,"symbol":"M3","name":"Kubieke Meter"}},{"id":7,"name":"Product7Model","width":null,"length":null,"height":null,"weight":null,"unitValue":95,"unitOfMeasurement":{"id":5,"symbol":"M3","name":"Kubieke Meter"}},{"id":20,"name":"Product20Model","width":null,"length":null,"height":null,"weight":null,"unitValue":95,"unitOfMeasurement":{"id":5,"symbol":"M3","name":"Kubieke Meter"}},{"id":24,"name":"Product24Model","width":null,"length":null,"height":null,"weight":null,"unitValue":95,"unitOfMeasurement":{"id":5,"symbol":"M3","name":"Kubieke Meter"}},{"id":1,"name":"ProductEenModel","width":null,"length":null,"height":null,"weight":null,"unitValue":95,"unitOfMeasurement":{"id":5,"symbol":"M3","name":"Kubieke Meter"}},{"id":5,"name":"Product5Model","width":null,"length":null,"height":null,"weight":null,"unitValue":95,"unitOfMeasurement":{"id":5,"symbol":"M3","name":"Kubieke Meter"}},{"id":7,"name":"Product7Model","width":null,"length":null,"height":null,"weight":null,"unitValue":95,"unitOfMeasurement":{"id":5,"symbol":"M3","name":"Kubieke Meter"}},{"id":20,"name":"Product20Model","width":null,"length":null,"height":null,"weight":null,"unitValue":95,"unitOfMeasurement":{"id":5,"symbol":"M3","name":"Kubieke Meter"}},{"id":24,"name":"Product24Model","width":null,"length":null,"height":null,"weight":null,"unitValue":95,"unitOfMeasurement":{"id":5,"symbol":"M3","name":"Kubieke Meter"}},{"id":1,"name":"ProductEenModel","width":null,"length":null,"height":null,"weight":null,"unitValue":95,"unitOfMeasurement":{"id":5,"symbol":"M3","name":"Kubieke Meter"}},{"id":5,"name":"Product5Model","width":null,"length":null,"height":null,"weight":null,"unitValue":95,"unitOfMeasurement":{"id":5,"symbol":"M3","name":"Kubieke Meter"}},{"id":7,"name":"Product7Model","width":null,"length":null,"height":null,"weight":null,"unitValue":95,"unitOfMeasurement":{"id":5,"symbol":"M3","name":"Kubieke Meter"}},{"id":20,"name":"Product20Model","width":null,"length":null,"height":null,"weight":null,"unitValue":95,"unitOfMeasurement":{"id":5,"symbol":"M3","name":"Kubieke Meter"}},{"id":24,"name":"Product24Model","width":null,"length":null,"height":null,"weight":null,"unitValue":95,"unitOfMeasurement":{"id":5,"symbol":"M3","name":"Kubieke Meter"}},{"id":1,"name":"ProductEenModel","width":null,"length":null,"height":null,"weight":null,"unitValue":95,"unitOfMeasurement":{"id":5,"symbol":"M3","name":"Kubieke Meter"}},{"id":5,"name":"Product5Model","width":null,"length":null,"height":null,"weight":null,"unitValue":95,"unitOfMeasurement":{"id":5,"symbol":"M3","name":"Kubieke Meter"}},{"id":7,"name":"Product7Model","width":null,"length":null,"height":null,"weight":null,"unitValue":95,"unitOfMeasurement":{"id":5,"symbol":"M3","name":"Kubieke Meter"}},{"id":20,"name":"Product20Model","width":null,"length":null,"height":null,"weight":null,"unitValue":95,"unitOfMeasurement":{"id":5,"symbol":"M3","name":"Kubieke Meter"}},{"id":24,"name":"Product24Model","width":null,"length":null,"height":null,"weight":null,"unitValue":95,"unitOfMeasurement":{"id":5,"symbol":"M3","name":"Kubieke Meter"}},{"id":1,"name":"ProductEenModel","width":null,"length":null,"height":null,"weight":null,"unitValue":95,"unitOfMeasurement":{"id":5,"symbol":"M3","name":"Kubieke Meter"}},{"id":5,"name":"Product5Model","width":null,"length":null,"height":null,"weight":null,"unitValue":95,"unitOfMeasurement":{"id":5,"symbol":"M3","name":"Kubieke Meter"}},{"id":7,"name":"Product7Model","width":null,"length":null,"height":null,"weight":null,"unitValue":95,"unitOfMeasurement":{"id":5,"symbol":"M3","name":"Kubieke Meter"}},{"id":20,"name":"Product20Model","width":null,"length":null,"height":null,"weight":null,"unitValue":95,"unitOfMeasurement":{"id":5,"symbol":"M3","name":"Kubieke Meter"}},{"id":24,"name":"Product24Model","width":null,"length":null,"height":null,"weight":null,"unitValue":95,"unitOfMeasurement":{"id":5,"symbol":"M3","name":"Kubieke Meter"}}]},"optionalSkus":[{"id":24,"name":"Sku24","retailPrice":9.99,"dynamicPricing":false,"available":true,"sellable":true,"materials":[],"skuModels":[]},{"id":5,"name":"Sku5","retailPrice":9.99,"dynamicPricing":false,"available":true,"sellable":true,"materials":[],"skuModels":[]},{"id":20,"name":"Sku20","retailPrice":9.99,"dynamicPricing":false,"available":true,"sellable":true,"materials":[],"skuModels":[]},{"id":7,"name":"Sku7","retailPrice":9.99,"dynamicPricing":false,"available":true,"sellable":true,"materials":[],"skuModels":[]}],"$promise":{},"$resolved":true},"lineItems":[{"id":null,"sku":{"id":1,"name":"SkuEen","retailPrice":9.99,"dynamicPricing":true,"available":true,"sellable":true,"materials":[{"id":1,"name":"MaterialEen","unitPrice":1.99,"unitOfMeasurement":{"id":1,"symbol":"G","name":"Gram"}},{"id":1,"name":"MaterialEen","unitPrice":1.99,"unitOfMeasurement":{"id":1,"symbol":"G","name":"Gram"}},{"id":1,"name":"MaterialEen","unitPrice":1.99,"unitOfMeasurement":{"id":1,"symbol":"G","name":"Gram"}},{"id":1,"name":"MaterialEen","unitPrice":1.99,"unitOfMeasurement":{"id":1,"symbol":"G","name":"Gram"}},{"id":1,"name":"MaterialEen","unitPrice":1.99,"unitOfMeasurement":{"id":1,"symbol":"G","name":"Gram"}},{"id":5,"name":"Material5","unitPrice":1.99,"unitOfMeasurement":{"id":5,"symbol":"M3","name":"Kubieke Meter"}},{"id":5,"name":"Material5","unitPrice":1.99,"unitOfMeasurement":{"id":5,"symbol":"M3","name":"Kubieke Meter"}},{"id":5,"name":"Material5","unitPrice":1.99,"unitOfMeasurement":{"id":5,"symbol":"M3","name":"Kubieke Meter"}},{"id":5,"name":"Material5","unitPrice":1.99,"unitOfMeasurement":{"id":5,"symbol":"M3","name":"Kubieke Meter"}},{"id":5,"name":"Material5","unitPrice":1.99,"unitOfMeasurement":{"id":5,"symbol":"M3","name":"Kubieke Meter"}},{"id":7,"name":"Material7","unitPrice":1.99,"unitOfMeasurement":{"id":5,"symbol":"M3","name":"Kubieke Meter"}},{"id":7,"name":"Material7","unitPrice":1.99,"unitOfMeasurement":{"id":5,"symbol":"M3","name":"Kubieke Meter"}},{"id":7,"name":"Material7","unitPrice":1.99,"unitOfMeasurement":{"id":5,"symbol":"M3","name":"Kubieke Meter"}},{"id":7,"name":"Material7","unitPrice":1.99,"unitOfMeasurement":{"id":5,"symbol":"M3","name":"Kubieke Meter"}},{"id":7,"name":"Material7","unitPrice":1.99,"unitOfMeasurement":{"id":5,"symbol":"M3","name":"Kubieke Meter"}},{"id":20,"name":"Material20","unitPrice":1.99,"unitOfMeasurement":{"id":3,"symbol":"M","name":"Meter"}},{"id":20,"name":"Material20","unitPrice":1.99,"unitOfMeasurement":{"id":3,"symbol":"M","name":"Meter"}},{"id":20,"name":"Material20","unitPrice":1.99,"unitOfMeasurement":{"id":3,"symbol":"M","name":"Meter"}},{"id":20,"name":"Material20","unitPrice":1.99,"unitOfMeasurement":{"id":3,"symbol":"M","name":"Meter"}},{"id":20,"name":"Material20","unitPrice":1.99,"unitOfMeasurement":{"id":3,"symbol":"M","name":"Meter"}},{"id":24,"name":"Material24","unitPrice":1.99,"unitOfMeasurement":{"id":6,"symbol":"Stuk","name":"Per Stuk"}},{"id":24,"name":"Material24","unitPrice":1.99,"unitOfMeasurement":{"id":6,"symbol":"Stuk","name":"Per Stuk"}},{"id":24,"name":"Material24","unitPrice":1.99,"unitOfMeasurement":{"id":6,"symbol":"Stuk","name":"Per Stuk"}},{"id":24,"name":"Material24","unitPrice":1.99,"unitOfMeasurement":{"id":6,"symbol":"Stuk","name":"Per Stuk"}},{"id":24,"name":"Material24","unitPrice":1.99,"unitOfMeasurement":{"id":6,"symbol":"Stuk","name":"Per Stuk"}}],"skuModels":[{"id":1,"name":"ProductEenModel","width":null,"length":null,"height":null,"weight":null,"unitValue":95,"unitOfMeasurement":{"id":5,"symbol":"M3","name":"Kubieke Meter"}},{"id":5,"name":"Product5Model","width":null,"length":null,"height":null,"weight":null,"unitValue":95,"unitOfMeasurement":{"id":5,"symbol":"M3","name":"Kubieke Meter"}},{"id":7,"name":"Product7Model","width":null,"length":null,"height":null,"weight":null,"unitValue":95,"unitOfMeasurement":{"id":5,"symbol":"M3","name":"Kubieke Meter"}},{"id":20,"name":"Product20Model","width":null,"length":null,"height":null,"weight":null,"unitValue":95,"unitOfMeasurement":{"id":5,"symbol":"M3","name":"Kubieke Meter"}},{"id":24,"name":"Product24Model","width":null,"length":null,"height":null,"weight":null,"unitValue":95,"unitOfMeasurement":{"id":5,"symbol":"M3","name":"Kubieke Meter"}},{"id":1,"name":"ProductEenModel","width":null,"length":null,"height":null,"weight":null,"unitValue":95,"unitOfMeasurement":{"id":5,"symbol":"M3","name":"Kubieke Meter"}},{"id":5,"name":"Product5Model","width":null,"length":null,"height":null,"weight":null,"unitValue":95,"unitOfMeasurement":{"id":5,"symbol":"M3","name":"Kubieke Meter"}},{"id":7,"name":"Product7Model","width":null,"length":null,"height":null,"weight":null,"unitValue":95,"unitOfMeasurement":{"id":5,"symbol":"M3","name":"Kubieke Meter"}},{"id":20,"name":"Product20Model","width":null,"length":null,"height":null,"weight":null,"unitValue":95,"unitOfMeasurement":{"id":5,"symbol":"M3","name":"Kubieke Meter"}},{"id":24,"name":"Product24Model","width":null,"length":null,"height":null,"weight":null,"unitValue":95,"unitOfMeasurement":{"id":5,"symbol":"M3","name":"Kubieke Meter"}},{"id":1,"name":"ProductEenModel","width":null,"length":null,"height":null,"weight":null,"unitValue":95,"unitOfMeasurement":{"id":5,"symbol":"M3","name":"Kubieke Meter"}},{"id":5,"name":"Product5Model","width":null,"length":null,"height":null,"weight":null,"unitValue":95,"unitOfMeasurement":{"id":5,"symbol":"M3","name":"Kubieke Meter"}},{"id":7,"name":"Product7Model","width":null,"length":null,"height":null,"weight":null,"unitValue":95,"unitOfMeasurement":{"id":5,"symbol":"M3","name":"Kubieke Meter"}},{"id":20,"name":"Product20Model","width":null,"length":null,"height":null,"weight":null,"unitValue":95,"unitOfMeasurement":{"id":5,"symbol":"M3","name":"Kubieke Meter"}},{"id":24,"name":"Product24Model","width":null,"length":null,"height":null,"weight":null,"unitValue":95,"unitOfMeasurement":{"id":5,"symbol":"M3","name":"Kubieke Meter"}},{"id":1,"name":"ProductEenModel","width":null,"length":null,"height":null,"weight":null,"unitValue":95,"unitOfMeasurement":{"id":5,"symbol":"M3","name":"Kubieke Meter"}},{"id":5,"name":"Product5Model","width":null,"length":null,"height":null,"weight":null,"unitValue":95,"unitOfMeasurement":{"id":5,"symbol":"M3","name":"Kubieke Meter"}},{"id":7,"name":"Product7Model","width":null,"length":null,"height":null,"weight":null,"unitValue":95,"unitOfMeasurement":{"id":5,"symbol":"M3","name":"Kubieke Meter"}},{"id":20,"name":"Product20Model","width":null,"length":null,"height":null,"weight":null,"unitValue":95,"unitOfMeasurement":{"id":5,"symbol":"M3","name":"Kubieke Meter"}},{"id":24,"name":"Product24Model","width":null,"length":null,"height":null,"weight":null,"unitValue":95,"unitOfMeasurement":{"id":5,"symbol":"M3","name":"Kubieke Meter"}},{"id":1,"name":"ProductEenModel","width":null,"length":null,"height":null,"weight":null,"unitValue":95,"unitOfMeasurement":{"id":5,"symbol":"M3","name":"Kubieke Meter"}},{"id":5,"name":"Product5Model","width":null,"length":null,"height":null,"weight":null,"unitValue":95,"unitOfMeasurement":{"id":5,"symbol":"M3","name":"Kubieke Meter"}},{"id":7,"name":"Product7Model","width":null,"length":null,"height":null,"weight":null,"unitValue":95,"unitOfMeasurement":{"id":5,"symbol":"M3","name":"Kubieke Meter"}},{"id":20,"name":"Product20Model","width":null,"length":null,"height":null,"weight":null,"unitValue":95,"unitOfMeasurement":{"id":5,"symbol":"M3","name":"Kubieke Meter"}},{"id":24,"name":"Product24Model","width":null,"length":null,"height":null,"weight":null,"unitValue":95,"unitOfMeasurement":{"id":5,"symbol":"M3","name":"Kubieke Meter"}}]},"material":null,"skuModel":null,"$$hashKey":"03D"},{"id":null,"sku":{"id":24,"name":"Sku24","retailPrice":9.99,"dynamicPricing":false,"available":true,"sellable":true,"materials":[],"skuModels":[]},"material":null,"skuModel":null,"$$hashKey":"03E"},{"id":null,"sku":{"id":5,"name":"Sku5","retailPrice":9.99,"dynamicPricing":false,"available":true,"sellable":true,"materials":[],"skuModels":[]},"material":null,"skuModel":null,"$$hashKey":"03F"},{"id":null,"sku":{"id":20,"name":"Sku20","retailPrice":9.99,"dynamicPricing":false,"available":true,"sellable":true,"materials":[],"skuModels":[]},"material":null,"skuModel":null,"$$hashKey":"03G"},{"id":null,"sku":{"id":7,"name":"Sku7","retailPrice":9.99,"dynamicPricing":false,"available":true,"sellable":true,"materials":[],"skuModels":[]},"material":null,"skuModel":null,"$$hashKey":"03H"}],"$$hashKey":"03B"}]}
lineItem.dynamicPricing
. Shouldn't it belineItem.sku.dynamicPricing
? Also, I don't see a skuModel property on the lineItem that you defined at the top. – Jerrad May 27 '14 at 17:15lineItem.sku.material.unitPrice
, butlineItem.sku
doesn't have a material property. It has a materials property, but it's an array, so it wouldn't have a unitPrice property. It would be really helpful if you could post a Plunker or JSFiddle. – Jerrad May 27 '14 at 18:53console.log(JSON.stringify($scope.order))
at the beginning of thetotal
function, and paste the results here? – Jerrad May 27 '14 at 19:38