sorting the order table in the email

  • Posts: 102
  • Thank you received: 0
13 years 2 months ago #24726

hi nicolas, i am trying to sort the order table in the emails so i can subdivide by category and i wanted to take a look at the variable $data->cart->products
but when i use var_dump it breaks the order process. is it not possible to use this function in the emails?

thanks

Please Log in or Create an account to join the conversation.

  • Posts: 102
  • Thank you received: 0
13 years 2 months ago #24728

nevermind i got it to work with print_r

Please Log in or Create an account to join the conversation.

  • Posts: 102
  • Thank you received: 0
13 years 2 months ago #24729

so trying to use sort_mult to sort the table but i get an error that i cant sort a stdclass object. this is the code i used

function array_sort_by_column(&$arr, $col, $dir = SORT_ASC) {
$sort_col = array();
foreach ($arr as $key=> $row) {
$sort_col[$key] = $row[$col];
}

array_multisort($sort_col, $dir, $arr);
}


array_sort_by_column($data->cart->products,'order_product_code');

how do i go about sorting this table?
Liz

Please Log in or Create an account to join the conversation.

  • Posts: 82868
  • Thank you received: 13377
  • MODERATOR
13 years 2 months ago #24730

You should try like that:

function array_sort_by_column(&$arr, $col) {
$sort_col = array();
foreach ($arr as $key=> $row) {
$sort_col[$row->$col] = $row;
}

sort($sort_col);
$arr = $sort_col;
}

array_sort_by_column($data->cart->products, 'order_product_code');

Please Log in or Create an account to join the conversation.

  • Posts: 102
  • Thank you received: 0
13 years 2 months ago #24731

hi nicolas thanks for the help. now i get the following error

Parse error: syntax error, unexpected $end ....

here is my template code:

<div style="background-color: #ffffff; font-family: Verdana, Arial, Helvetica, sans-serif;font-size:12px; color: #000000; width: 100%;">
<table style="margin: auto;font-family: Verdana, Arial, Helvetica, sans-serif;font-size:12px;" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td height="10">
</td>
</tr>
<tr>
<td>
<br/>
<br/>
<?php
$url = HIKASHOP_LIVE.'administrator/index.php?option=com_hikashop&ctrl=order&task=edit&order_id='.$data->order_id;
//echo JText::sprintf('ORDER_STATUS_CHANGED',$data->mail_status)."<br/><br/>".JText::sprintf('NOTIFICATION_OF_ORDER_ON_WEBSITE',$data->order_number,HIKASHOP_LIVE);
$currency = hikashop_get('class.currency');
$url = '<a href="'.$url.'" target="_blank">'.$url.'</a>';
echo "<br/>".JText::sprintf('ACCESS_ORDER_WITH_LINK',$url);
if($data->order_payment_method=='creditcard' && !empty($data->credit_card_info->cc_number)){
echo "<br/>".JText::_('CUSTOMER_PAID_WITH_CREDIT_CARD');
if(!empty($data->credit_card_info->cc_owner)){
echo "<br/>".JText::_('CREDIT_CARD_OWNER').' : '.$data->credit_card_info->cc_owner;
}
echo "<br/>".JText::_('END_OF_CREDIT_CARD_NUMBER').' : '.substr($data->credit_card_info->cc_number,8);
if(!empty($data->credit_card_info->cc_CCV)){
echo "<br/>".JText::_('CARD_VALIDATION_CODE').' : '.$data->credit_card_info->cc_CCV;
}
echo "<br/>".JText::_('CREDITCARD_WARNING');
} ?>
<br><br>
<table width="100%" style="border: 1px solid #DDDDDD;font-family: Verdana, Arial, Helvetica, sans-serif;font-size:12px;">
<?php
$params = null;
$js = '';
$fieldsClass = hikashop_get('class.field');
$template = trim(hikashop_getLayout('address','address_template',$params,$js));
if(!empty($data->cart->billing_address)){
$billing = $template;
foreach($data->cart->fields as $field){
$fieldname = $field->field_namekey;
$billing=str_replace('{'.$fieldname.'}',$fieldsClass->show($field,$data->cart->billing_address->$fieldname),$billing);
}
echo '<tr><td><strong>';
echo str_replace(array("\r\n","\r","\n"),'--',preg_replace('#{(?:(?!}).)*}#i','',$billing)).'</strong></td></tr>';
}
if(!empty($data->cart->order_shipping_id) && !empty($data->cart->shipping_address)){
$shipping = $template;
foreach($data->cart->fields as $field){
$fieldname = $field->field_namekey;
$shipping=str_replace('{'.$fieldname.'}',$fieldsClass->show($field,$data->cart->shipping_address->$fieldname),$shipping);
}
echo '<tr><td style="font-weight:bold;background-color:#DDDDDD">'.JText::_('HIKASHOP_SHIPPING_ADDRESS').'</td></tr><tr><td>';
echo str_replace(array("\r\n","\r","\n"),'<br/>',preg_replace('#{(?:(?!}).)*}#i','',$shipping)).'<br/></td></tr>';
}?>
</table>
<?php

