public function getCategory($id) { $result['categories'] = $this->category->getCategories(); $result['title'] = 'Shop'; $result['currentCategory'] = $id; $result['isEditor'] = Auth::isUserInRole(array('editor', 'admin')); $result['isAdmin'] = Auth::isUserInRole(array('admin')); if ($result['isEditor']) { $result['products'] = $this->product->getProductsForCategoryWitnUnavailable($id); } else { $result['products'] = $this->product->getProductsForCategory($id); } $all_promotion = $this->promotion->getHighestActivePromotion(); foreach ($result['products'] as $k => $p) { $productPromotion = max($all_promotion['discount'], $p['discount'], $p['category_discount']); if (is_numeric($productPromotion)) { $result['products'][$k]['promotion_price'] = $p['price'] - $p['price'] * ($productPromotion / 100); } } View::make('index', $result); if (Auth::isAuth()) { View::appendTemplateToLayout('topBar', 'top_bar/user'); } else { View::appendTemplateToLayout('topBar', 'top_bar/guest'); } View::appendTemplateToLayout('header', 'includes/header')->appendTemplateToLayout('footer', 'includes/footer')->appendTemplateToLayout('catMenu', 'side_bar/category_menu')->render(); }
public function getProduct($id) { $result['comments'] = $this->comment->getCommentsByProduct($id); $result['categories'] = $this->category->getCategories(); $result['isEditor'] = Auth::isUserInRole(array('editor', 'admin')); $result['isAdmin'] = Auth::isUserInRole(array('admin')); if ($result['isEditor']) { $result['product'] = $this->product->getProductWitnUnavailable($id); } else { $result['product'] = $this->product->getProduct($id); } $all_promotion = $this->promotion->getHighestActivePromotion(); $productPromotion = max($all_promotion['discount'], $result['product']['discount'], $result['product']['category_discount']); if (is_numeric($productPromotion)) { $result['product']['promotion_price'] = $result['product']['price'] - $result['product']['price'] * ($productPromotion / 100); } $result['title'] = 'Shop'; $result['currentCategory'] = $result['product']['category_id']; View::make('product', $result); if (Auth::isAuth()) { View::appendTemplateToLayout('topBar', 'top_bar.user'); } else { View::appendTemplateToLayout('topBar', 'top_bar.guest'); } View::appendTemplateToLayout('header', 'includes.header')->appendTemplateToLayout('footer', 'includes.footer')->appendTemplateToLayout('catMenu', 'side_bar.category_menu')->render(); }
private function getProductsFromCart($cart) { $all_promotion = $this->promotion->getHighestActivePromotion(); $productsFromCart = array(); foreach ($cart as $id => $q) { if ($currentProduct = $this->product->getProduct($id)) { $productPromotion = max($all_promotion['discount'], $currentProduct['discount'], $currentProduct['category_discount']); if (is_numeric($productPromotion)) { $currentProduct['price'] = $currentProduct['price'] - $currentProduct['price'] * ($productPromotion / 100); } $currentProduct['cart_quantity'] = $q['quantity']; $productsFromCart[] = $currentProduct; } } return $productsFromCart; }