pickles/common/modules/store.php
Josh Sherman c6af785100 Latest and greatest.
git-svn-id: http://svn.cleancode.org/svn/pickles@85 4d10bc64-7434-11dc-a737-d2d0f8310089
2008-12-31 02:45:40 +00:00

60 lines
1.6 KiB
PHP

<?php
class store extends Module {
protected $display = DISPLAY_SMARTY;
protected $session = true;
public function __construct(Config $config, DB $db, Mailer $mailer, Error $error) {
parent::__construct($config, $db, $mailer, $error);
// Loads up the cart in case we need it
if (!isset($_SESSION['cart'], $_SESSION['cart']['count'], $_SESSION['cart']['products'])) {
$_SESSION['cart'] = array();
$_SESSION['cart'] = array('count' => 0, 'products' => null);
}
else {
$count = 0;
if (is_array($_SESSION['cart']['products'])) {
foreach ($_SESSION['cart']['products'] as $product_id => $product_info) {
$count += $product_info['quantity'];
}
}
$_SESSION['cart']['count'] = $count;
}
$this->cart = $_SESSION['cart'];
// Loads the navigation
$this->subnav = $config->store->sections;
// Loads the categories
$categories = $this->db->getArray('SELECT id, name, permalink FROM categories WHERE parent_id IS NULL AND visible = "Y" ORDER BY weight;');
if (is_array($categories)) {
foreach ($categories as $key => $category) {
$categories[$key]['subcategories'] = $this->db->getArray('
SELECT id, name, permalink
FROM categories
WHERE parent_id = "' . $category['id'] . '"
AND visible = "Y"
ORDER BY weight;
');
}
}
$this->categories = $categories;
}
public function __default() {
// Forces store/home as the first page you get when only /store is called
$object = new store_home($this->config, $this->db, $this->mailer, $this->error);
$object->__default();
$this->data = $object->data;
$this->name = 'store/home';
}
}
?>