diff --git a/component/site/models/category.php b/component/site/models/category.php index 781457060fe..6d9b2bf71ac 100644 --- a/component/site/models/category.php +++ b/component/site/models/category.php @@ -798,29 +798,11 @@ protected function populateState($ordering = '', $direction = '') $selectedTemplate, 'int' ); - $this->setState('category_template', $categoryTemplate); - - if ($_POST) { - $manufacturerId = $app->input->post->getInt('manufacturer_id', 0); - - if ($manufacturerId != $app->getUserState( - $this->context . '.manufacturer_id', - $app->input->get->getInt('manufacturer_id', 0) - )) { - $app->redirect( - Redshop\IO\Route::_( - 'index.php?option=com_redshop&view=category&layout=' . $layout . '&cid=' . $this->_id . '&manufacturer_id=' . $manufacturerId - . '&Itemid=' . $app->input->getInt('Itemid', 0), - true - ) - ); - } - } else { - $manufacturerId = $app->input->getInt('manufacturer_id', 0); - $app->setUserState($this->context . '.manufacturer_id', $manufacturerId); - } $categoryId = $app->input->post->getInt('category_id', 0); + $manufacturerId = $app->input->getInt('manufacturer_id', 0); + + $this->setState('category_template', $categoryTemplate); $this->setState('category_id', $categoryId); $this->setState('manufacturer_id', $manufacturerId); diff --git a/component/site/models/manufacturers.php b/component/site/models/manufacturers.php index f92146830a1..234423f781f 100644 --- a/component/site/models/manufacturers.php +++ b/component/site/models/manufacturers.php @@ -244,10 +244,59 @@ public function getManufacturerProducts($template_data = '') $limitstart = JFactory::getApplication()->input->getInt('limitstart', 0); $query = $this->_buildProductQuery($template_data); $this->products = $this->_getList($query, $limitstart, $limit); + $countProduct = count($this->products); + $orderBy = $this->_buildProductOrderBy(); + + if (strpos($orderBy, "p.product_price ASC") !== false) { + for ($i = 0; $i < $countProduct; $i++) { + $productPrices = RedshopHelperProductPrice::getNetPrice($this->products[$i]->product_id); + + $this->products[$i]->productPrice = $productPrices['product_price']; + } + + $this->products = $this->columnSort($this->products, 'productPrice', 'ASC'); + } elseif (strpos($orderBy, "p.product_price DESC") !== false) { + for ($i = 0; $i < $countProduct; $i++) { + $productPrices = RedshopHelperProductPrice::getNetPrice($this->products[$i]->product_id); + + $this->products[$i]->productPrice = $productPrices['product_price']; + } + + $this->products = $this->columnSort($this->products, 'productPrice', 'DESC'); + } return $this->products; } + public function columnSort($unsorted, $column, $sort) + { + $sorted = $unsorted; + + if ($sort == "ASC") { + for ($i = 0; $i < count($sorted) - 1; $i++) { + for ($j = 0; $j < count($sorted) - 1 - $i; $j++) { + if ($sorted[$j]->$column > $sorted[$j + 1]->$column) { + $tmp = $sorted[$j]; + $sorted[$j] = $sorted[$j + 1]; + $sorted[$j + 1] = $tmp; + } + } + } + } else { + for ($i = 0; $i < count($sorted) - 1; $i++) { + for ($j = 0; $j < count($sorted) - 1 - $i; $j++) { + if ($sorted[$j]->$column < $sorted[$j + 1]->$column) { + $tmp = $sorted[$j]; + $sorted[$j] = $sorted[$j + 1]; + $sorted[$j + 1] = $tmp; + } + } + } + } + + return $sorted; + } + public function getProductLimit() { return $this->_productlimit; @@ -299,7 +348,7 @@ public function _buildProductQuery($template_data = '') $query->where($db->qn('p.manufacturer_id') . ' IN (' . $shopperGroupManufactures . ')'); } - if ($filterBy != '0') { + if (!empty($filterBy)) { $query->where($db->qn('c.id') . ' = ' . $db->q((int)$filterBy)); }