open a modal windows in a server - joomla

Hi everyone I have a modal windows in joomla 3.0!
I pass the router to javascript like this
<?php $link =JURI::root().'index.php?option=com_projects&view=proyectos&format=raw&task=todosProyecto&id='. $item->id;?>
<li class="item" data-id="id-<?php echo $item->id ?>" data-type="<?php echo $item->categoria ?>">
<a href="#modal" id="<?php echo $link;?>" role="<?php echo $item->id ?>" class="picture" data-toggle="modal">
<img src="<?php echo JURI::root()?><?php echo $item->imagen_portada; ?>"/></a>
<p class="titulo"><?php echo $item->nombre; ?></p>
<p> <?php echo $item->municipio; ?>(<?php echo $item->pais; ?>)<br><?php echo $item->year; ?>
</p>
In local when I open the modal windows it work well, but in the server the modal windows show me the index.php view of this component.
I think that my problem is here, when I take the request for the model I have this.
public function elegirSeleccionados(){
$this->pagination = $this->get('pagination');
$this->items = $this->get('recientes');
$this->list = $this->get('list');
parent::display();
}
But $this->get('list'); is null so I have to asigned a null value to list.
I changed by that..
$this->list = $this->items;
but dont work to!
Any idea!!!

Where is this code?
First part looks like a Layout (views\proyectos\tmpl\default.php) and the second one like a View (views\proyectos\view.html.php).
If it is so, I'd say you are not really loading items in View from the Model. Try using $this->items = $this->get('Items');
But this doesn't explain different results on server and local host.

Hi everyone I solved the problem... the name of my view hava a Camelcase for example itemId and joomla try to find itemid, so don´t find the view and show the default view in the modal.
So I change the name of file without camelCase and now work.!

Related

show welcome message only on index.php [CI]

I make custom welcome message in codeigniter script, but i want show only on index.php
I have
<div class="welcome">
<?php echo getConfigSetting('config_welcome') ?>
</div>
This message show in header,on all page. I want show only on homepage (index.php)
I already tried this code but give me a blank page
<?php if( $this->uri->segment(1) == 'home' || $this->uri->segment(1) = '' ): ?>
Affordable Business Websites Done Fast…
"Just find a website you like and we will customize it to your business needs, easy as 123!"
Start Search
</div>
</div>
Any sugestion?
Thank you
you could try to use the CI helper URL and grab the first segment of the url to check whta page we are on.
example:
<?php if( $this->uri->segment(1) == 'home' || $this->uri->segment(1) = '' ): ?>
<div class="welcome">
<?php echo getConfigSetting('config_welcome') ?>
</div>
<?php endIf; ?>
of course you would want to change the "home" to the name of your homepage name you see in the url, or the default controller/method name.
You will also want to make sure you autoload the url_helper in the config/autoload.

Update multilingual content with AJAX in Yii

Refer to my code below, when user click on en button, the content will be changed to English, while clicking tw button, the content will be changed to Chinese.
However, the page will be refreshed each time when user click either en or tw button. I want to ask how can I implement AJAX content update in this case?
The result is when user click either en or tw button, the page won't be refreshed to change the content language.
Thanks
I have refer to Yii docs here, but seem that it is not appropriate for my case
C:\wamp\www\website\protected\views\site\index.php
<?php
$lang = isset($_GET["lang"]) ? $_GET["lang"] : "en_uk";
$lang = $lang == "en" ? "en_uk" : "zh_tw";
Yii::app()->setLanguage($lang);
?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="get">
<input type="submit" value="en" name="lang" />
<input type="submit" value="tw" name="lang" />
</form>
<div class="main">
<?php echo Yii::t(Yii::app()->controller->id, "Causeway Bay"); ?>
</div>
Best practice is to reload the page in these cases, because usually you have to update so much, that it is just not worth it.
That said, CHtml's ajaxSubmitButton is the cleanest way to implement this, because you can map every event of your call very easily. It looks something like this:
<?php
echo CHtml::ajaxSubmitButton('en', CHtml::normalizeUrl(array('site/changeLanguage')),
array(
'error'=>'js:function(){
alert("error");
}',
//if you add a return false in this, it will not submit.
'beforeSend'=>'js:function(){
alert("beforeSend");
}',
'success'=>'js:function(data){
alert("success, data from server: "+data);
}',
'complete'=>'js:function(){
alert("complete");
}',
//'update'=>'#where_to_put_the_response',
)
);
?>
You don't have to use every parameter of course. The update parameter can update a HTML tag instantly.
EDIT:
This can be done easily if you use the controller's renderPartial method, for instance in your site controller if you have the action responsible for the index.
public function actionIndex(){
//get variables, etc
if(Yii::app()->request->isAjaxRequest) {
$lang = $_POST['nameOfSubmit'];
}else {
//...
}
//if the 3rd parameter is true, the method returns the generated HTML to a variable
$page = $this->renderPartial('_page', array(/*parameters*/ ), true);
echo $page;
}
And then, in your view file you can simply have
<?php echo CHtml::ajaxSubmitButton('en', CHtml::normalizeUrl(array('site/index')),
array('update'=>'#content_div',));?>
and
<?php echo CHtml::ajaxSubmitButton('tw', CHtml::normalizeUrl(array('site/index')),
array('update'=>'#content_div',));?>

