Advertisement
BakerMan

Basket Snoop: basketsnoop.php (revision 1)

Oct 17th, 2012
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.74 KB | None | 0 0
  1. class BasketSnoop extends AdminController {
  2.  
  3.     protected $shoppingdata = array();
  4.  
  5.     public function admin () {
  6.         // Load the shopping data and bring into scope
  7.         $this->loadshopping();
  8.         $data = $this->shoppingdata;
  9.  
  10.         // Display the data
  11.         include dirname(__FILE__).'/view.php';
  12.     }
  13.  
  14.     protected function loadshopping () {
  15.         $db = DB::instance();
  16.         $prefix = $db->table_prefix;
  17.  
  18.         // Run our query
  19.         $results = (array) DB::query("SELECT SQL_CALC_FOUND_ROWS
  20.        session, data, modified FROM {$prefix}shopp_shopping LIMIT 0, 10");
  21.  
  22.         // Extract the data
  23.         foreach ($results as $result)
  24.             $this->organizedata($result);
  25.     }
  26.  
  27.     protected function organizedata ( $result ) {
  28.         $result->data = unserialize($result->data);
  29.  
  30.         $cart = $result->data->Order->Cart;
  31.         $viewed = $result->data->viewed;
  32.         $customer = $this->pullCustomerData($result->data->Order);
  33.  
  34.         // Add to the shopping data array
  35.         $this->shoppingdata[$result->session] = array(
  36.             'modified' => $result->modified,
  37.             'cart' => $cart,
  38.             'viewed' => $viewed,
  39.             'customer' => $customer
  40.         );
  41.     }
  42.  
  43.  
  44.     protected function pullCustomerData($order) {
  45.         // Pull available customer details
  46.         $customer = array_merge(
  47.             (array) $order->Shipping, // Least interest
  48.             (array) $order->Billing, // Preferable
  49.             (array) $order->Customer // Ideal
  50.         );
  51.  
  52.         // Consolidate firstname/lastname
  53.         if (array_key_exists('firstname', $customer) and !empty($customer['firstname']))
  54.             $customer['name'] = $customer['firstname'].' '.$customer['lastname'];
  55.  
  56.         // Distill the array down to a limited number of fields
  57.         $desired = array_flip(array(
  58.             'name', 'address', 'xaddress', 'city', 'state',
  59.             'country', 'postcode', 'email'));
  60.  
  61.         return array_intersect_key($customer, $desired);
  62.     }
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement