Программирование
- 4 ответа
- 0 вопросов
3
Вклад в тег
<?php
defined('SYSPATH') or die('No direct script access.');
class Controller_Products extends Controller_Base
{
public function action_index()
{
// пагинация
$count = ORM::factory('product')->count_all();
$pagination = Pagination::factory(array('total_items' => $count));
$products = ORM::factory('product')
->limit($pagination->items_per_page)
->offset($pagination->offset)
->find_all();
$content = View::factory('prodAll')
->set('products', $products);
//используется в шаблоне?
$content->pagination = $pagination;
$this->template->title = 'Все товары';
$this->template->description = 'Список всех товаров';
$this->template->content = $content;
}
public function action_cart()
{
$content = View::factory('cartView');
$content->inCart = FALSE;
$content->inCart = $this->session->get('product2');
$this->template->title = 'Корзина покупок';
$this->template->description = 'Список ваших товаров';
$this->template->content = $content;
}
public function action_product()
{
//узнаем id материала
$id = $this->request->param('id');
$post = $this->request->post();
// получаем данные из таблицы "products"
$product = ORM::factory('product', $id);
$content = View::factory('prodView')
->set('product', $product);
$this->template->title = $product->title;
$this->template->content = $content;
$content->inCart = FALSE;
if (isset($post['Submit'])) {
$this->processOrder($post, $product);
Controller::redirect('main/ordered');
}
if (isset($post['InCart'])) {
$this->session->set('product2', $product->name);
}
}
/**
*
* @param array $post
* @param Model_Product $product
*/
protected function processOrder($post, $product)
{
$clientName = Arr::get($post, 'Name', '');
$clientPhone = Arr::get($post, 'Phone', '');
$clientAdress = Arr::get($post, 'Adress', '');
$orderNumber = Arr::get($post, 'Number', '');
$post = array(
'name' => $product->name,
'number' => $orderNumber,
'url' => $product->url,
'client_name' => $clientName,
'client_phone' => $clientPhone,
'client_adress' => $clientAdress
);
ORM::factory('order')
->values($post)
->save();
}
}