@ChuckWatson ..my bad for not posting the javascript.
So here goes…
The _createLineItemList function creates each line item in the cart when the cart is created; and the cart is created whenever the cart page is loaded and whenever the cart is updated. So I reckon this is best place to tweak code.
_createLineItemList: function(state) {
return $.map(
state.items,
function(item, index) {
var $item = this.$itemTemplate.clone();
var $itemPriceList = this.$itemPriceListTemplate.clone();
this._setLineItemAttributes($item, item, index);
this._setLineItemImage($item, item.featured_image);
$(selectors.cartItemTitle, $item)
.text(item.product_title)
.attr('href', item.url);
var productDetailsList = this._createProductDetailsList(
item.product_has_only_default_variant,
item.options_with_values,
item.properties
);
this._setProductDetailsList($item, productDetailsList);
this._setItemRemove($item, item.title);
$itemPriceList.html(
this._createItemPrice(
item.original_price,
item.final_price,
this.$itemPriceListTemplate
)
);
if (item.unit_price_measurement) {
$itemPriceList.append(
this._createUnitPrice(
item.unit_price,
item.unit_price_measurement,
this.$itemPriceListTemplate
)
);
}
this._setItemPrice($item, $itemPriceList);
var itemDiscountList = this._createItemDiscountList(item);
this._setItemDiscountList($item, itemDiscountList);
this._setQuantityInputs($item, item, index);
//Added to manipulate weight
$("[data-cart-lineitem-weight]",$item).text( item.quantity * item.grams);
var itemLinePrice = this._createItemPrice(
item.original_line_price,
item.final_line_price,
this.$itemLinePriceTemplate
);
this._setItemLinePrice($item, itemLinePrice);
return $item[0];
}.bind(this)
);
},
I was playing around and thought may be this would work, although not sure if this is right way to update html content and honestly I am just shooting in the dark.
$(“[data-cart-lineitem-weight]”,$item).text( item.quantity * item.grams);
My corresponding HTML looks like this:
<dl>
<dd>
{%- assign my_variable = item.grams | times: item.quantity -%}
{{ my_variable | weight_with_unit }}
</dd>
</dl>