public function loadAction() { if (!($customer = Axis::single('account/customer')->find((int) $this->_getParam('id'))->current())) { Axis::message()->addError(Axis::translate('Axis_Account')->__("Customer '%s' not found", $this->_getParam('id'))); return $this->_helper->json->sendFailure(); } $data = array(); $data['customer'] = $customer->toArray(); // custom fields $data['custom_fields'] = array(); foreach ($customer->getDetails() as $item) { if (isset($data['custom_fields']['field_' . $item['customer_field_id']])) { $data['custom_fields']['field_' . $item['customer_field_id']] .= ',' . $item['customer_valueset_value_id']; } else { $data['custom_fields']['field_' . $item['customer_field_id']] = isset($item['data']) ? $item['data'] : $item['customer_valueset_value_id']; } } // address $data['address'] = array(); $rowset = Axis::single('account/customer_address')->getSortListByCustomerId($customer->id); foreach ($rowset as $address) { $data['address'][] = $address->toArray(); } // orders $orders = Axis::single('sales/order')->fetchAll($this->db->quoteInto('customer_id = ?', $customer->id)); $orderStatus = Axis_Collect_OrderStatus::collect(); $orderStatusText = Axis_Collect_OrderStatusText::collect(); $data['order'] = array(); $i = 0; foreach ($orders as $order) { $data['order'][$i] = $order->toArray(); $data['order'][$i]['product'] = array_values($order->getProducts()); foreach ($data['order'][$i]['product'] as &$product) { $product['price'] = $product['price'] * $order->currency_rate; $product['final_price'] = $product['final_price'] * $order->currency_rate; $product['product_subtotal'] = $product['final_price'] * $product['quantity']; } if (isset($orderStatusText[$order['order_status_id']])) { $data['order'][$i]['status'] = $orderStatusText[$order['order_status_id']]; } else { $data['order'][$i]['status'] = isset($orderStatus[$order['order_status_id']]) ? $orderStatus[$order['order_status_id']] : $order['order_status_id']; } $i++; } // shopping cart $data['shopping_cart'] = array(); if ($cart = Axis::single('checkout/cart')->getCustomerCart($customer->id)) { $data['shopping_cart'] = array_values($cart->getProducts()); foreach ($data['shopping_cart'] as &$product) { $product['attributes'] = array_values($product['attributes']); } } return $this->_helper->json->setData($data)->sendSuccess(); }
public function loadAction() { $orderId = $this->_getParam('orderId'); $this->view->order = $order = Axis::single('sales/order')->find($orderId)->current(); $products = $order->getProducts(); foreach ($products as &$product) { $product['price'] = $product['price'] * $order->currency_rate; $product['final_price'] = $product['final_price'] * $order->currency_rate; $product['tax_rate'] = $product['tax'] * 100 / $product['final_price']; } $data['products'] = array_values($products); $totals = $order->getTotals(); foreach ($totals as &$total) { $total['value'] = $total['value'] * $order->currency_rate; } $this->view->totals = $data['totals'] = $totals; $data['history'] = $order->getStatusHistory(); $customer = Axis::single('account/customer')->find($order->customer_id)->current(); if ($customer instanceof Axis_Db_Table_Row) { $data['customer'] = $customer->toArray(); unset($data['customer']['password']); //paranoid $data['customer']['group'] = Axis::single('account/customer_group')->getName($customer->group_id); } else { $data['customer'] = array('firstname' => '-//-', 'lastname' => '-//-', 'group' => 'Guest', 'group_id' => Axis_Account_Model_Customer_Group::GROUP_GUEST_ID, 'email' => $order->customer_email); } $delivery = $order->getDelivery(); $data['address']['delivery'] = $delivery->toFlatArray(); $billing = $order->getBilling(); $data['address']['billing'] = $billing->toFlatArray(); $this->view->cc = Axis::single('sales/order_creditcard')->find($order->id)->current(); $form = $this->view->paymentForm($order->payment_method_code, 'view'); $data['payment'] = array('name' => $order->payment_method, 'code' => $order->payment_method_code, 'form' => $form); $data['shipping'] = array('name' => $order->shipping_method, 'code' => $order->shipping_method_code); $order = $order->toArray(); $order['status_name'] = Axis_Collect_OrderStatusText::getName($order['order_status_id']); $order['site_name'] = Axis_Collect_Site::getName($order['site_id']); // convert price with rates that was available // during order was created (not current rates) $order['order_total'] = $order['order_total'] * $order['currency_rate']; $data['order'] = $order; return $this->_helper->json->setData($data)->sendSuccess(); }