$fieldsClass = hikashop_get('class.field');
$fields = $fieldsClass->getFields('frontcomp',$data,'order','');
foreach($fields as $fieldName => $oneExtraField) {
if(!empty($data->$fieldName)) echo "<br/>".$fieldsClass->trans($oneExtraField->field_realname).' : '.$fieldsClass->show($oneExtraField,$data->$fieldName);
}
$class = hikashop_get('class.order');
$url = $data->order_number;
$config =& hikashop_config();
if($config->get('simplified_registration',0)!=2){
$url .= ' ( '.$data->order_url.' )';
}
$data->cart = $class->loadFullOrder($data->order_id,true,false);
$data->cart->coupon = null;
$price = null;
$tax = $data->cart->order_subtotal - $data->cart->order_subtotal_no_vat;
$price->price_value = $data->order_full_price-$tax;
$price->price_value_with_tax = $data->order_full_price;
$data->cart->full_total = null;
$data->cart->full_total->prices = array($price);
$data->cart->coupon->discount_value =& $data->order_discount_price;
?>
</td>
</tr>
<tr>
<td height="10">
</td>
</tr>
<tr>
<td>
<table width="100%" style="font-family: Verdana, Arial, Helvetica, sans-serif;font-size:12px;border-bottom:1px solid black;">
<tr>
<td style="font-weight:bold;">
<?php echo JText::_('CART_PRODUCT_QUANTITY'); ?>
</td>
<td style="font-weight:bold;">
Unit
</td>
<td style="font-weight:bold;">
<?php echo 'Product Code'; ?>
</td>
<td style="font-weight:bold;">
<?php echo JText::_('CART_PRODUCT_NAME'); ?>
</td>
<td style="font-weight:bold;">
<?php echo JText::_('CART_PRODUCT_UNIT_PRICE'); ?>
</td>


