Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2017
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.47 KB | None | 0 0
  1. $category = array('Your Category Id' => array('Price','Your attribute title'));
  2.  
  3. <?php $currentCategory = Mage::registry('current_category')->getId(); ?>
  4. <?php foreach ($_filters as $_filter): ?>
  5. <?php if($_filter->getItemsCount()): ?>
  6. <?php if(in_array($_filter->getName(),$category[$currentCategory])){
  7. continue;
  8. } ?>
  9. <dt><?php echo $this->__($_filter->getName()) ?></dt>
  10. <dd><?php echo $_filter->getHtml() ?></dd>
  11. <?php endif; ?>
  12. <?php endforeach; ?>
  13.  
  14. if (Mage::app()->getFrontController()->getAction()->getFullActionName() == 'catalogsearch_result_index') {
  15. // The current page is the search page
  16. }
  17.  
  18. protected function _prepareLayout()
  19. {
  20. $stateBlock = $this->getLayout()->createBlock($this->_stateBlockName)
  21. ->setLayer($this->getLayer());
  22.  
  23. $categoryBlock = $this->getLayout()->createBlock($this->_categoryBlockName)
  24. ->setLayer($this->getLayer())
  25. ->init();
  26.  
  27. $this->setChild('layer_state', $stateBlock);
  28. $this->setChild('category_filter', $categoryBlock);
  29.  
  30. $filterableAttributes = $this->_getFilterableAttributes();
  31. foreach ($filterableAttributes as $attribute) {
  32. if (
  33. Mage::registry('current_category')->getId() == 19
  34. && in_array($attribute->getAttributeCode(), array('style'))
  35. ) {
  36. continue;
  37. }
  38.  
  39. if ($attribute->getAttributeCode() == 'price') {
  40. $filterBlockName = $this->_priceFilterBlockName;
  41. } elseif ($attribute->getBackendType() == 'decimal') {
  42. $filterBlockName = $this->_decimalFilterBlockName;
  43. } else {
  44. $filterBlockName = $this->_attributeFilterBlockName;
  45. }
  46.  
  47.  
  48.  
  49. $this->setChild($attribute->getAttributeCode() . '_filter',
  50. $this->getLayout()->createBlock($filterBlockName)
  51. ->setLayer($this->getLayer())
  52. ->setAttributeModel($attribute)
  53. ->init());
  54. }
  55.  
  56. $this->getLayer()->apply();
  57.  
  58. return parent::_prepareLayout();
  59. }
  60.  
  61. public function getFilters()
  62. {
  63. $filters = array();
  64. if ($categoryFilter = $this->_getCategoryFilter()) {
  65. $filters[] = $categoryFilter;
  66. }
  67.  
  68. $filterableAttributes = $this->_getFilterableAttributes();
  69. foreach ($filterableAttributes as $attribute) {
  70. $filters[] = $this->getChild($attribute->getAttributeCode() . '_filter');
  71. }
  72.  
  73. foreach ($filters as $filter) {
  74. if ($filter !== false) {
  75. $result[] = $filter;
  76. }
  77.  
  78. }
  79.  
  80. return $result;
  81. }
  82.  
  83. if (
  84. Mage::registry('current_category')->getId() == 19
  85. && in_array($attribute->getAttributeCode(), array('style'))
  86. ) {
  87. continue;
  88. }
  89.  
  90. foreach ($filters as $filter) {
  91. if ($filter !== false) {
  92. $result[] = $filter;
  93. }
  94.  
  95. }
  96.  
  97. return $result;
  98.  
  99. <?php
  100. /**
  101. * Category layered navigation
  102. *
  103. * @see Mage_Catalog_Block_Layer_View
  104. */
  105. ?>
  106. <?php $pageIdentifier = Mage::app()->getFrontController()->getAction()->getFullActionName() ?>
  107. <?php if ($pageIdentifier!='catalogsearch_result_index'): ?>
  108. <?php $currentCategory = Mage::registry('current_category')->getId() ?>
  109. <?php $filterCategory['63'] = array('Price') ?>
  110. <?php $filterCategory['89'] = array('Manufacturer') ?>
  111. <?php endif; ?>
  112. <?php if($this->canShowBlock()): ?>
  113. <div class="block block-layered-nav">
  114. <div class="block-title">
  115. <strong><span><?php echo $this->__('Shop By') ?></span></strong>
  116. </div>
  117. <div class="block-content">
  118. <?php echo $this->getStateHtml() ?>
  119. <?php if ($this->getLayer()->getState()->getFilters()): ?>
  120. <div class="actions"><a href="<?php echo $this->getClearUrl() ?>"><?php echo $this->__('Clear All') ?></a></div>
  121. <?php endif; ?>
  122. <?php if($this->canShowOptions()): ?>
  123. <p class="block-subtitle"><?php echo $this->__('Shopping Options') ?></p>
  124. <dl id="narrow-by-list">
  125. <?php $_filters = $this->getFilters() ?>
  126. <?php foreach ($_filters as $_filter): ?>
  127. <?php if($_filter->getItemsCount()): ?>
  128. <?php if(in_array($_filter->getName(),$filterCategory[$currentCategory])) continue ?>
  129. <dt><?php echo $this->__($_filter->getName()) ?></dt>
  130. <dd><?php echo $_filter->getHtml() ?></dd>
  131. <?php endif; ?>
  132. <?php endforeach; ?>
  133. </dl>
  134. <script type="text/javascript">decorateDataList('narrow-by-list') </script>
  135. <?php endif; ?>
  136. </div>
  137. </div>
  138. <?php endif; ?>
  139.  
  140. public function hideAttributes($attributeCodes)
  141. {
  142. $attributeCodes = array_map('trim', explode(',', $attributeCodes));
  143. $this->setData('hide_attributes', $attributeCodes);
  144. }
  145.  
  146. public function getFilters()
  147. {
  148. $filters = array();
  149. if ($categoryFilter = $this->_getCategoryFilter()) {
  150. $filters[] = $categoryFilter;
  151. }
  152.  
  153. $filterableAttributes = $this->_getFilterableAttributes();
  154. # added line
  155. $hiddenAttributes = $this->getHideAttributes();
  156. foreach ($filterableAttributes as $attribute) {
  157. # added line
  158. if (!$hiddenAttributes || (is_array($hiddenAttributes) && !in_array($attribute->getAttributeCode(), $hiddenAttributes))) { # added
  159. $filters[] = $this->getChild($attribute->getAttributeCode() . '_filter');
  160. }
  161. }
  162.  
  163. return $filters;
  164. }
  165.  
  166. <reference name="catalog.leftnav">
  167. <action method="hideAttributes"><code>price,manufacturer</code></action>
  168. </reference>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement