2011-11-16 1 views
0

Ubercart order.tpl.php 파일의 각 stdClass 객체 [title]별로이 배열을 정렬하려고합니다. 나는 정상적인 정렬을 시도했지만 모든 것이 stdClass 객체이기 때문에 아무것도하지 않는다.stdClass 객체로 배열 정렬

function sortByTitle($a, $b){ 
    return strcmp($a->title, $b->title); 
} 

usort($theArray, 'sortByTitle'); 

당신은 어떤하게 확인 던져 할 수 있습니다 :

<pre>Array 
(
[0] => stdClass Object 
    (
     [order_product_id] => 1157 
     [order_id] => 142 
     [nid] => 38 
     [title] => Eatonville Forest Camping Permit 
     [manufacturer] => 
     [model] => eatonville-camp-permit 
     [qty] => 1 
     [cost] => 9.00000 
     [price] => 10.00000 
     [weight] => 0 
     [data] => Array 
      (
       [attributes] => Array 
        (
        ) 

       [shippable] => 0 
       [restrict_qty] => 1 
       [module] => uc_product 
      ) 

     [order_uid] => 13 
    ) 

[1] => stdClass Object 
    (
     [order_product_id] => 1158 
     [order_id] => 142 
     [nid] => 35 
     [title] => Eatonville Forest Motorized Recreation Access Permit and Release of Liability 
     [manufacturer] => 
     [model] => eatonville-motor-rec-access 
     [qty] => 1 
     [cost] => 175.00000 
     [price] => 175.00000 
     [weight] => 0 
     [data] => Array 
      (
       [attributes] => Array 
        (
        ) 

       [shippable] => 1 
       [restrict_qty] => 1 
       [module] => uc_product 
      ) 

     [order_uid] => 13 
    ) 

[2] => stdClass Object 
    (
     [order_product_id] => 1159 
     [order_id] => 142 
     [nid] => 31 
     [title] => Snoqualmie Forest Non-motorized Recreation Access Permit for Families and Release of Liability 
     [manufacturer] => 
     [model] => snoqualmie-family-non-motor-rec-access 
     [qty] => 1 
     [cost] => 150.00000 
     [price] => 150.00000 
     [weight] => 0 
     [data] => Array 
      (
       [attributes] => Array 
        (
        ) 

       [shippable] => 1 
       [restrict_qty] => 1 
       [module] => uc_product 
      ) 

     [order_uid] => 13 
    ) 

[3] => stdClass Object 
    (
     [order_product_id] => 1160 
     [order_id] => 142 
     [nid] => 40 
     [title] => Snoqualmie Forest Camping Permit 
     [manufacturer] => 
     [model] => snoqualmie-camp-permit 
     [qty] => 1 
     [cost] => 300.00000 
     [price] => 300.00000 
     [weight] => 0 
     [data] => Array 
      (
       [attributes] => Array 
        (
        ) 

       [shippable] => 1 
       [restrict_qty] => 1 
       [module] => uc_product 
      ) 

     [order_uid] => 13 
    ) 

[4] => stdClass Object 
    (
     [order_product_id] => 1161 
     [order_id] => 142 
     [nid] => 39 
     [title] => White River Forest Camping Permit 
     [manufacturer] => 
     [model] => whiteriver-camp-permit 
     [qty] => 1 
     [cost] => 300.00000 
     [price] => 300.00000 
     [weight] => 0 
     [data] => Array 
      (
       [attributes] => Array 
        (
        ) 

       [shippable] => 1 
       [restrict_qty] => 1 
       [module] => uc_product 
      ) 

     [order_uid] => 13 
    ) 

[5] => stdClass Object 
    (
     [order_product_id] => 1162 
     [order_id] => 142 
     [nid] => 30 
     [title] => White River Forest Family Non-motorized Recreation Access Permit for Families and Release of Liability 
     [manufacturer] => 
     [model] => whiteriver-family-non-motor-rec-access 
     [qty] => 1 
     [cost] => 150.00000 
     [price] => 150.00000 
     [weight] => 0 
     [data] => Array 
      (
       [attributes] => Array 
        (
        ) 

       [shippable] => 1 
       [restrict_qty] => 1 
       [module] => uc_product 
      ) 

     [order_uid] => 13 
    ) 

[6] => stdClass Object 
    (
     [order_product_id] => 1163 
     [order_id] => 142 
     [nid] => 33 
     [title] => White River Forest Non-motorized Recreation Access Permit for Individuals and Release of Liability 
     [manufacturer] => 
     [model] => whiteriver-non-motor-rec-access 
     [qty] => 1 
     [cost] => 75.00000 
     [price] => 75.00000 
     [weight] => 0 
     [data] => Array 
      (
       [attributes] => Array 
        (
        ) 

       [shippable] => 1 
       [restrict_qty] => 1 
       [module] => uc_product 
      ) 

     [order_uid] => 13 
    ) 

[7] => stdClass Object 
    (
     [order_product_id] => 1164 
     [order_id] => 142 
     [nid] => 34 
     [title] => Snoqualmie Forest Non-motorized Recreation Access Permit for Individuals and Release of Liability 
     [manufacturer] => 
     [model] => snoqualmie-non-motor-rec-access 
     [qty] => 1 
     [cost] => 75.00000 
     [price] => 75.00000 
     [weight] => 0 
     [data] => Array 
      (
       [attributes] => Array 
        (
        ) 

       [shippable] => 1 
       [restrict_qty] => 1 
       [module] => uc_product 
      ) 

     [order_uid] => 13 
    ) 
)</pre> 

<pre>php if (is_array($order->products)) { 
         $context = array(
          'revision' => 'formatted', 
          'type' => 'order_product', 
          'subject' => array(
          'order' => $order, 
         ), 
         ); 
} 
</pre> 

답변

2

내가 usort() 작동합니다 생각 order.tpl.php에서 제어 코드 title 회원이 실제로 존재하는지 확인하십시오.

+0

작동합니다! 대단히 감사합니다. – xeraseth