public function init()
 {
     $site = new Model_Site();
     $products = new Model_Products();
     $all_menus = $site->AllMenus();
     foreach ($all_menus as $menu_id => $menu) {
         $menu_key = 'menu_' . $menu_id;
         $this->view->{$menu_key} = $menu;
     }
     $this->view->widget_blurb = $site->widget_blurb();
     //@todo to be removed soon
     $this->view->pagetypes = $this->pageTypes();
     //echo '<pre>'; print_r($products->bestSeller()); exit;
     $this->view->best_sellers = $products->bestSeller();
     $this->view->featured_products = $products->featuredProducts();
 }
 public function init()
 {
     parent::init();
     $site = new Model_Site();
     $page = new Model_Page();
     $categories = new Model_Categories();
     $products = new Model_Products();
     $all_menus = $site->AllMenus();
     foreach ($all_menus as $menu_id => $menu) {
         $menu_key = 'menu_' . $menu_id;
         $this->view->{$menu_key} = $menu;
     }
     $this->view->category_menu = $site->categoryMenu();
     $categoryTree = $categories->listCategoryTree();
     $this->view->categoryTree = $categoryTree;
     $this->view->widget_blurb = $site->widget_blurb();
     //@todo to be removed soon
     $this->view->categories = $page->displayCategories(null, 12);
     $this->view->Brands = $site->ListBrands();
     $this->view->best_sellers = $products->bestSeller();
     $this->view->featured_products = $products->featuredProducts();
 }
 public function bestsellersAction()
 {
     $this->view->errorMessage = '';
     $BestSellers = new Model_Bestsellers();
     if ($this->_getParam('add_best_seller') != '') {
         $bestSellerItem = $BestSellers->getData('best_sellers', 'ProductID=' . $this->_getParam('add_best_seller'), null, 1);
         if (empty($bestSellerItem)) {
             $order = $BestSellers->selectNextOrder();
             $BestSellers->insertData('best_sellers', array('ProductID' => $this->_getParam('add_best_seller'), 'order' => $order));
         } else {
             $this->view->errorMessage = 'Product that you have selected already exist in the best seller list.';
         }
     }
     if ($this->_getParam('delete_best_seller') != '') {
         if ($this->_getParam('delete_best_seller') == 'all') {
             $BestSellers->deleteData('best_sellers', '');
         } else {
             $BestSellers->deleteData('best_sellers', 'ProductID = ' . $this->_getParam('delete_best_seller'));
         }
     }
     if ($this->_getParam('up_best_seller') != '') {
         $bestSellerItem = $BestSellers->getData('best_sellers', 'ProductID=' . $this->_getParam('up_best_seller'), null, 1);
         if (!empty($bestSellerItem[0])) {
             $order = $bestSellerItem[0]['order'];
             $bestSellerItemBefore = $BestSellers->getData('best_sellers', '`order` < ' . $order, '`order` desc', 1);
             if (!empty($bestSellerItemBefore[0])) {
                 $BestSellers->updateData('best_sellers', array('order' => $bestSellerItemBefore[0]['order']), 'ProductID=' . $this->_getParam('up_best_seller'));
                 $BestSellers->updateData('best_sellers', array('order' => $order), 'ProductID=' . $bestSellerItemBefore[0]['ProductID']);
             }
         }
     }
     if ($this->_getParam('down_best_seller') != '') {
         $bestSellerItem = $BestSellers->getData('best_sellers', 'ProductID=' . $this->_getParam('down_best_seller'), null, 1);
         if (!empty($bestSellerItem[0])) {
             $order = $bestSellerItem[0]['order'];
             $bestSellerItemAfter = $BestSellers->getData('best_sellers', '`order` > ' . $order, '`order` asc', 1);
             if (!empty($bestSellerItemAfter[0])) {
                 $BestSellers->updateData('best_sellers', array('order' => $bestSellerItemAfter[0]['order']), 'ProductID=' . $this->_getParam('down_best_seller'));
                 $BestSellers->updateData('best_sellers', array('order' => $order), 'ProductID=' . $bestSellerItemAfter[0]['ProductID']);
             }
         }
     }
     if ($this->_getParam('default_setting') == 'true') {
         $BestSellers->setDefaultSetting();
     }
     $products = new Model_Products();
     $this->view->bestSellersList = $products->bestSeller();
     $where = "where 1";
     if ($_POST) {
         if (isset($_POST['q1']) && !empty($_POST['q1'])) {
             $where .= " and t2.Name like '%" . $_POST['q1'] . "%' or t2.Name like '" . $_POST['q1'] . "%'";
         }
         if (isset($_POST['q2']) && !empty($_POST['q2'])) {
             $where .= " and t2.Code = '" . $_POST['q2'] . "' ";
         }
         if (isset($_POST['q3']) && !empty($_POST['q3'])) {
             $where .= " and t5.DiscPrice = '" . $_POST['q3'] . "' ";
         }
         if (isset($_POST['q4']) && !empty($_POST['q4'])) {
             $where .= " and t5.Price = '" . $_POST['q4'] . "' ";
         }
         if (isset($_POST['q5']) && !empty($_POST['q5'])) {
             $where .= " and t1.Quantity = '" . $_POST['q5'] . "' ";
         }
     }
     //$list = $products->ListProducts("",$where,"",1); //set to forcebuild
     $sql = "select t1.Quantity, t1.Minimum, t2.ID ProductID, t2.*, t3.ID CategoryID, t3.Name CatName, t4.ID BrandID, t4.Name BrandName, t5.Currency, t5.Price, t5.DiscPrice, t5.DiscRate, t5.isDefault , t6.Filename , t8.Attributes\n\t\tfrom Store t1 join Products t2 on t1.ProductID = t2.ID \n\t\tleft join ProductCategory t7 on t1.ProductID = t7.ProductID \n\t\tleft join Category t3 on t7.CategoryID = t3.ID join Brands t4 on t1.BrandID = t4.ID \n\t\tleft join Prices t5 on t1.ProductID = t5.ProductID \n\t\tleft join ProductImages t6 on t6.ProductID = t2.ID \n\t\tleft join ProductAttributes t8 on t8.ProductID = t2.ID\n\t\t" . $where . " \n\t\tgroup by t2.ID order by t2.Created Desc";
     //echo $sql;exit;
     $list = $products->oldSkul($sql);
     if (count($list) > 0) {
         $paginator = Zend_Paginator::factory($list);
         $this->paginator($list);
     } else {
         $this->view->nodata = true;
     }
 }