Can't insert in database with Codeigniter - php

I'm trying to add everything from a table (transactions) then try to insert all the totals to another table(reports_daily), but nothing is inserted.
transaction.php
public function index()
{
$this->load->model('transactions_model');
$transresult = $this->transactions_model->get_transactions_list();
$data['translist'] = $transresult;
$this->load->view('transactions_view',$data);
}
function create() {
$transresult = $this->transactions_model->get_transactions_list();
$data['translist'] = $transresult;
$sum=0;
$items=0;
$orders=0;
$date=$translist[0]->date_d;
for ($i=0; $i<count($translist); ++$i){
$sum += $translist[$i]->total_amount;
$items += $translist[$i]->no_items;
$orders++;
}
$data = array(
'date_d' => $date,
'total_items' => $items,
'total_orders' => $orders,
'total_sales' => $sum
);
//$this->db->set($data);
//$this->db->insert('reports_daily', $data);
$this->transactions_model->insert_reports($data);
$this->index();
}
transactions_model.php
function get_transactions_list()
{
$sql = 'select * from transactions order by date_d desc';
$query = $this->db->query($sql);
$result = $query->result();
return $result;
}
function insert_reports($data)
{
$this->db->insert('reports_daily', $data);
return;
}
Help :(

$translist is not exist on controller. So use $transresult[0] instead of $translist[0];
function create() {
$transresult = $this->transactions_model->get_transactions_list();
$sum=0;
$items=0;
$orders=0;
$date = $transresult[0]->date_d;
for ($i=0; $i<count($translist); ++$i){
$sum += $translist[$i]->total_amount;
$items += $translist[$i]->no_items;
$orders++;
}
$data = array(
'date_d' => $date,
'total_items' => $items,
'total_orders' => $orders,
'total_sales' => $sum
);
//$this->db->set($data);
//$this->db->insert('reports_daily', $data);
$this->transactions_model->insert_reports($data);
$this->index();
}

Related

An uncaught Exception was encountered Type: Error Message: Class 'BaseController' not found

<?php
defined('BASEPATH') or exit('No direct script access allowed');
class index extends BaseController
{
public function __construct()
{
parent::__construct();
$this->load->model('P_pmb', 'p_pmb');
}
public function index()
{
$data['title'] = 'Dashboard';
$this->render('index/index', $data);
}
public function pendaftarprodi1()
{
$data['title'] = 'Grafik Berdasarkan Prodi 1';
$prodi = $this->p_pmb->listProdi();
foreach ($prodi as $key => $p) {
$prodi[$key]['jumlah'] = $this->p_pmb->jumlahPendaftarProdi1($p['id_prodi']);
$prodi[$key]['jumlah2'] = $this->p_pmb->jumlahPendaftarProdi2($p['id_prodi']);
$prodi[$key]['size'] = rand(10, 30);
}
//grafik 1
$result = null;
foreach ($prodi as $p => $prod) {
// if ($prod['jumlah'] > $sum) {
// $sum = $prod['jumlah'];
// $sliced = true;
// $selected = true;
// }
$result[$p] = [
"name" => $prod['nama_prodi'],
"jumlah" => $prod['jumlah'],
"y" => $prod['size'],
// "sliced" => $sliced,
// 'selected' => $selected
];
}
$data['pendaftar'] = $prodi;
$data['grafik1'] = json_encode($result);
$this->render('index/grafik1', $data);
}
public function pendaftarprodi2()
{
$data['title'] = 'Grafik Berdasarkan Prodi 2';
$prodi = $this->p_pmb->listProdi();
foreach ($prodi as $key => $p) {
$prodi[$key]['jumlah'] = $this->p_pmb->jumlahPendaftarProdi1($p['id_prodi']);
$prodi[$key]['jumlah2'] = $this->p_pmb->jumlahPendaftarProdi2($p['id_prodi']);
$prodi[$key]['size'] = rand(10, 30);
}
//grafik 2
$hasil = null;
foreach ($prodi as $p => $prod) {
$hasil[$p] = [
"name" => $prod['nama_prodi'],
"jumlah" => $prod['jumlah2'],
"y" => $prod['size'],
// "sliced" => $sliced,
// 'selected' => $selected
];
}
$data['pendaftar'] = $prodi;
$data['grafik2'] = json_encode($hasil);
$this->render('index/grafik2', $data);
}
public function pendaftarprestasi()
{
$pendaftarprestasi = $this->p_pmb->listpendaftarprestasi();
foreach ($pendaftarprestasi as $key => $p) {
$pendaftarprestasi[$key]['jumlah'] = $this->p_pmb->jumlahpendaftarprestasi($p['tingkat_prestasi']);
$pendaftarprestasi[$key]['size'] = rand(10, 30);
}
$result = null;
$sum = 0;
foreach ($pendaftarprestasi as $p => $pendpres) {
//if ($pendpres['jumlah'] > $sum) {
// $sum = $pendpres['jumlah'];
// $sliced = true;
// $selected = true;
// }
$result[$p] = [
"name" => $pendpres['tingkat_prestasi'],
'jumlah' => $pendpres['jumlah'],
'y' => $pendpres['size'],
// $sliced => $sliced,
// $selected => $selected
];
}
$data['pendaftarprestasi'] = $pendaftarprestasi;
$data['grafikprestasi'] = json_encode($result);
$this->render('index/grafikprestasi', $data);
}
public function jalurmasuk()
{
$pendaftar = $this->p_pmb->listjalurpendaftar();
foreach ($pendaftar as $key => $p) {
$pendaftar[$key]['jumlah'] = $this->p_pmb->jumlahjalurpendaftar($p['nama_jalur']);
$pendaftar[$key]['jumlah'] = rand(10, 30);
}
$result = null;
$sum = 0;
foreach ($pendaftar as $p => $jalmask) {
//if ($jalmask['jumlah'] > $sum) {
// $sum = $jalmask['jumlah'];
// $sliced = true;
// $selected = true;
// }
$result[$p] = [
"name" => $jalmask['nama_jalur'],
'jumlah' => $jalmask['jumlah'],
'y' => $jalmask['jumlah'],
// $sliced => $sliced,
// $selected => $selected
];
}
$data['jalur_masuk'] = $jalmask;
$data['grafikmasuk'] = json_encode($result);
$this->render('index/grafikmasuk', $data);
}
public function pendapatan()
{
$data['title'] = 'Grafik Pendapatan Berdasarkan Bank';
$bank = $this->p_pmb->listBank();
$pendaftar = $this->p_pmb->pendaftarBank();
$categories = null;
$lunas = null;
$belum_lunas = null;
$sumTotal = 0;
foreach ($bank as $i => $b) {
$categories[] = $b['bank'];
foreach ($pendaftar as $key => $value) {
if ($b['id_bank'] == $value['id_bank']) {
if ($value['is_bayar'] == '1') {
$sumTotal += intval($value['total']);
$lunas[] = intval($value['total']);
} else {
$belum_lunas[] = intval($value['total']);
}
}
}
}
$result[] = [
'name' => 'Pendapatan',
'data' => $lunas,
];
$data['subtitle'] = 'Total Pendapatan Rp.' . $sumTotal;
$grafik['id_bank'] = json_encode($result);
$grafik['categories'] = json_encode($categories);
$data['grafikpendapatan'] = $grafik;
$this->render('index/grafikpendapatan', $data);
}
public function bank()
{
$data['title'] = 'Grafik Pendapatan Berdasarkan Bank';
$bank = $this->p_pmb->listBank();
$pendaftar = $this->p_pmb->pendaftarBank();
$categories = null;
$lunas = null;
$belum_lunas = null;
$sumTotal = 0;
foreach ($bank as $i => $b) {
$categories[] = $b['bank'];
foreach ($pendaftar as $key => $value) {
if ($b['id_bank'] == $value['id_bank']) {
if ($value['is_bayar'] == '1') {
$sumTotal += intval($value['total']);
$lunas[] = intval($value['total']);
} else {
$sumTotal += $value['jumlah'];
$belum_lunas[] = intval($value['total']);
}
}
}
}
$result[] = [
'name' => 'Lunas',
'data' => $lunas,
];
$result[] = [
'name' => 'Belum Lunas',
'data' => $belum_lunas,
];
$data['subtitle'] = 'Total Pendaftar: ' . $sumTotal;
$data['id_bank'] = $bank;
$data['grafikbank'] = json_encode($result);
$this->render('index/grafikbank', $data);
}
}
<?php
defined('BASEPATH') or exit('No direct script access allowed');
class BaseController extends CI_Controller
{
public function render($filename, $data)
{
$this->load->view('template/app_top', $data);
$this->load->view('template/template_scripts', $data);
$this->load->view($filename, $data);
$this->load->view('template/app_bottom', $data);
}
}

show post of category in index controller codeigniter

i completely new in ci and i build a project that have index page and show posts in this page with pagination, i have menu sidebar that contain categories , i want when i click each them show posts of that category. how can change my code to that?
home_controller
class Home extends Ci_controller {
function __construct() {
parent:: __construct();
$this->load->model('home_model');
$this->load->model('category_model');
$this->load->library('pagination');
}
function index() {
$category = $this->category_model->allCategory();
$config['base_url'] = base_url() . 'index.php/home/index/page/';
$config['total_rows'] = $this->home_model->countall();
$config['per_page'] = 5;
$config['uri_segment'] = 4;
$page = ($this->uri->segment(4)) ? $this->uri->segment(4) : 0;
$this->pagination->initialize($config);
$posts = $this->home_model->all($config['per_page'], $page);
$setting = $this->home_model->setting('about');
$pagination = $this->pagination->create_links();
$this->template->load('home', array('posts' => $posts, 'pagination' => $pagination, 'category' => $category, 'setting' => unserialize($setting['value'])));
}
}
home_model
class Home_model extends CI_Model {
function __construct() {
parent::__construct();
}
function allPost() {
$all = $this->db->get('posts')->result_array();
$data_send = array();
foreach ($all as $key => $value) {
$data = array();
$category = $this->db->get_where('catpost', array('post_id' => $value['post_id']))->result_array();
$data['id'] = $value['post_id'];
$data['title'] = $value['title'];
$data['create_time'] = $value['create_time'];
$data['content'] = $value['content'];
$data['username'] = $value['username'];
$data['category'] = $category;
$data_send[] = $data;
}
return $data_send;
}
function all($limit, $start) {
$lastpost = $this->db->select('post_id')->order_by('create_time DESC')->limit($limit, $start)->get('post')->result_array();
$idarr = array();
foreach ($lastpost as $key => $value) {
$idarr[] = "'{$value['post_id']}'";
}
$ids = implode(',', $idarr);
$sql = "select tbl_post.post_id, tbl_category.name, tbl_post.title, tbl_post.content, tbl_post.create_time, tbl_post.author_id, tbl_user.username from `tbl_category` join `tbl_post_category` on `tbl_post_category`.`category_id`=`tbl_category`.`category_id` join `tbl_post` on `tbl_post`.`post_id`=`tbl_post_category`.`post_id` join tbl_user on tbl_user.user_id=tbl_post.author_id where tbl_post.post_id in($ids) ORDER BY tbl_post.post_id DESC";
$allpost = $this->db->query($sql)->result_array();
$posts = array();
foreach ($allpost as $key => $value) {
$postid = $value['post_id'];
if (array_key_exists($postid, $posts)) {
$posts[$postid]['category'] .= ",{$value['name']}";
} else {
$posts[$postid] = array(
'post_id' => $postid,
'title' => $value['title'],
'content' => $value['content'],
'create_time' => $value['create_time'],
'username' => $value['username'],
'category' => $value['name']);
}
}
return $posts;
}
function setting($name = NULL) {
$ret = NULL;
if ($name != NULL) {
$this->db->where('name', $name);
$ret = $this->db->get('setting')->result_array()[0];
} else {
$ret = $this->db->get('setting')->result_array();
}
return $ret;
}
function countall() {
Return $this->db->count_all('posts');
}
}
view part of category
<?php
foreach($category as $key => $value){
$name='category['.$value['name'].']';
echo '<li><a href='.$value['name'].'>'.$value['name'].'</a></li>';
}
?>

Can I call codeigniter model function as a table?

I spent a whole day just to find out, how to make my code cooler. I just curious about, Can I call Codeigniter model function as a table?. Here is codeigniter with my little custom serverside datatables.
my Model : M_global
private function _get_datatables_query($table, $column_order, $column_search, $order) {
$this->db->from($table);
$i = 0;
foreach ($column_search as $item) {
if($_POST['search']['value']) {
if($i===0) {
$this->db->group_start();
$this->db->like($item, $_POST['search']['value']);
} else {
$this->db->or_like($item, $_POST['search']['value']);
}
if(count($column_search) - 1 == $i)
$this->db->group_end();
}
$i++;
}
if(isset($_POST['order'])) {
$this->db->order_by($column_order[$_POST['order']['0']['column']], $_POST['order']['0']['dir']);
} else if(isset($order)) {
$order = $order;
$this->db->order_by(key($order), $order[key($order)]);
}
}
function get_datatables($table, $column_order, $column_search, $order)
{
$this->_get_datatables_query($table, $column_order, $column_search, $order);
if($_POST['length'] != -1)
$this->db->limit($_POST['length'], $_POST['start']);
$query = $this->db->get();
return $query->result();
}
function count_filtered($table, $column_order, $column_search, $order)
{
$this->_get_datatables_query($table, $column_order, $column_search, $order);
$query = $this->db->get();
return $query->num_rows();
}
public function count_all($table) {
$this->db->from($table);
return $this->db->count_all_results();
}
// My query here
function sum_filter() {
return $this->db->query("
SELECT
main.name,
main.date_submit,
main.id_claim,
ifnull((SELECT SUM(amount) FROM v_t_office
WHERE id_claim = main.id_claim), 0) as total_office,
ifnull((SELECT SUM(amount) FROM v_t_misc
WHERE id_claim = main.id_claim), 0) as total_misc,
ifnull((
(SELECT SUM(amount) FROM v_t_office
WHERE id_claim = main.id_claim) +
(SELECT SUM(amount) FROM v_t_misc
WHERE id_claim = main.id_claim)
), 0) as total_expense
FROM
vc_submit main
GROUP BY main.id_claim
")
}
my Controller : Approval
Here is my problem, I cant use, in $table
public function show_approve() {
$table = $this->M_global->sum_filter(); //Here
// $table = 'v_transaction';
$column_order = array(null, 'name','date_submit','total_office','total_misc','total_expense',null);
$column_search = array('name','date_submit','total_office','total_misc','total_expense');
$order = array('name' => 'asc');
$list = $this->M_global->get_datatables($table, $column_order, $column_search, $order);
$data = array();
$no = $_POST['start'];
foreach ($list as $l) {
$no++;
$row = array();
$row[] = $no;
$row[] = $l->name;
$row[] = date('d-m-Y', strtotime($l->date_submit));
$row[] = $l->total_office;
$row[] = $l->total_misc;
$row[] = $l->total_expense;
$row[] = '';
$data[] = $row;
}
$output = array(
"draw" => $_POST['draw'],
"recordsFiltered" => $this->M_global->count_filtered($table, $column_order, $column_search, $order),
"recordsTotal" => $this->M_global->count_all($table),
"data" => $data,
);
echo json_encode($output);
}
I can't use
$table = $this->M_global->sum_filter();
The ajax response say "strpos() expects parameter 1 to be string, object given". What am I doing wrong? or Its just cannot. For alternative I use v_transaction table which is made by sum_filter() query.

Saving reservations using available 2 halls

Below is the function for saving some reservation details to the database. get_hall() query returns 2 halls(haal1 and hall2). bus when going to the database only hall1 is inserting. I want to insert hall1 next reservation hall2. How to improve below code.
function save_reserve_detail($date,$time,$flag){
$halls = $this->halls_model->get_hall();
foreach ($halls AS $each) {
$hall = $each['hall_id'];
break;
}
$reference_no = date("YmdHis");
if ($flag == 1) {
$hall_id = $hall;
$type = 1;
$date = $date;
} else if ($flag == 2) {
$hall_id = $hall;
$type = 0;
$date = $date;
}
$data = array(
'reference_no' => $reference_no,
'date' => $date,
'type' => $type,
'hall' => $hall
);
$result = $this->db->insert('reserving_details', $data);
if ($result) {
return $reference_no;
} else {
return 0;
}
}
Remove the break from foreach . now the $hall contains an array of 2 values. now use a for loop to insert the value into the table.
<?php
function save_reserve_detail($date,$time,$flag){
$halls = $this->halls_model->get_hall();
foreach ($halls AS $each) {
$hall = $each['hall_id'];
// break;
}
$reference_no = date("YmdHis");
if ($flag == 1) {
$hall_id = $hall;
$type = 1;
$date = $date;
} else if ($flag == 2) {
$hall_id = $hall;
$type = 0;
$date = $date;
}
for($i=0;$i<sizeof($hall);$i++){
$data = array(
'reference_no' => $reference_no,
'date' => $date,
'type' => $type,
'hall' => $hall[$i]
);
$result = $this->db->insert('reserving_details', $data);
if ($result) {
return $reference_no;
} else {
return 0;
}
}
}
?>
Even you can alter your insert('reserving_details', $data); code which can handle array insertion.

Want to remove (((price_table_price.value)*1) < from the product collection

I am very new to Magento. (Indeed this is my first task). I would be very glad if you can help me on this.
I am using magento sample database and theMagento version is 1.3.2.
Local PC URL : http://magento.local/electronics/cell-phones.html?price=4,100
Class : Mage_Catalog_Block_Product_List
protected function _getProductCollection()
{
if (is_null($this->_productCollection)) {
$layer = Mage::getSingleton('catalog/layer');
/* #var $layer Mage_Catalog_Model_Layer */
if ($this->getShowRootCategory()) {
$this->setCategoryId(Mage::app()->getStore()->getRootCategoryId());
}
// if this is a product view page
if (Mage::registry('product')) {
// get collection of categories this product is associated with
$categories = Mage::registry('product')->getCategoryCollection()
->setPage(1, 1)
->load();
// if the product is associated with any category
if ($categories->count()) {
// show products from this category
$this->setCategoryId(current($categories->getIterator()));
}
}
$origCategory = null;
if ($this->getCategoryId()) {
$category = Mage::getModel('catalog/category')->load($this->getCategoryId());
if ($category->getId()) {
$origCategory = $layer->getCurrentCategory();
$layer->setCurrentCategory($category);
}
}
$this->_productCollection = $layer->getProductCollection();
$this->prepareSortableFieldsByCategory($layer->getCurrentCategory());
if ($origCategory) {
$layer->setCurrentCategory($origCategory);
}
}
return $this->_productCollection;
}
I need to remove (((price_table_price.value)*1) < 400) from the $this->_productCollection.
Can’t figure out how and when this added to the product collection. Please HELP!!!
Thanks!!!!
Since No one helped me, I figured out answer by myself.
Firstly I'll state what my task was.
Lets say that I have a products 10 in 100-200 price range, 12 in 500-600 and 1 product in 10000-20000 of X category. With the default price range of magento it display as two ranges which are 0-10000 and 10000-200000 which is not much useful for the customer.
I had to made the ranges as 100-200,500-600 and 1000<
I'll post all my code here.
When I follow other post for customizing ranges most of them have only consider display of the layered navigation. But here I have made my consideration on displaying the products when click on the final range (i.e. 1000<)
Please note that LMage is local->LMage folder and also I am a new bee for the Magento ;).
Please post here if you find a better way to do this.
class LMage_CatalogIndex_Model_Mysql4_Price extends Mage_CatalogIndex_Model_Mysql4_Price {
public function getCount($range, $attribute, $entitySelect) {
$select = clone $entitySelect;
$select->reset(Zend_Db_Select::COLUMNS);
$select->reset(Zend_Db_Select::ORDER);
$select->reset(Zend_Db_Select::LIMIT_COUNT);
$select->reset(Zend_Db_Select::LIMIT_OFFSET);
$select->join(array('price_table' => $this->getMainTable()), 'price_table.entity_id=e.entity_id', array());
$response = new Varien_Object();
$response->setAdditionalCalculations(array());
if ($attribute->getAttributeCode() == 'price') {
$select->where('price_table.customer_group_id = ?', $this->getCustomerGroupId());
$args = array(
'select' => $select,
'table' => 'price_table',
'store_id' => $this->getStoreId(),
'response_object' => $response,
);
Mage::dispatchEvent('catalogindex_prepare_price_select', $args);
}
$fields = array('count' => 'COUNT(DISTINCT price_table.entity_id)', 'range' => "FLOOR(((price_table.value" . implode('', $response->getAdditionalCalculations()) . ")*{$this->getRate()})/{$range})+1");
$select->from('', $fields)
->group('range')
->where('price_table.website_id = ?', $this->getWebsiteId())
->where('price_table.attribute_id = ?', $attribute->getId());
$result = $this->_getReadAdapter()->fetchAll($select);
$counts = array();
foreach ($result as $row) {
if ($row['range'] >= 11) {
$counts[11] = isset($counts[11])?$row['count']+$counts[11]:$row['count'];
} else {
$counts[$row['range']] = $row['count'];
}
}
return $counts;
}
public function applyFilterToCollection($collection, $attribute, $range, $index, $tableName = 'price_table') {
/**
* Distinct required for removing duplicates in case when we have grouped products
* which contain multiple rows for one product id
*/
$collection->getSelect()->distinct(true);
$tableName = $tableName . '_' . $attribute->getAttributeCode();
$collection->getSelect()->joinLeft(
array($tableName => $this->getMainTable()), $tableName . '.entity_id=e.entity_id', array()
);
$response = new Varien_Object();
$response->setAdditionalCalculations(array());
$collection->getSelect()
->where($tableName . '.website_id = ?', $this->getWebsiteId())
->where($tableName . '.attribute_id = ?', $attribute->getId());
if ($attribute->getAttributeCode() == 'price') {
$collection->getSelect()->where($tableName . '.customer_group_id = ?', $this->getCustomerGroupId());
$args = array(
'select' => $collection->getSelect(),
'table' => $tableName,
'store_id' => $this->getStoreId(),
'response_object' => $response,
);
Mage::dispatchEvent('catalogindex_prepare_price_select', $args);
}
$collection->getSelect()->where("(({$tableName}.value" . implode('', $response->getAdditionalCalculations()) . ")*{$this->getRate()}) >= ?", ($index - 1) * $range);
if($index<=10){
$collection->getSelect()->where("(({$tableName}.value" . implode('', $response->getAdditionalCalculations()) . ")*{$this->getRate()}) < ?", $index * $range);
}
return $this;
}
public function getCategoryProductPrices($attribute = null, $entitySelect) {
$select = clone $entitySelect;
$select->reset(Zend_Db_Select::COLUMNS);
$select->reset(Zend_Db_Select::ORDER);
$select->reset(Zend_Db_Select::LIMIT_COUNT);
$select->reset(Zend_Db_Select::LIMIT_OFFSET);
$response = new Varien_Object();
$response->setAdditionalCalculations(array());
$select->join(array('price_table' => $this->getMainTable()), 'price_table.entity_id=e.entity_id', array());
if ($attribute->getAttributeCode() == 'price') {
$select->where('price_table.customer_group_id = ?', $this->getCustomerGroupId());
$args = array(
'select' => $select,
'table' => 'price_table',
'store_id' => $this->getStoreId(),
'response_object' => $response,
);
Mage::dispatchEvent('catalogindex_prepare_price_select', $args);
}
$select
->from('', "(price_table.value" . implode('', $response->getAdditionalCalculations()) . ")")
->where('price_table.website_id = ?', $this->getWebsiteId())
->where('price_table.attribute_id = ?', $attribute->getId());
return $this->_getReadAdapter()->fetchAll($select);
}
}
class LMage_CatalogIndex_Model_Price extends Mage_CatalogIndex_Model_Price{
public function getCategoryProductPrices($attribute, $entityIdsFilter){
return $this->_getResource()->getCategoryProductPrices($attribute, $entityIdsFilter);
}
}
class LMage_Catalog_Model_Layer_Filter_Price extends Mage_Catalog_Model_Layer_Filter_Price {
public function getPriceRange() {
$range = $this->getData('price_range');
if (is_null($range)) {
$productsprice = $this->getCategoryProductPricesArr();
$maxPrice = $this->getMaxPriceInt();
$maxPrice = $this->getMaxPriceOfMaxOccurenceRange($productsprice, $maxPrice);
$index = 1;
do {
$range = pow(10, (strlen(floor($maxPrice)) - $index));
$items = $this->getRangeItemCounts($range);
$index++;
} while ($range > self::MIN_RANGE_POWER && count($items) < 1);
$this->setData('price_range', $range);
}
return $range;
}
public function getMaxPriceOfMaxOccurenceRange($productsprice, $maxPrice) {
$rangeArr = array();
$i = 1;
$val = 0;
do {
$val = self::MIN_RANGE_POWER * $i - 1;
$rangeArr[$val] = 0;
$i *= 10;
} while ($maxPrice > $val);
foreach ($productsprice as $value) {
$rangeArr[pow(10, strlen(floor($value['value']))) - 1]+=1;
}
return array_search(max($rangeArr), $rangeArr);
}
public function getCategoryProductPricesArr() {
$productsprice = $this->getData('products_price_arr');
if (is_null($productsprice)) {
$productsprice = Mage::getSingleton('catalogindex/price')->getCategoryProductPrices(
$this->getAttributeModel(), $this->_getBaseCollectionSql()
);
$this->setData('products_price_arr', $productsprice);
}
return $productsprice;
}
/**
* Prepare text of item label
*
* #param int $range
* #param float $value
* #return string
*/
protected function _renderItemLabel($range, $value) {
$store = Mage::app()->getStore();
if ($value > 10) {
$fromPrice = $store->formatPrice(($value - 1) * $range);
//$toPrice = $store->formatPrice($value * $range);
return Mage::helper('catalog')->__('%s < ', $fromPrice);
}
$fromPrice = $store->formatPrice(($value - 1) * $range);
$toPrice = $store->formatPrice($value * $range);
return Mage::helper('catalog')->__('%s - %s', $fromPrice, $toPrice);
}

Categories