Remove anchor tag from a particular subcategory in Magento - magento

I want to disable the anchor tag of two subcategories. I used a free extension for topmenu. The code for subcategory menu is:
public function drawMenuItem($children, $level = 1)
{
$html = '<div class="itemMenu level' . $level . '">';
$keyCurrent = $this->getCurrentCategory()->getId();
foreach ($children as $child) {
if (is_object($child) && $child->getIsActive()) {
// --- class for active category ---
$active = '';
if ($this->isCategoryActive($child)) {
$active = ' actParent';
if ($child->getId() == $keyCurrent) $active = ' act';
}
// --- format category name ---
$name = $this->escapeHtml($child->getName());
if (Mage::getStoreConfig('custom_menu/general/non_breaking_space')) $name = str_replace(' ', ' ', $name);
$html.= '<a class="itemMenuName level' . $level . $active . '" href="' . $this->getCategoryUrl($child) . '"><span>' . $name . '</span></a>';
$activeChildren = $this->_getActiveChildren($child, $level);
if (count($activeChildren) > 0) {
$html.= '<div class="itemSubMenu level' . $level . '">';
$html.= $this->drawMenuItem($activeChildren, $level + 1);
$html.= '</div>';
}
}
}
$html.= '</div>';
return $html;
}
I tried to disable the two subcategories. But it didn't work. How can I give proper condition to disable particular two subcategories link?

Related

Sitemap-XML in Processwire 3

how can i generate a sitemap for processwire 3 for huebert-webentwicklung.de/sitemap.xml it doesen't work with the Plugin MarkupSitemapXML. Any idea how to get it work?
Thanks.
Create a new page template (sitemap.xml) then set the page output to be XML the the PW backend. Create a page and link it (set it to hidden).
function renderSitemapPage(Page $page) {
return
"\n<url>" .
"\n\t<loc>" . $page->httpUrl . "</loc>" .
"\n\t<lastmod>" . date("Y-m-d", $page->modified) . "</lastmod>" .
"\n</url>";
}
function renderSitemapChildren(Page $page) {
$out = '';
$newParents = new PageArray();
$children = $page->children;
foreach($children as $child) {
$out .= renderSitemapPage($child);
if($child->numChildren) $newParents->add($child);
else wire('pages')->uncache($child);
}
foreach($newParents as $newParent) {
$out .= renderSitemapChildren($newParent);
wire('pages')->uncache($newParent);
}
return $out;
}
function renderSitemapXML(array $paths = array()) {
$out = '<?xml version="1.0" encoding="UTF-8"?>' . "\n" . '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">';
array_unshift($paths, '/'); // prepend homepage
foreach($paths as $path) {
$page = wire('pages')->get($path);
if(!$page->id) continue;
$out .= renderSitemapPage($page);
if($page->numChildren) $out .= renderSitemapChildren($page);
}
$out .= "\n</urlset>";
return $out;
}
header("Content-Type: text/xml");
echo renderSitemapXML();

Where put displaying tree logic?

I have a function which builds category tree:
public static function buildSelectTree($tree, $step = 0) {
$result = '';
foreach ($tree as $element) {
$result .= "<option>";
$result .= str_repeat('--', $step) . ' ' . $element->name;
$result .= '</option>';
if ($element->children) {
$result .= self::buildSelectTree($element->children, $step + 1);
}
}
return $result;
}
Is it okay to put it in a model? Or I should put it somewhere else? I don't like the idea to work with html inside a model

Errors, warning, notices with a cross to hide them using Jquery. How to extend the core message class in a right way to achieve this?

