18 require_once SQ_INCLUDE_PATH.
'/asset.inc';
43 $this->_ser_attrs = TRUE;
44 parent::__construct($assetid);
61 if (!parent::_createAdditional($link))
return FALSE;
84 $keywords = parent::getAvailableKeywords();
86 $keywords[
'asset_attribute_summary'] =
'The summary of the Paypal order';
104 if ($keyword ==
'asset_attribute_summary') {
108 return parent::getKeywordReplacement($keyword);
121 $products = $this->
attr(
'products');
122 $products_string = Array();
124 foreach ($products as $product) {
125 $product_string = Array();
126 $product_number = ($product[
'number'] !=
'') ?
' (#'.$product[
'number'].
')' :
'';
127 $product_string[
'name'] = $product[
'name'].$product_number;
128 $product_string[
'quantity'] = sprintf(
'%d', $product[
'quantity']);
129 $product_string[
'price'] = sprintf(
'%01.2f', $product[
'price']);
130 $product_string[
'subtotal'] = sprintf(
'%01.2f', $product[
'subtotal']);
131 $products_string[] = $product_string;
134 $name_padding_len = $this->_getPaddingLength($products_string,
'name');
135 $quantity_padding_len = $this->_getPaddingLength($products_string,
'quantity');
136 $price_padding_len = $this->_getPaddingLength($products_string,
'price');
137 $subtotal_padding_len = $this->_getPaddingLength($products_string,
'subtotal');
139 $format =
"%-{$name_padding_len}s%-{$quantity_padding_len}s%-{$price_padding_len}s%-{$subtotal_padding_len}s\n";
140 $split_string = str_repeat(
'-', $name_padding_len + $quantity_padding_len + $price_padding_len + $subtotal_padding_len).
"\n";
143 $summary = sprintf($format,
'Name',
'Quantity',
'Price',
'Subtotal');
144 $summary .= $split_string;
147 foreach ($products_string as $product_string) {
148 $summary .= sprintf($format, $product_string[
'name'], $product_string[
'quantity'], $product_string[
'price'], $product_string[
'subtotal']);
152 $summary .= $split_string;
153 $total = sprintf(
'%01.2f', $this->
attr(
'total_amount')).
' '.$this->
attr(
'currency');
154 $summary .= sprintf($format,
'Total',
'',
'', $total);
156 return '<pre>'.htmlspecialchars($summary).
'</pre>';
169 private function _getPaddingLength($products_string, $index)
171 $max_length = strlen($index);
172 foreach ($products_string as $product_string) {
173 if (strlen($product_string[$index]) > $max_length) {
174 $max_length = strlen($product_string[$index]);
178 return $max_length + 2;