`
kirenenko04
  • 浏览: 151056 次
  • 性别: Icon_minigender_2
  • 来自: 上海
社区版块
存档分类
最新评论

manufacturer list alphabetical order

 
阅读更多

in Block File:

<?php
class Bysoft_Mypage_Block_Manufacturer extends Mage_Core_Block_Template  {
	
	public function getAllBrands($cate_id, $first='') {
		
		$is_test = true;//display all brands ignore category
		
		$manu_content = array();
		
		if ($is_test ===false) {
			// filter by category 
			$category           = Mage::getModel('catalog/category')->load($cate_id);
			$layer              = Mage::getSingleton('catalog/layer');
			$layer->setCurrentCategory($category);
			$attributes = $layer->getFilterableAttributes();
			$manufacturers = array();
			foreach ($attributes as $attribute) {
				if ($attribute->getAttributeCode() == 'manufacturer') {
					$filterBlockName = 'catalog/layer_filter_attribute';
					$result = Mage::app()->getLayout()->createBlock($filterBlockName)->setLayer($layer)->setAttributeModel($attribute)->init();
					foreach($result->getItems() as $option) {
						$manufacturers[] = $option->getData();
					}
				}
			}
		} else {
			//get all, ignore category
			$product = Mage::getModel('catalog/product');
			$attributes = Mage::getResourceModel('eav/entity_attribute_collection')
			->setEntityTypeFilter($product->getResource()->getTypeId())
			->addFieldToFilter('attribute_code', 'manufacturer');
			$attribute = $attributes->getFirstItem()->setEntity($product->getResource());
			$manufacturers = $attribute->getSource()->getAllOptions(false);
		}
		
		$this->array_sort_by_column($manufacturers, 'label');
		
		foreach ($manufacturers as $key=>$m) {
			$manufacturers[$key]['first'] = mb_substr($m['label'],0,1,'utf-8');
			if ($first == '1') {
				$number = array('0','1','2','3','4','5','6','7','8','9');
				if (in_array($manufacturers[$key]['first'], $number)) {
					$manu_content[] = $manufacturers[$key];
				}
			} else if ($first) {
				if ($first == $manufacturers[$key]['first']) {
					$manu_content[] = $manufacturers[$key];
				}
			} else if ($first == '') {
				$manu_content[] = $manufacturers[$key];
			}
		}
		return array('title'=>$manufacturers,'content'=>$manu_content);
	}
	

	function array_sort_by_column(&$arr, $col, $dir = SORT_ASC) {
		$sort_col = array();
		foreach ($arr as $key=> $row) {
			$sort_col[$key] = $row[$col];
		}
		array_multisort($sort_col, $dir, $arr);
	}
	
	public function getAllBrandsByCate($cate_id) {
		$category           = Mage::getModel('catalog/category')->load($cate_id);
		$layer              = Mage::getSingleton('catalog/layer');
		$layer->setCurrentCategory($category);
		$attributes = $layer->getFilterableAttributes();
		$manufacturers = array();
		foreach ($attributes as $attribute) {
			if ($attribute->getAttributeCode() == 'manufacturer') {
				$filterBlockName = 'catalog/layer_filter_attribute';
				$result = Mage::app()->getLayout()->createBlock($filterBlockName)->setLayer($layer)->setAttributeModel($attribute)->init();
				foreach($result->getItems() as $option) {
					$manufacturers[$option->getValue()] = $option;
				}
			}
		}
		return $manufacturers;
		
	}
}

 In phtml File:

 

<?php 
$cate_id = Mage::app()->getRequest()->getParam('cate_id');
$first_url = Mage::app()->getRequest()->getParam('first');
$manus = $this->getAllBrands($cate_id,$first_url);
$sub_cate = Mage::getModel('catalog/category')->load($cate_id);
$first = '';
$first_arr = array();
?>
<div class="index-div">
<a href="<?php echo $this->getUrl('mypage/index/manufacturer',array('cate_id'=>$cate_id));?>"><?php echo $this->__('All')?></a> | 
<a href="<?php echo $this->getUrl('mypage/index/manufacturer',array('cate_id'=>$cate_id,'first'=>'1'));?>"><?php echo $this->__('0 - 9');?></a> | 
<?php foreach ($manus['title'] as $index):?>
	<?php if (($first == '' || $first!=$index['first']) && $index['first'] > '9'):?>
		<?php $first = $index['first'];?>
		<?php $first_arr[] = $index['first'];?>
	<?php endif;?>
<?php endforeach;?>
<?php foreach ($first_arr as $key=>$fa):?>
	<a href="<?php echo $this->getUrl('mypage/index/manufacturer',array('cate_id'=>$cate_id,'first'=>$fa));?>"><?php echo $fa;?></a> 
	<?php if ($key < count($first_arr) -1):?>
	|
	<?php endif;?>
<?php endforeach;?>
</div>
<?php $first = '';?>
<div class="manu-content">
<ul>
<li class="top-letter"><a name="0-9"></a>0-9</li>
<?php foreach ($manus['content'] as $manu):?>
<?php if (($first == '' || $first!=$manu['first']) && $manu['first'] > '9'):?>
	<?php $first = $manu['first'];?>
	<li class="top-letter"><a name="<?php echo $first?>"></a><?php echo $first?></li>
<?php endif;?>
<?php $cate_manu_url = $sub_cate->getUrl().'?manufacturer='.$manu['value'];?>
<li > <a title="<?php echo $manu['label'];?>" href="<?php echo $cate_manu_url;?>"><?php echo $manu['label'];?></a>
</li>
<?php endforeach;?>
</ul>
</div>

 

 

分享到:
评论

相关推荐

    前端开源库-eslint-plugin-import-order-alphabetical

    `eslint-plugin-import-order-alphabetical` 是一个针对这个需求的开源库,它是一个`ESLint`插件,用于规范项目的导入顺序,确保所有导入语句按照字母顺序排列。这个插件可以帮助开发者自动检查和修复导入模块时的...

    Alphabetical_list_of_freepublic_domain_datasets

    Alphabetical_list_of_freepublic_domain_datasets_w_nlp-datasets_w_nlp-datasets.zip

    eslint-plugin-import-order-alphabetical:已淘汰

    `eslint-plugin-import-order-alphabetical`是一个ESLint插件,专门用于管理代码中的导入语句顺序,按照字母顺序排列,以提高代码可读性和团队协作效率。然而,根据提供的信息,这个插件已被标记为“已淘汰”,这...

    EnglishWords_alphabetical_194433.7z

    标题“EnglishWords_alphabetical_194433.7z”暗示了这是一个与英语词汇相关的项目。这个压缩包包含了一个程序,该程序能够处理194433个英语单词,并按照字母顺序排列。这可能是为了创建一个词汇表或者帮助用户学习...

    alphabetical-order:单词字母按字母顺序排列

    按字母顺序 工作CodePen: ://codepen.io/captainpainway/pen/LpYPja 少数单词的字母按字母顺序排列,如果您要沿英语字母扫描,则单词中的任何地方都不会改变单词的方向。 一个例子是单词“ almost”,它的字母按...

    微信小程序-微信小程序带字母滑动的listview

    5. **性能优化**:由于列表可能包含大量数据,微信小程序提供了虚拟列表(`virtual-list`)的概念,只渲染可视区域内的元素,降低内存占用和渲染开销。在`wx-alphabetical-listview`中,可能会结合虚拟列表来提高...

    poj 1007 DNA Sorting

    However, you want to catalog them, not in alphabetical order, but rather in order of ``sortedness'', from ``most sorted'' to ``least sorted''. All the strings are of the same length. Input The ...

    Lecture_1_Introduction.pdf

    - Method 2 (alphabetical order) is generally more efficient than Method 1 (random insertion) for finding books, but it requires more careful organization. - Method 3 (clustering by topic) can ...

    TopCoder: SmartWordToy

    Below each letter are two buttons that cause the letter above to change to the previous or next letter in alphabetical order. So, with one click of a button the letter 'c' can be changed to a 'b' or ...

    GNS3-2.2.27-all-in-one.exe

    Fix symbols in "Symbol selection" dialog are not placed in alphabetical order. Fixes #3245 Fix link duplicates in topology summary. Fixes #3251 chore : use --no-cache-dir flag to pip in dockerfiles to...

    ANSYS Mechanical APDL Command Reference.pdf

    descriptions, arranged in alphabetical order. It is the definitive resource for correct command usage, providing comprehensive specifications for every argument of every command. The Command ...

    西电软工oop上机题目2 7.10-7.rar

    Consider:Write a function for entering new words into a tree of Tnodes. Write a function to write out a tree of ... Write a function to write out a tree of Tnodes with the words in alphabetical order.

    电路设计百科全书 1000 Circuits

    各类常用电路图,以及详细注释 1.Audio Circuits 2.Consumer circuits 3.Dislay 4.General Electronics 5.Measurement and Sensor Electronics 6.Power and Battery Circuits ...9.Topics in AlphaBetical Order

    MySQL Cookbook

    MySQL programming interfaces exist for many languages, including (in alphabetical order) C, C++, Eiffel, Java, Pascal, Perl, PHP, Python, Ruby, Smalltalk, and Tcl.[] Given this fact, writing a MySQL ...

    Word Amalgamation

    For each scrambled word in the input, output an alphabetical list of all dictionary words that can be formed by rearranging the letters in the scrambled word. Each word in this list must appear on a ...

    is-alphabetical:检查字符是否为(ASCII)字母

    : npm install is-alphabetical用import { isAlphabetical } from 'is-alphabetical'isAlphabetical ( 'a' ) // =&gt; trueisAlphabetical ( 'B' ) // =&gt; trueisAlphabetical ( '0' ) // =&gt; falseisAlphabetical ( ':...

    word smith tools

    The WordList tool lets you see a list of all the words or word-clusters in a text, set out in alphabetical or frequency order. The concordancer, Concord, gives you a chance to see any word or phrase ...

    Alphabetical Navigation Bar Display Tag-开源

    标题中的"Alphabetical Navigation Bar Display Tag"是一个Java开发的开源项目,主要目的是为了实现一个功能性的字母导航栏。这个导航栏能够帮助用户更高效地浏览和筛选存储在`java.util.List`对象中的大量字符串...

    经典的DSP程序库.rar

    /* SPALIB.C SUBPROGRAMS IN ALPHABETICAL ORDER IN THE C PROGRAMMING LANGUAGE */ /* SPPLOT.C Plot File Routines for SIGNAL PROCESSING ALGORITHMS. */ /* SPTEST */ /* SPXAMP.C is a file of files. ...

    alphabetical-grid-extension:恢复应用程序网格的字母顺序,在 GNOME 3.38 中删除

    按字母顺序排列的应用程序网格 GNOME 扩展 恢复应用程序网格的字母顺序,在 GNOME 3.38 中删除支持 GNOME 3.38+,早期版本未经测试,不需要从获取扩展本项目已获得 GPL 3.0 许可任何捐赠都非常感谢:)从发行版安装...

Global site tag (gtag.js) - Google Analytics