I’ve allowed myself to add some tweaks here and there:
<script>
    var _paq = _paq || [];
    var orderDetails = {{ ecommerce object }};
    var products = orderDetails.purchase.products;
    var order_id = orderDetails.purchase.actionField.id;
    var grand_total = orderDetails.purchase.actionField.revenue;
	var tax = parseInt(orderDetails.purchase.actionField.tax);
	var shipping = orderDetails.purchase.actionField.shipping;
  	
    products.forEach(function(product){
      _paq.push(["addEcommerceItem",product.id.toString(), product.name, product.category, product.price, product.quantity])
  
  });
    _paq.push(["trackEcommerceOrder",order_id, grand_total,, tax, shipping,]);
  </script>
Please note:
- I’ve used parseInt()to change tax from string to number;
- You don’t need to capture product attributes since we are operating on the whole products objects.
Please give it a try and let me know if it works 