Retrieve product custom media image label in magento

I have a custom block loading products on my front page that loads the four newest products that have a custom product picture attribute set via:
$_helper = $this->helper('catalog/output');
$_productCollection = Mage::getModel("catalog/product")->getCollection();
$_productCollection->addAttributeToSelect('*');
$_productCollection->addAttributeToFilter("image_feature_front_right", array("notnull" => 1));
$_productCollection->addAttributeToFilter("image_feature_front_right", array("neq" => 'no_selection'));
$_productCollection->addAttributeToSort('updated_at', 'DESC');
$_productCollection->setPageSize(4);
What I am trying to do is grab the image_feature_front_right label as set in the back-end, but have been unable to do so. Here is my code for displaying the products on the front end:
<?php foreach($_productCollection as $_product) : ?>
<div class="fll frontSale">
<div class="productImageWrap">
<img src="<?php echo $this->helper('catalog/image')->init($_product, 'image_feature_front_right')->directResize(230,315,4) ?>" />
</div>
<div class="salesItemInfo">
<p class="caps"><?php echo $this->htmlEscape($_product->getName());?></p>
<p class="nocaps"><?php echo $this->getImageLabel($_product, 'image_feature_front_right') ?></p>
</div>
</div>
I read that $this->getImageLabel($_product, 'image_feature_front_right') was the way to do it, but produces nothing. What am I doing wrong?
Thanks!
Tre
It seems you asked this same question in another thread, so to help others who might be searching for an answer, I'll anser it here as well:
I imagine this is some sort of magento bug. The issue seems to be that the Magento core is not setting the custom_image_label attribute. Whereas for the default built-in images [image, small_image, thumbnail_image] it does set these attributes - so you could do something like:
$_product->getData('small_image_label');
If you look at Mage_Catalog_Block_Product_Abstract::getImageLabel() it just appends '_label' to the $mediaAttributeCode that you pass in as the 2nd param and calls $_product->getData().
If you call $_product->getData('media_gallery'); you'll see the custom image label is available. It's just nested in an array. So use this function:
function getImageLabel($_product, $key) {
$gallery = $_product->getData('media_gallery');
$file = $_product->getData($key);
if ($file && $gallery && array_key_exists('images', $gallery)) {
foreach ($gallery['images'] as $image) {
if ($image['file'] == $file)
return $image['label'];
}
}
return '';
}
It'd be prudent to extend the Magento core code (Ideally Mage_Catalog_Block_Product_Abstract, but I don't think Magento lets you override Abstract classes), but if you need a quick hack - just stick this function in your phtml file then call:
<?php echo getImageLabel($_product, 'image_feature_front_right')?>
Your custom block would need to inherit from Mage_Catalog_Block_Product_Abstract to give access to that method.
You could also use the code directly from the method in the template:
$label = $_product->getData('image_feature_front_right');
if (empty($label)) {
$label = $_product->getName();
}

how to use JHTML::_('behavior.modal') in Joomla?

