Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Get view order working, with a bad layout

  • Loading branch information...
commit 27f831c7cf4df011fd4602f7c4a2ae990b437243 1 parent 92f0e69
Jeremy Bush zombor authored
23 classes/view/admin/order/index.php
View
@@ -26,14 +26,31 @@ public function orders()
foreach (Model_Order::get_orders(10, $this->page-1) as $order)
{
- $orders[] = array(
+ $foo = array(
'id' => $order->id,
- 'user_id' => $order->user_id,
- 'contact_id' => $order->contact_id,
'date_created' => date('m/d/Y', $order->date_created),
'address_id' => $order->address_id,
'amount' => number_format($order->amount(), 2),
);
+
+ if ($order->user_id)
+ {
+ $foo['user'] = array(
+ 'id' => $order->user_id,
+ 'name' => $order->user->last_name.', '.
+ $order->user->first_name,
+ );
+ }
+ elseif ($order->contact_id)
+ {
+ $foo['contact'] = array(
+ 'id' => $order->contact_id,
+ 'name' => $order->contact->last_name.', '.
+ $order->contact->first_name,
+ );
+ }
+
+ $orders[] = $foo;
}
return $orders;
66 classes/view/admin/order/view.php
View
@@ -14,6 +14,10 @@ class View_Admin_Order_View extends View_Admin_Layout
public $order;
+ protected $_partials = array(
+ 'cart' => 'admin/order/cart',
+ );
+
/**
* Returns details for this order
*
@@ -23,4 +27,66 @@ public function order()
{
return $this->order->as_array();
}
+
+ /**
+ * Returns the user data for this order
+ *
+ * @return array
+ */
+ public function user()
+ {
+ return $this->order->user;
+ }
+
+ /**
+ * Returns shipping information about this order
+ *
+ * @return array
+ */
+ public function shipping()
+ {
+ return $this->order->address;
+ }
+
+ /**
+ * Determines if this order comes from a registered user or not
+ *
+ * @return book
+ */
+ public function registered_user()
+ {
+ return NULL !== $this->order->user_id;
+ }
+
+ /**
+ * Var method to get the order's products
+ *
+ * @return array
+ */
+ public function cart()
+ {
+ $cart_items = array();
+
+ foreach ($this->order->get_products() as $product_id => $product)
+ {
+ $cart_items[] = array(
+ 'product' => array(
+ 'total_price' => number_format($product['product']->price*$product['quantity'], 2)
+ )+$product['product']->as_array(),
+ 'quantity' => $product['quantity'],
+ );
+ }
+
+ return $cart_items;
+ }
+
+ /**
+ * Returns the total price for the order
+ *
+ * @return float
+ */
+ public function total_price()
+ {
+ return number_format($this->order->amount(), 2);
+ }
}
26 templates/admin/order/cart.mustache
View
@@ -0,0 +1,26 @@
+<table>
+ <thead>
+ <tr>
+ <th>Qty</th>
+ <th>Product Name</th>
+ <th>Price</th>
+ <th>Total Price</th>
+ </tr>
+ </thead>
+ <tbody>
+ {{#cart}}<tr>
+ {{#product}}<td>{{quantity}}</td>
+ <td>{{name}}</td>
+ <td>${{price}}</td>
+ <td>${{total_price}}</td>{{/product}}
+ </tr>
+ {{/cart}}
+ </tbody>
+ <tfoot>
+ <tr>
+ <td class="total_items">{{total_items}}</td>
+ <td colspan="2"></td>
+ <td>${{total_price}}</td>
+ </tr>
+ </tfoot>
+</table>
4 templates/admin/order/index.mustache
View
@@ -15,8 +15,8 @@
{{#orders}}<tr>
<td><a href="{{#routes}}{{order_view}}{{/routes}}?id={{id}}">{{id}}</a></td>
<td>
- {{#user_id}}<a href="{{#routes}}{{user}}{{/routes}}?id={{user_id}}">{{user_id}}</a>{{/user_id}}
- {{^user_id}}{{#contact_id}}<a href="{{#routes}}{{contact}}{{/routes}}?id={{contact_id}}">{{contact_id}}</a>{{/contact_id}}{{/user_id}}
+ {{#user}}<a href="{{#routes}}{{user}}{{/routes}}?id={{id}}">{{name}}</a>{{/user}}
+ {{^user}}{{#contact}}<a href="{{#routes}}{{contact}}{{/routes}}?id={{id}}">{{name}}</a>{{/contact}}{{/user}}
</td>
<td>{{date_created}}</td>
<td>${{amount}}</td>
21 templates/admin/order/view.mustache
View
@@ -1 +1,20 @@
-<h2>Put order details here</h2>
+<h2>Order Details</h2>
+<h3>Purchaser Details</h3>
+<p>Registered User: {{#registered_user}}Yes{{/registered_user}}{{^registered_user}}No{{/registered_user}}</p>
+<div id="user_details">
+ <h4>User Details</h4>
+ {{#user}}<ul>
+ <li>Name: {{first_name}} {{last_name}}</li>
+ <li>Email: {{email}}</li>
+ </ul>{{/user}}
+ <h4>Shipping Information</h4>
+ {{#shipping}}<ul>
+ <li>Address: {{shipping_address}}</li>
+ <li>City: {{shipping_city}}</li>
+ <li>State: {{shipping_state}}</li>
+ <li>Postal Code: {{shipping_postal_code}}</li>
+ </ul>{{/shipping}}
+</div>
+<div id="order_details">
+ {{>cart}}
+</div>
Please sign in to comment.
Something went wrong with that request. Please try again.