I want my error, warning, notification messages on frontend to extend a bit. So,
I need to override
Mage_Core_Block_Messages
class's
public function getGroupedHtml()
{
$types = array(
Mage_Core_Model_Message::ERROR,
Mage_Core_Model_Message::WARNING,
Mage_Core_Model_Message::NOTICE,
Mage_Core_Model_Message::SUCCESS
);
$html = '';
foreach ($types as $type) {
if ( $messages = $this->getMessages($type) ) {
if ( !$html ) {
$html .= '<' . $this->_messagesFirstLevelTagName . ' class="messages">';
}
$html .= '<' . $this->_messagesSecondLevelTagName . ' class="' . $type . '-msg">';
$html .= '<' . $this->_messagesFirstLevelTagName . '>';
foreach ( $messages as $message ) {
$html.= '<' . $this->_messagesSecondLevelTagName . '>';
$html.= '<' . $this->_messagesContentWrapperTagName . '>';
$html.= ($this->_escapeMessageFlag) ? $this->htmlEscape($message->getText()) : $message->getText();
$html.= '</' . $this->_messagesContentWrapperTagName . '>';
$html.= '</' . $this->_messagesSecondLevelTagName . '>';
}
$html .= '</' . $this->_messagesFirstLevelTagName . '>';
$html .= '</' . $this->_messagesSecondLevelTagName . '>';
}
}
if ( $html) {
$html .= '</' . $this->_messagesFirstLevelTagName . '>';
}
return $html;
}
to extend the html and put a cross in the message box and implement Jquery. logic: on click close hide error box. So customers can upon click hide the box.
I believe this class doesn't have any template file and the html it is rendering from the this block class itself as I can see in getGroupedHtml() method.
So, I am going to override this method and add more html.
Also, I want to do this only for one theme and not in Admin
What is the better way to achieve this?
Please suggest me something. Thanks
You could accomplish this without overriding anything and by just going for JavaScript (jQuery) only.
Here is a simple script that should do the job.
var messages = jQuery("ul.messages li[class$='-msg']");
messages.each(function(){
var message = jQuery(this);
message.find('span').append('<span class="close">X</span>');
});
messages.on('click', function(){
var message = jQuery(this).closest("li[class$='-msg']");
message.hide();
});
The script adds a 'X' to the end of every message and removes (hides) the message when it's clicked.
The only thing left to do is to give the cross (span X) some styling.
You could place this in your footer template for the correct theme.

Joomla custom field type when editing