I am creating a component,
controllers
theatercontroller
facilitycontroller
Models
theater
facility
view
theater
facility
What I want is I want to add a new facility from the theater view by clicking a button and opening a modal window. I have tried but didn't work. I studied some components but it is difficult for someone like me to understand it. Please I need a simple example and a explanation to understand it.
It doesn't have to be anywhere near that complicated. Many templates turn the modal behavior on already, but if they don't all you need to do is add this to the head -
<?php JHTML::_('behavior.modal'); ?>
Then add this to any links you want to open in a modal window -
class="modal"
Everything else is optional.
You can use this function to get a modal button
static public function getModalButtonObject($name,$text,$link,$width=750,$height=480)
{
JHTML::_('behavior.modal', "a.{$name}"); // load the modal behavior for the name u given
$buttonMap = new JObject(); // create an Jobject which will contain some data, it is similar like stdClass object
$buttonMap->set('modal', true);
$buttonMap->set('text', $text );
$buttonMap->set('name', 'image');
$buttonMap->set('modalname', $name);
$buttonMap->set('options', "{handler: 'iframe', size: {x: ".$width.", y: ".$height."}}");
$buttonMap->set('link', $link);
return $buttonMap;
}
And HTML can be written as
<a id="<?php echo $buttonMap->modalname; ?>" class="<?php echo $buttonMap->modalname; ?>" title="<?php echo $buttonMap->text; ?>" href="<?php echo $buttonMap->link; ?>" rel="<?php echo $buttonMap->options; ?>"><?php echo $buttonMap->text; ?></a>

IF (ThisProduct IS IN ANY ConfigurableProduct) redirect(ThatConfigurableProduct)

That's pretty much what I'm trying to do. All of my simple products are part of, at most, 1 configurable product, so there's no possibility for issues there.
This is necessary because I want my simple products (pillow in design X, color Y) to show in search, catalog but I need the user to know that the design exists in different colors once they click (presumably because they like design X but aren't necessarily sold on color Y). Further, my implementation of Color Swatches (extension) is causing my simple products (that are part of configurables) to behave funnily when accessed directly.
Thanks for any help.
Edit:
Here's the code I ended up using. I'm not a very good coder so make sure to improve it before deploying... (~In app/design/frontend/blah/blah/template/catalog/product/view.media.phtml)
<?php
/* THIS BLOCK ADDED BY __ ON 5/5/2011 */
$thisProductId = $_product['entity_id'];
$thisProductParentId = Mage::getResourceSingleton('catalog/product_type_configurable')->getParentIdsByChild($thisProductId);
if (!$thisProductParentId)
{
?>
<div class="more-views">
<h2><?php echo $this->__('More Views') ?></h2>
<ul>
<?php foreach ($this->getGalleryImages() as $_image): ?>
<li>
<img src="<?php echo $this->helper('catalog/image')->init($this->getProduct(), 'thumbnail', $_image->getFile())->resize(56); ?>" width="56" height="56" alt="<?php echo $this->htmlEscape($_image->getLabel()) ?>" />
</li>
<?php endforeach; ?>
</ul>
</div>
<?php
}
else if ($thisProductParentId)
{
$_product_temp = Mage::getModel('catalog/product')->load($thisProductParentId);
if($_product_temp->getStatus()==1)
{
$_categories = $_product_temp->getCategoryIds();
$_category = Mage::getModel('catalog/category')->load($_categories[0]);
$url = $this->getUrl($_category->getUrlPath()).$_product_temp->getUrlPath();
echo '<h1><a style="color:red;" href="'.$url.'">Click here to view this pillow design in different colors and styles.</a></h1>';
// redirect disabled because it won't preload the new color on the configurable image page anyway. (haven't attempted)
/* echo '<script type="text/javascript">
<!--
window.location = "'.$url.'"
//-->
</script>'; */
}
}
// -- end --
?>
The overwriting of the More Images gallery bit is a project-specific customization, so keep that in mind.
I went and wrote a bunch of code to try to do this, and forgot that this is already a simple use case, and Magento has it written for you:
Mage::getResourceSingleton('catalog/product_type_configurable')
->getParentIdsByChild($childId);
That snippet should give you all parent products for the child. If there is one, redirect to it. Otherwise, render the page as requested.
you have two options here :
add rewrite rules form catalog > url rewrite management
program an extension that makes the necessary check against product database and makes the redirect

Resources