i have joomla view where i am including 4 more sub template views
<?php echo $this->loadTemplate('Market_1'); ?>
<?php echo $this->loadTemplate('Market_2'); ?>
<?php echo $this->loadTemplate('Market_3'); ?>
<?php echo $this->loadTemplate('Market_4'); ?>
and every template file taking too much time to load because every file displays 15 tables with text and images...
and page load when all templates loaded and its taking too much time is there any way to load some fast? or first load 'Market_1' and others one by one and page open in quick time?
First. I cannot think of any reason why you would want to display that much data at once that it actually "overloads" the page.
But to address your question. No. In php you cannot asynchronous load the templates. To do that you should implement some kind of Ajax (javascript).
But again... You really need to reconsider your solution imo.
Related
The Magento category sort order seams to be stored in cookies.
Lets say default sort oder is by Name ascending. If a user changes this in descending then all next pages will have this sort order too.
How can i change this so the user sees in the next category the default sort order?
This is an old question but comes up as the first Google result for "Magento sort by cookie". So, in the spirit of SO, let's answer it!
To begin we must do some investigation, but first we need to know what our assumptions are.
Assumptions
Sort by state is stored in a cookie
Cookie is updated when the sort by select is changed
Where to start?
When in doubt in Magento in a situation like this, start in the frontend where your output is viewable.
If we look in \app\design\frontend\<your_package>\<your_theme>\template\catalog\product\list\toolbar.phtml
We see that the following handles the javascript action when the "Sort By" select box is changed.
<div class="sort-by">
<label><?php echo $this->__('Sort By') ?></label>
<select onchange="setLocation(this.value)">
<?php foreach($this->getAvailableOrders() as $_key=>$_order): ?>
<option value="<?php echo $this->getOrderUrl($_key, 'asc') ?>"<?php if($this->isOrderCurrent($_key)): ?> selected="selected"<?php endif; ?>>
<?php echo $this->__($_order) ?>
</option>
<?php endforeach; ?>
</select>
<?php if($this->getCurrentDirection() == 'desc'): ?>
<img src="<?php echo $this->getSkinUrl('images/sort_desc_arrow.gif') ?>" alt="<?php echo $this->__('Set Ascending Direction') ?>" class="v-middle" />
<?php else: ?>
<img src="<?php echo $this->getSkinUrl('images/sort_asc_arrow.gif') ?>" alt="<?php echo $this->__('Set Descending Direction') ?>" class="v-middle" />
<?php endif; ?>
</div>
In particular, we're interested in the <select onchange="setLocation(this.value)"> portion. So what happens when this method is called?
Deeper down the hole we go! setLocation is defined in \js\varien\js.js around line 30.
function setLocation(url){
window.location.href = url;
}
So that's simple enough, it's just your basic Javascript new location directive.
When this <select> is changed, we are sent to a new URL with some parameters. This is the most probable location of the cookie setting.
Again in particular we are interested in the url parameters ?dir=<asc OR desc>&order=<whatever_metric_you_are_sorting_by>. Let's go out on a limb and take a guess that the order parameter is causing a "setCookie" method or something of the sort to be called.
Where do we find this though? Well that's simple: all Magento actions on a request can be followed from index.php to the final frontend rendering, so it MUST happen somewhere along the way! You can track down just about ANY action in Magento using this method.
However, to save you and I some time, we can also assume that cookies probably aren't set that often in any given web framework. Running a grep on the Magento directory for ('core/cookie') returns 23 hits in 14 files. That's narrowed it down pretty stinkin' well!
Of the 23 hits, only 4 of them are using the ('core/cookie')->set() method.
Of the 4 using the set() method:
\app\code\core\Mage\Persistent\Model\Observer\Session.php - line 79
\app\code\core\Mage\Sales\Helper\Guest.php - line 100
\app\code\core\Mage\XmlConnect\controllers\ConfigurationController.php - line 112
\app\code\core\Mage\XmlConnect\controllers\Adminhtml\Connect\ConfigController.php - line 101
Of those 4, only 2 of them are going to be dealing with your end user directly, namely Session.php, and Guest.php. Since the Guest.php is part of the Sales module in Magento AND part of the loadValidOrder() method, it is quite unlikely that it is dealing with product list sorting. That leaves us with 1 option left, and that is:
\app\code\core\Mage\Persistent\Model\Observer\Session.php - line 79
What does inspection of this code tell us?
// Set new cookie
if ($sessionModel->getId()) {
Mage::getSingleton('core/cookie')->set(
Mage_Persistent_Model_Session::COOKIE_NAME,
$sessionModel->getKey(),
$persistentLifeTime
);
}
That all the cookie is storing is a session ID for the server! It's almost like this is standard practice or something for modern web frameworks! ;). One of our base assumptions was incorrect!
TL;DR The Answer
The sort by preference is saved in the Magento server-side session for that client, and recalled when the user returns with the ID stored in the cookie.
To make it so Magento doesn't save this, we must do the following then:
Magento 'Sort By' - How to make Magento forget which option was selected
I figured instead of just linking the answer, I would explain how to get from your line of thinking to the answer, which is much more valuable since now you understand WHY the answer is the correct one. Enjoy and happy coding.
Update
Since the SO thread I linked accepted answer doesn't really follow Magento XML protocol, but the comment on the answer does, I'll post it here with credit to the Author of the comment:
You need to apply a Layout update with the following xml for the pages you want Magento to "forget" sorting order on:
<reference name="product_list_toolbar">
<action method="disableParamsMemorizing" />
</reference>
by SO User Giel Berkers
I dont think you can. If the user is trying to improve their experience which only effects them then the cookie is updated and until this cookie expires the sort order will always show as they have selected.
You could clear the cookie on every time the pagination is clicked but this could cause other issue if the user is logged in.
Not only that it would remove and products that may have been added to their basket.
I would suggest to accept the user is responsable for they wish to view the listings, or simply remove the option " sort oder is by Name ascending" for example so they cannot select it.
I have this template view at view/include
<?php $this->load->view('include/header'); ?>
<?php $this->load->view($sidebar_column); ?>
<?php $this->load->view($result_column); ?>
<?php $this->load->view($footer_row); ?>
<?php $this->load->view('include/footer'); ?>
and i have the footer_row html at view/include
<div> this is footer row <?php echo $username ?></div>
then i call the footer_row in my controller
$data['footer_row'] = 'include/footer_row';
$this->load->view('include/template',$data);
My question, the footer_row is logged in user info and it appear in EVERY pages. With the above method I use, I have to call and retrieve the user info in every controller. How can i make it reusable so i don't need to repeat myself.
Reusability comes from making use of your constructors, and parent classes. Have a look at my previous answers:
Header and Footer in CodeIgniter
Constructor session validation for different functions
Instead of using this method why dont you use a template library which is easy to use. I would recommend Philsturgeons Template Library but there are some more you can use any that fits to your requirements.
Williams Concepts
http://williamsconcepts.com/ci/codeigniter/libraries/template/
Phil Sturgeons's
http://philsturgeon.co.uk/demos/codeigniter-template/user_guide/
Most Simple
http://maestric.com/doc/php/codeigniter_template
And Finally Binpresses's
http://www.binpress.com/app/codeigniter-template-library/223
I would like to retrieve the categories of my website in order to build me own Category menu.
but I don't understand how to get all the categories from the class/model. So I've created a file called top.phtml that I've put in template/catalog/navigation ,
First, do I MUST put that name to the file into that folder if I want to create a top Menu ? Can t I decide where to put it with the name I want like TopMenu.phtml ? Because in evry tut I red, they are doing the same way ..
Second : What i the function I must call ? I've been here : http://www.magentix.fr/ergonomie-web/agencer-page-accueil-site-magento.html but the way the do that doesn t work for me .. I add that code to my file top.phtml properly called in the page.xml :
<div class="category-list" style="background-color:white;">
<h2>Nos produits</h2>
<?php
foreach ($this->getStoreCategories() as $_category):
if($_category->getIsActive()):
$_category = Mage::getModel('catalog/category')->load($_category->getId());
$layer = Mage::getSingleton('catalog/layer')->setCurrentCategory($_category);
?>
<div class="category-list-view">
<a href="<?php echo $this->getCategoryUrl($_category)?>" title="<?php echo $_category->getName()?>">
<img src="<?php echo $this->getCurrentCategory()->getImageUrl(); ?>" alt="<?php echo $_category->getName() ?>" />
</a>
<h3><?php echo $_category->getName()?></h3>
</div>
<?php
endif;
endforeach;
?>
</div>
Last : where could I find a clear user guide like there is for CodeIgniter ? I found that, but I never found any answer on it : http://www.magentocommerce.com/wiki/doc/webservices-api/api#magento_core_api
Thanks for your answers, I m a web dev used to work with CodeIgniter or without any template, and I can t clearly see the logic behind Magento way of programming.
EDIT: Is there anything to do with the categories ? Becaue I tried to create a sub category under the Default Category and it do work, but if I create a new Root Category,It simply didnt recognize it .. why
First, do I MUST put that name to the file into that folder if I want to create a top Menu ? Can t I decide where to put it with the name I want like TopMenu.phtml ? Because in evry tut I red, they are doing the same way ..
You can name your template file whatever you like. However, it's best to follow the nomenclature and established conventions. The template filename is contingent on your layout XML. It should have the template attribute, something like <block name="x" type="x/y" template="catalog/navigation/topmenu.phtml" /> (for example).
Second : What i the function I must call ? I've been here : http://www.magentix.fr/ergonomie-web/agencer-page-accueil-site-magento.html but the way the do that doesn t work for me
The functions available to your template (topmenu.phtml file) depend on the block's type. In your layout XML, you should specify the block type that corresponds to the functionality you need. In your case, you're probably looking for the block type to be catalog/navigation. If you look in ./app/code/core/Mage/Catalog/Block/Navigation.php, you can see what public methods are available to your template. Several of the methods here facilitate generating (nested) category listing. This is where your getStoreCategories() method comes from. Remember that these blocks inherit from several parenting classes, so you have a lot more methods available than you may at first think.
where could I find a clear user guide like there is for CodeIgniter ? I found that, but I never found any answer on it : http://www.magentocommerce.com/wiki/doc/webservices-api/api#magento_core_api
That's a link to the Magento API. What you need is a tutorial on Magento layout XML and the design layer therein. The Magento wiki has some good info, but Google around and you'll find a ton of really helpful resources on understanding Magento's design system.
Is there anything to do with the categories ? Becaue I tried to create a sub category under the Default Category and it do work, but if I create a new Root Category,It simply didnt recognize it .. why
A root category is what you'll use to identify the basis of the catalog for the selected store(s). You will never see the root category appear on the frontend (and you shouldn't). Each subcategory within the root category is the top-level category; sub-categories beneath those subcategories (tertiary categories) would appear as your "second-level" categories on the Magento frontend. You might want to look into Magento's GWS ("global, website, store") scope system, and how it manages catalog data in a multi-store setup to better understand why root categories function this way.
Hope this helps!
On the page I edit modules constitute the main page. Actually there is no need for any component out there.
I can't remove jdoc from the template because other part of the site requires it.
I wonder what is the best solution for the problem: for main page I need one template but for others another.
As far I have worked with joomla internals almost never with back-end so I guess my knowledge lack in this department.
Any hint how to achieve that?
You can do something in your template like:
<?php
$menu = JSite::getMenu();
if ($menu->getActive() != $menu->getDefault()) : ?>
<jdoc:include type="component" />
<?php endif; ?>
Which will disable the component position when on the default [home] page
I have disabled layout for the wishlist block:
<block type="catalog/product_view" name="product.info.addtoto" as="addtoto" template="catalog/product/view/addto.phtml"/>
I now want to call that block in the phtml instead of add it to another layout.
How do I call it directly?
While Prattski is correct that this is poor form (am I'm upvoting as such), there have been times when developing when either this has been a valuable debugging technique, or it made the difference of several hours of programming. In that spirit, this is the bad habit way of doing it:
<?php print $this->getLayout()
->createBlock("catalog/product_view")
->setTemplate("catalog/product/view/addto.phtml")
->toHtml(); ?>
Use sparingly, if at all.
echo Mage::app()->getLayout()
->createBlock('somemodule/someblock')
->setSomeVariable($variable)
->setTemplate('somemodule/someblock.phtml')
->toHtml();
this can be use anywhere for calling blocks. setSomeVariable($variable) if set can be accessed in someblock.phtml by $this->getSomeVariable();
Chris - You should ever need to call a block directly from within a template. It would be a bad habit/practice to get into. Find the proper reference to the template you want to add the block to, and add it into the layout xml. Then from within the template file, use:
echo $this->getChildHtml('your-block');
I struggled with this for ages and found that if you want to call a block from a totally separate part of the layout you need to use slightly different code. Use:
<?php echo $this->getBlockHtml('any_block'); ?>
Instead of:
<?php echo $this->getChildHtml('any_block'); ?>
Using this code you can either create your own blocks anywhere or pick blocks from other modules and put them anywhere.