how do make it so that when I edit an entry, the correct value for my custom field type is selected? I have this so far:
class JFormFieldCustom extends JFormField {
protected $type = 'Custom';
// getLabel() left out
public function getInput() {
return '<select id="'.$this->id.'" name="'.$this->name.'">'.
'<option value="1" >1</option>'.
'<option value="2" >2</option>'.
'</select>';
}
}
How do I pass the selected value to this class so I can do:
<option value="1"SELECTED>1</option>
or
<option value="2" SELECTED>2</option>
Thanks!
It's easier to use what's already there, i.e. extend JFormFieldList in place of JFormField, then all you have to do is return the option's for your list. The inherited functionality will do the rest for you - including selecting the option that matches $this->value
<?php
/**
* Do the Joomla! security check and get the FormHelper to load the class
*/
defined('_JEXEC') or die('Restricted Access');
JFormHelper::loadFieldClass('list');
class JFormFieldMyCustomField extends JFormFieldList
{
/**
* Element name
*
* #var string
*/
public $type = 'MyCustomField';
/**
* getOptions() provides the options for the select
*
* #return array
*/
protected function getOptions()
{
// Create an array for our options
$options = array();
// Add our options to the array
$options[] = array("value" => 1, "text" => "1);
$options[] = array("value" => 1, "text" => "1);
return $options;
}
}
Use $this->value to get selected value.Try this-
class JFormFieldCustom extends JFormField {
protected $type = 'Custom';
// getLabel() left out
public function getInput() {
return '<select id="'.$this->id.'" name="'.$this->name.'">'.
'<option value="1" <?php echo ($this->value==1)?'selected':''?>>1</option>'.
'<option value="2" <?php echo ($this->value==2)?'selected':''?>>2</option>'.
'</select>';
}
}
Hope this will help.
Select for Joomla
http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL
* #copyright (c) 2017 YouTech Company. All Rights Reserved.
* #author macasin
*/
defined('_JEXEC') or die;
JFormHelper::loadFieldClass('list');
class JFormFieldSelect extends JFormFieldList
{
protected $type = 'select';
protected function getInput()
{
$html = array();
$attr = '';
// Initialize some field attributes.
$attr .= !empty($this->class) ? ' class=select ' . $this->class . '"' : ' class=select ';
$attr .= $this->readonly ? ' readonly' : '';
$attr .= $this->disabled ? ' disabled' : '';
$attr .= !empty($this->size) ? ' size="' . $this->size . '"' : '';
$attr .= $this->required ? ' required aria-required="true"' : '';
// Initialize JavaScript field attributes.
$attr .= $this->onchange ? ' onchange="' . $this->onchange . '"' : '';
// Get the field options.
$options = $this->getOptions();
// Load the combobox behavior.
JHtml::_('behavior.combobox');
$html[] = '<div class="select input-append">';
// Build the input for the combo box.
$html[] = '<select name="' . $this->name . '" id="' . $this->id . '" value="'
. htmlspecialchars($this->value, ENT_COMPAT, 'UTF-8') . '"' . $attr . ' autocomplete="off" >';
foreach ($options as $option)
{
$html[] = '<option '.($option->value == $this->value ? "selected" : "").' value='.$option->value.'>' . $option->text . '</option>';
}
$html[] = '</select></div>';
return implode($html);
}
}

Magento not recognizing custom Topmenu.php

I have built a custom module to enable changing the Topmenu link text based on a custom attribute in the backend.
The module was tested on Magento CE 1.7.02 and works 100%.
Now I am testing on Magento EE 1.12.02 and the menu is not recognizing the rewritten Topmenu class (As-in, I can remove everything from the file, and/or mis-spell the class name in the XML and there are no errors, and the site loads fine).
Something tells me that Enterprise Edition pulls this menu from a different location than Community Edition, but I cannot find the place.
Here is the relevant portion of my config XML:
<blocks>
<page>
<rewrite>
<html_topmenu>WorldSynergy_Seoadditions_Block_Html_Topmenu</html_topmenu>
</rewrite>
</page>
</blocks>
And here is the Topmenu.php class:
class WorldSynergy_Seoadditions_Block_Html_Topmenu extends Mage_Page_Block_Html_Topmenu
{
/**
* Recursively generates top menu html from data that is specified in $menuTree
*
* #param Varien_Data_Tree_Node $menuTree
* #param string $childrenWrapClass
* #return string
*/
protected function _getHtml(Varien_Data_Tree_Node $menuTree, $childrenWrapClass)
{
$html = '';
$children = $menuTree->getChildren();
$parentLevel = $menuTree->getLevel();
$childLevel = is_null($parentLevel) ? 0 : $parentLevel + 1;
$counter = 1;
$childrenCount = $children->count();
$parentPositionClass = $menuTree->getPositionClass();
$itemPositionClassPrefix = $parentPositionClass ? $parentPositionClass . '-' : 'nav-';
foreach ($children as $child) {
$child->setLevel($childLevel);
$child->setIsFirst($counter == 1);
$child->setIsLast($counter == $childrenCount);
$child->setPositionClass($itemPositionClassPrefix . $counter);
$outermostClassCode = '';
$outermostClass = $menuTree->getOutermostClass();
if ($childLevel == 0 && $outermostClass) {
$outermostClassCode = ' class="' . $outermostClass . '" ';
$child->setClass($outermostClass);
}
$childId = explode( "-" , $child->getId() );
$childId = $childId[2];
$attrs = Mage::getModel("catalog/category")->getAttributes();
$altName = $attrs['ws_menutitle']->getFrontEnd()->getValue( Mage::getModel("catalog/category")->load( $childId ) );
if( empty($altName) ){ $altName = $child->getName(); }
$html .= '<li ' . $this->_getRenderedMenuItemAttributes($child) . '>';
$html .= '<a href="' . $child->getUrl() . '" ' . $outermostClassCode . '><span>ABC'
. $this->escapeHtml($altName) . '</span></a>';
if ($child->hasChildren()) {
if (!empty($childrenWrapClass)) {
$html .= '<div class="' . $childrenWrapClass . '">';
}
$html .= '<ul class="level' . $childLevel . '">';
$html .= $this->_getHtml($child, $childrenWrapClass);
$html .= '</ul>';
if (!empty($childrenWrapClass)) {
$html .= '</div>';
}
}
$html .= '</li>';
$counter++;
}
return $html;
}
}
I'm in 1.11.1.0, but I believe the same exact thing is happening.
If you look at app/design/frontend/base/default/layout/page.xml, you'll see that the top.menu block is missing the page/html_topmenu block that CE has.
<block type="core/text_list" name="top.menu" as="topMenu" translate="label">
<label>Navigation Bar</label>
</block>
Then, in app/design/frontend/base/default/layout/catalog.xml, they're inserting the catalog navigation block into the top.menu block:
<reference name="top.menu">
<block type="catalog/navigation" name="catalog.topnav" template="catalog/navigation/top.phtml"/>
</reference>
Strange that they did all of this in app/design/frontend/base, and not app/design/frontend/enterprise.

Resources