discount = new Discont(); $this->section = new Section(); $this->cart = new Cart(); $this->product = new Product(); parent::__construct(); $this->setCart(); $this->template->set("items", $this->section->getAllSortID()); $this->template->set("cart_link", $this->url->cart()); $this->template->display("main"); } public function setCart(){ $ids = explode(",", $_SESSION["id"]); $words = array("товар", "товара", "товаров"); $word = $this->getDeclineWord($ids, $words); $this->template->set("product_word", $word); if(!$_SESSION["id"]){ $this->template->set("cart_summa", 0); $this->template->set("cart_count", 0); } else{ if(($sum = $this->cart->cartSum($ids)) !== false){ $this->template->set("cart_summa", $sum); $this->template->set("cart_count", count($ids)); } else { unset($_SESSION["id"]); } } } protected function getDeclineWord($ids, $words){ $doubleCount = count($ids) % 100; $singleCount = count($ids) % 10; $key = array(2, 0, 1, 1, 1, 2); $mods = ($doubleCount > 4 && $doubleCount < 20)? 2 : $key[min($singleCount, 5)]; return $words[$mods]; } abstract protected function getContent(); protected function notFound(){ $this->redirect($this->url->notFound()); } protected function redirect($link){ header("Location: $link"); exit(); } protected function setMessage(){ if($_SESSION["message"]){ $text = $this->message->get($_SESSION["message"]); $this->template->set("message", $text); unset($_SESSION["message"]); } } protected function getDirTmpl(){ return $this->config->dir_tmpl; } } ?>