Get Ext/Module Name of Form Element - magento

In admin configuration I have a section that has groups and fields. To one of those fields I'm doing some custom stuff via the <frontend_model> in _getElementHtml()
Is there a way to retrieve the module or extension name of the current extension within that function?
<sections>
<extensionname translate="label" module="extensionname">
<label>Extension Name</label>
sorry if my question isn't very clear... I know what I'm trying to do but stumbling in how to ask.

I'm not sure if this helps me make my question more clear but here is the solution I finally came up with...
protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element){
$modules = Mage::getConfig()->getNode('modules')->children();
$modulesArray = (array)$modules;
$module = '';
foreach($modulesArray as $k => $v){
if(strpos(strtolower($k), $this->getRequest()->getParam('section')) !== false){
$module = $k;
};
}
essentially I was wanting to get the Extensions or "Modules" name so that later on in the code I could call this
Mage::getConfig()->getNode()->modules->$module->version
that way I wouldn't have to hard code in the extension or modules name it could be dynamic...
IF.... there is a better way of doing this please let me know as I am just hacking my way through this lol.

Related

Render module in the right position from code (Joomla 2.5)

In my component view, I can show a module by this code:
$module = JModuleHelper::getModule('mod_login');
$html = JModuleHelper::renderModule($module);
echo $html;
or
echo JHtml::_('content.prepare', '{loadmodule login}');
But that will usually place the module in the middle of the screen in the main-content div.
How can I place the module in the position defined in the module params?
Take a look at how the admin template Isis renders the quickicons module on the home page or at how the error page in protostar renders the search modules.
$this->searchmodules = JModuleHelper::getModules('position-0');
foreach ($this->searchmodules as $searchmodule)
{
$output = JModuleHelper::renderModule($searchmodule, array('style' => 'none'));
$params = new JRegistry;
$params->loadString($searchmodule->params);
echo $output;
}
You just want one module, but you get the basic idea.
Try This.
You can Pass the module parameters too.
$document = &JFactory::getDocument();
$renderer = $document->loadRenderer('module');
$Module = &JModuleHelper::getModule('mod_fmDataGrid');
$Params = "param1=bruno\n\rparam2=chris";
$Module->params = $Params;
echo $renderer->render($Module);
This may help you..
You can't, jdoc includes in the template are processed after the component has finished producing its output.
Why not let Joomla render the modules in the right positions? that should be one of the reasons for using it, i.e. taking care of placement and order of modules.
If you have other reasons for doing this, please explain further.

Hide Products without images magento

I have followed this answer to hide products without images on the category listing page. It worked nicely for a while.
Now, for some reason it seems the products without images are still showing up on the listing page.
Any ideas as to why this may be happening?
Note:
The same list.phtml page is being used.
Thank you.
Add the following to list.phtm:
//$_productCollection=$this->getLoadedProductCollection();
$_productCollection = clone $this->getLoadedProductCollection();
$_productCollection->clear()
->addAttributeToFilter('small_image', array('neq' => 'no_selection'))
->load();
This answer recommended the following:
->addAttributeToFilter('image', array('neq' => 'no_selection'))
Whereas I have set it to:
->addAttributeToFilter('small_image', array('neq' => 'no_selection'))
The reason the previous answer did not work was because the product collection doesn't load the regular image, and therefore the regular image cannot be added as an attribute to filter, so instead, I added the small_image as the attribute to filter.
You can also try R.S's answer where he adds the image to the page and hence the collection. You may have to also add all attributes using:
->addAttributeToSelect('*')
There are some tricks to keeping Magento in line. One thing I've learned is that the Magento Model will change for many different reasons, and its kinda hard to figure out why. There are better ways to do this (modifying the collection, etc) but it sometimes just does not work and you don't have days to figure out why.
If you want a surefire way to make sure your image exists, use the following code... It may not be the 'magento way' but it works, and I tested it on my site (Magento EE 1.12). Put it in a function, or use it directly in your phtml if you want!
It basically just makes sure the URL exists.
$exists = false;
$entity_id = 8800;
$product = Mage::getModel('catalog/product')->load($entity_id);
$mediaUrl= Mage::getBaseUrl('media');
$imageUrl = $mediaUrl . "catalog/product" . $product->getImage();
$file_headers = #get_headers($imageUrl);
if($file_headers[0] == 'HTTP/1.1 404 Not Found') {
$exists = false;
}
else {
$exists = true;
}
var_dump($exists);
var_dump($imageUrl);
echo '<img src="' . $imageUrl . '" />';
$exists will either be true (image does exist) or false (image does not)
I think that the issue is that you are trying to get the 'image' (base image) property on the list.phtml (by default i can only access the thumbnail, small_image).
On list.phtml (not loading the full product resource like on view.pthml)
echo $_product->getImage() //null
echo $_product->getThumbnail() // path/name.jpg
echo $_product->getSmallImage() // path/name.jpg
I think you may need to add adding something like this to app/design/frontend/default/yourtheme/layout/catalog.xml
<action method="addAttribute"><name>image</name></action>
See How to get access to custom Image Attribute in list.phtml in Magento

Where is Itemid used to flag active menu item in Joomla 2.5.6?

Can anyone please help me with the process flow through which the Joomla Itemid parameter ends up being the highlighted menu item?
I have embedded a 3rd party application in Joomla and by temporarily changing the php environment within the application.
I am able to get joomla html and insert the 3rd party html by replacing a token.
Simplified Code:
if ($_SERVER['REQUEST_METHOD'] == 'GET' ) {
$_SERVER['REQUEST_METHOD'] = '';
}
$_SERVER['REQUEST_URI'] = '/joomla/index.php?view=mycom&option=com_mycom&Itemid=103';
$_SERVER['SCRIPT_NAME'] = $_SERVER['PHP_SELF'] = '/joomla/index.php';
$_SERVER['QUERY_STRING'] = 'view=mycom&option=com_mycom&Itemid=103';
ob_start();
require_once '/joomla/index.php';
$joomlaHTML = ob_get_clean();
echo str_replace($replacementToken, $thirdPartyHTML, $joomlaHTML);
In v1.5.x, the menu item with ID 103 is properly highlighted but in v2.5.6, it isn't and the Home item is always highlighted. I think it used to be highlighted correctly in v1.6.x and earlier versions of 2.5.x as well but not sure.
I wanted to find how the process flows (where this is set) so I can see what tweaks I need to make.
DELETED WRONG INFO
Thanks Dayo! you saved my day with this:
// force highlight the external url menu item
$Itemid = JRequest::getVar('Itemid');
$menu = JSite::getMenu();
$menu->setActive($Itemid);
I don't fully understand the breadcrumb part, but I managed to get it working by editing my component's controller.php to read:
// No direct access to this file
defined('_JEXEC') or die('Restricted access');
// force highlight the external url menu item
$Itemid = JRequest::getVar('Itemid');
$menu = JSite::getMenu();
$menu->setActive($Itemid);
// force fix the breadcrumb
$app = JFactory::getApplication('site');
$pathway =& $app->getPathway();
$bcrumbs = &JPathway::getInstance('site');
// import Joomla controller library
jimport('joomla.application.component.controller');
/**
* MyCom Component Controller
*/
class MyComController extends JController
{
}
Look in the following File
Check the
/modules/mod_menu/mod_menu.php
File and you will see two functions has been called "getActive" and "getDefault"
Which can be find in following file
/libraries/joomla/application/menu.php
I think it can be customized easily now

getAddressesHtmlSelect() Change - Magento

I've been trying to edit the getAddressesHtmlSelect() function (found in code/core/Mage/Checkout/Block/Onepage/abstract.php) in order to enable the "new address" to display first in the dropdpown created.
I've located the place it needs to be changed in, but I can't figure out how to do that. Can anyone help? The code in question is:
$select = $this->getLayout()->createBlock('core/html_select')
->setName($type.'_address_id')
->setId($type.'-address-select')
->setClass('address-select')
->setExtraParams('onchange="'.$type.'.newAddress(!this.value)"')
->setValue($addressId)
->setOptions($options);
$select->addOption('', Mage::helper('checkout')->__('New Address'));
return $select->getHtml();
Look for magento block rewrite.
You need to rewrite Mage_Checkout_Block_Onepage_Billing and Mage_Checkout_Block_Onepage_Shipping
Just rewrite this blocks in your custom module and define new logic for getAddressesHtmlSelect
function
To set "New address" as default one:
Assembled working sample for you.
array_unshift($options, array('value' => '', 'label'=> Mage::helper('checkout')->__('New Address')));
$select = $this->getLayout()->createBlock('core/html_select')
->setName($type.'_address_id')
->setId($type.'-address-select')
->setClass('address-select')
->setExtraParams('onchange="'.$type.'.newAddress(!this.value)"')
->setOptions($options);
return $select->getHtml();

Joomla - renderModule function strips javascript

please help, I've a problem with Joomla's function renderModule.. I am trying to render module with this function, but it unfortunately strips javascript from the the rendered module.
I use the function in my own module which includes other modules according to current article..
The code is as following:
<?php
$moduleType = "j15html";
$moduleName = "test";
$option = JRequest::getVar( 'option', '' );
$view = JRequest::getVar( 'view', '' );
$id = JRequest::getInt( 'id', 0 );
$moduleName .= $id;
//echo $view;
if ( $option == "com_content" && $view == "article" ) {
//echo $moduleName;
$module = JModuleHelper::getModule($moduleType, $moduleName);
//print_r($module);
if ( ! empty( $module ) ) {
$attribs = array();
echo JModuleHelper::renderModule( $module, $attribs );
}
}
When I set the position of the included module to any position used in my template and set it to displat in particular menu section, it renders properly even with javascript and so on..
Any advices how to make this thing working?
You didn't mention which version of Joomla you're using - but you may want to check out SOURCERER it keeps coding how you put it and does not strip out extra coding.
Make sure you read the how-to so you know how to use it because it can seem a little confusing at first, but it has a button to 'change the tags' from < to << or [ which do not get stripped out by the WYSIWYG editor in Joomla!.
Of course, that could be your issue also, if your WYSIWYG editor is on (by default it is) and you're inputting code - it strips it. An easy way is to just turn it off under global options, then when you save the code doesn't get stripped. Just turning off the WYSIWYG editor is the quick/easy/simple solution - but if you turn it back on and open that module again, the code will be gone. So it can be a tricky solution if others may like using the editor or if you're using lots of custom code around your side. In that case the plugin I mentioned above is a great solution.

Resources