<td style="font-weight:bold;text-align:right;">
<?php echo JText::_('HIKASHOP_TOTAL'); ?>
</td>
</tr>
<?php
if(hikashop_level(2)){
$fieldsClass = hikashop_get('class.field');
$null = null;
$itemFields = $fieldsClass->getFields('frontcomp',$null,'item');

//print_r($data->cart->products);

function array_sort_by_column(&$arr, $col) {
$sort_col = array();
foreach ($arr as $key=>$row) {
$sort_col[$row->$col]=$row;
}

sort($sort_col);
$arr = $sort_col;
}

$mynewarray=array_sort_by_column($data->cart->products,'order_product_code');


foreach($mynewarray as $item){
$price = $item->order_product_total_price_no_vat;
?>
<tr>
<td style="border-bottom:1px solid #ccc;">
<?php echo $item->order_product_quantity; ?>
</td>
<td style="border-bottom:1px solid #ccc;">
<?php /**lpw**/
$productClass = hikashop::get('class.product');
$product = $productClass->get($item->product_id);
echo $product->measurement;
/**lpw**/?>
</td>
<td style="border-bottom:1px solid #000;"><p><?php echo $item->order_product_code; ?></p></td>
<td style="border-bottom:1px solid #000;">
<p><?php echo $item->order_product_name; ?></p><?php
if(!empty($itemFields)){
foreach($itemFields as $field){
$namekey = $field->field_namekey;
if(empty($item->$namekey)) continue;
echo '<p>'.$fieldsClass->getFieldName($field).': '.$fieldsClass->show($field,$item->$namekey).'</p>';
}
} ?>
</td>
<td style="border-bottom:1px solid #000;">
<?php echo $currencyHelper->format($item->order_product_price,$data->order_currency_id); ?>
</td>


<td style="text-align:right;border-bottom:1px solid #000;">
<?php echo $currencyHelper->format($price,$data->order_currency_id); ?>
</td>
</tr>
<?php
}
if(bccomp($data->order_discount_price,0,5)){
echo '<tr><td colspan="4" style="text-align:right">'.JText::_('HIKASHOP_COUPON').' : '.$currencyHelper->format($data->order_discount_price,$data->order_currency_id).'</td></tr>';
}
if(bccomp($data->order_shipping_price,0,5)){
echo '<tr><td colspan="4" style="text-align:right">'.JText::_('HIKASHOP_SHIPPING_METHOD').' : '.$currencyHelper->format($data->order_shipping_price,$data->order_currency_id).'</td></tr>';
}
//echo '<tr><td colspan="5" style="text-align:right">'.JText::sprintf('TOTAL_WITHOUT_VAT',$currencyHelper->format($data->cart->full_total->prices[0]->price_value,$data->order_currency_id)).'</td></tr>';
echo '<tr><td colspan="5" style="text-align:right;font-weight:bold;">'.JText::sprintf('TOTAL_WITH_VAT',$currencyHelper->format($data->cart->full_total->prices[0]->price_value_with_tax,$data->order_currency_id)).'</td></tr>';
?>
</table>
</td>
</tr>
<tr>
<td height="10">
</td>
</tr>
<tr>
<td>

</td>
</tr>
<tr>
<td height="10">
</td>
</tr>
<tr>
<td height="10">
</td>
</tr>
<tr>
<td height="10">
</td>
</tr>
</tbody>
</table>
</div>

File Attachment:

File Name: notificati...late.zip
File Size:3 KB

Attachments:
Last edit: 13 years 2 months ago by MinnieMouse. Reason: code is hard to read i am attaching as file

Please Log in or Create an account to join the conversation.

  • Posts: 102
  • Thank you received: 0
13 years 2 months ago #24732

sorry an error was a typo, but this one is real...
Warning: Invalid argument supplied for foreach() in /home/rockridg/public_html/media/com_hikashop/mail/order_admin_notification.html.modified.php on line 136

Please Log in or Create an account to join the conversation.

  • Posts: 102
  • Thank you received: 0
13 years 2 months ago #24733

so that function returns no result.

Please Log in or Create an account to join the conversation.

  • Posts: 82868
  • Thank you received: 13377
  • MODERATOR
13 years 2 months ago #24734

Yes, that's normal. As you can see I didn't set any return variable. My function directly modifies the array given in the first parameter. So if you do :
array_sort_by_column($data->cart->products,'order_product_code');

you can just do your foreach on $data->cart->products after that

Please Log in or Create an account to join the conversation.

  • Posts: 102
  • Thank you received: 0
13 years 2 months ago #24735

maybe i am misunderstanding. i tried it both ways. with your strait function leaving my foreach the way it was (no result)
and i assigned a variable to array_sort_by_column($data->cart->products,'order_product_code'); and then used that in the foreach and again no result. so i am a little confused.

if i take the results from that function and plug them into my foreach shouldnt the table spit out as before but sorted?
but when i try to print the results of my array $data->cart->products into the function i get no result...

Please Log in or Create an account to join the conversation.

  • Posts: 82868
  • Thank you received: 13377
  • MODERATOR
13 years 2 months ago #24753

After looking a bit more at the code, it's not sort that should be used in the function but the function ksort. That might explain the problem you're having...

Please Log in or Create an account to join the conversation.

  • Posts: 102
  • Thank you received: 0
13 years 2 months ago #24789

yep... that worked...

Please Log in or Create an account to join the conversation.

Time to create page: 0.048 seconds
Powered by Kunena Forum