<commit_before><?php

/**
 * Additional template functions for Item lists.
 */
class OrderItemList extends Extension{
	
	function Quantity(){
		return $this->owner->Sum('Quantity');
	}
	
	function Plural(){
		return $this->Quantity() > 1;
	}
	
	function Sum($field){
		$total = 0;
		if($this->owner->exists()){
			foreach($this->owner as $item){
				$total += $item->$field;
			}
		}
		return $total;
	}<commit_msg>NEW: added ability to do sums with related Product fields for OrderItemList (extension of ComponentSet)<commit_after><?php
/**
 * Additional functions for Item lists.
 */
class OrderItemList extends Extension{
	
	function Quantity(){
		return $this->owner->Sum('Quantity');
	}
	
	function Plural(){
		return $this->Quantity() > 1;
	}
	
	/**
	 * Sums up all of desired field for items. Optionally sum product field instead.
	 * @param $field - field to sum
	 * @param boolean $onproduct - sum from product or not
	 * @return number total
	 */
	function Sum($field, $onproduct = false){
		$total = 0;
		if($this->owner->exists()){
			foreach($this->owner as $item){
				if(!$onproduct){
					$total += $item->$field;
				}elseif($product = $item->Product()){
					$total += $product->$field;
				}
			}
		}
		return $total;
	}
{'fraction_non_alphanumeric': 0.1606133979015335, 'fraction_numerical': 0.003228410008071025, 'mean_word_length': 3.4927536231884058, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5909978', 'n_tokens_mistral': 448, 'n_tokens_neox': 382, 'n_words': 113}