Skip to content

Commit

Permalink
Get view order working, with a bad layout
Browse files Browse the repository at this point in the history
  • Loading branch information
zombor committed Feb 25, 2011
1 parent 92f0e69 commit 27f831c
Show file tree
Hide file tree
Showing 5 changed files with 134 additions and 6 deletions.
23 changes: 20 additions & 3 deletions classes/view/admin/order/index.php
Expand Up @@ -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;
Expand Down
66 changes: 66 additions & 0 deletions classes/view/admin/order/view.php
Expand Up @@ -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
*
Expand All @@ -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 changes: 26 additions & 0 deletions templates/admin/order/cart.mustache
@@ -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 changes: 2 additions & 2 deletions templates/admin/order/index.mustache
Expand Up @@ -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>
Expand Down
21 changes: 20 additions & 1 deletion templates/admin/order/view.mustache
@@ -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>

0 comments on commit 27f831c

Please sign in to comment.