Пример #1
0
 /**
  * Adds product properties to analytics.track() when the order is completed successfully.
  *
  * @since  1.0.0
  * @access public
  *
  * @uses  func_get_args() Because our abstract class doesn't know how many parameters are passed to each hook
  *                        for each different platform, we use func_get_args().
  *
  * @return array Filtered array of name and properties for analytics.track().
  */
 public function completed_order()
 {
     $args = func_get_args();
     $track = $args[0];
     if (did_action('wpsc_transaction_results_shutdown') && isset($_GET['sessionid'])) {
         $log = new WPSC_Purchase_Log($_GET['sessionid'], 'sessionid');
         /* We like checking is_order_received(), as that's what the manual payment gateway uses. */
         if ($log->is_transaction_completed() || $log->is_order_received()) {
             $gateway_data = $log->get_gateway_data();
             $items = $log->get_cart_contents();
             $products = array();
             foreach ($items as $item) {
                 $product = array('id' => $item->prodid, 'sku' => wpsc_product_sku($item->prodid), 'name' => $item->name, 'price' => $item->price, 'quantity' => $item->quantity, 'category' => implode(', ', wp_list_pluck(wpsc_get_product_terms($item->prodid, 'wpsc_product_category'), 'name')));
                 $products[] = $product;
             }
             $track = array('event' => __('Completed Order', 'segment'), 'properties' => array('id' => $log->get('id'), 'total' => $log->get('totalprice'), 'revenue' => $gateway_data['subtotal'], 'shipping' => $gateway_data['shipping'], 'tax' => $gateway_data['tax'], 'products' => $products));
         }
     }
     return $track;
 }