Is there an easy way in Magento to display individual products in a cms page without copying and pasting the code from the catalog pages?
I have a blog on my magento store and sometimes I'd like to drop the listing for individual products into the posts.
A code block in Magento is the best way to achieve this effect. If you look at your home page, that's how new products are generated dynamically:
{{block type="catalog/product_new" template="catalog/product/new.phtml"}}
If you created another block for a 'featured' item that took a product ID as a parameter, you could place that block on the static page and it would show that item. This page shows a brief example, but for the sake of being complete, I'll reproduce it here:
First create a new .phtml file with the following undercatalog/product/view/your_new_page.phtml
<?php
$productId = $this->getProduct_id();
$_product = Mage::getModel('catalog/product')->load($productId); //load the product
?>
<img src="<? echo Mage::helper('catalog/image')->init($_product, 'thumbnail')>resize(75, 75); ?>" alt="<?php echo $this->htmlEscape($_product['name']); ?>" border="0" width="75" />
Now simply add the following to your CMS Page or Block and adjust the product ID to the product Image you wish to view:
{{block type="catalog/product_new" product_id="1" template="catalog/product/view/your_new_page.phtml"}}
I'd probably tweak it a bit for readability if I used this on my store, but I'm also a bit overzealous in terms of using human-readable code. :)
If you are working on Magento 1.4, you should take a look at widgets which do exactly what you want.
Related
I have installed Strategery InfiniteScroll. Which is working great for category listing page. Now i have a custom product page. I want to apply Strategery InfiniteScroll on my custom product page. How to do.?
My Page
<?php
$_productCollection=$this->getLoadedProductCollection();
$_productCollection = Mage::getResourceModel('catalog/product_collection')
->addAttributeToSelect('*')
->addFieldToFilter(array(array('attribute'=>'featured','eq'=>'1')));
$_productCollection->getSelect()->order('rand()');
$_productCollection->getSelect()->limit(20);
?>
//loop for products
</div>
</div>
Before you start, assure you have included .js file in your custom page.
if you see the ias.phtml template, it has some container defined.
You need to add the same code for your custom page.
For documentation of infinite ajax scroll, read this
I want to show in my product page the approved reviews for the product.
So I am editing this file:
mytemplate/default/catalog/product/view.phtml
I tried adding this to the view.phtml file but nothing is showing up:
<?php echo $this->getChildHtml('reviews') ?>
Can you suggest a way of adding approved reviews on product page? I'm using Magento 1.7.0.2.
first of all write this code in catalog.xml
<block type="review/product_view_list" name="product.info.product_additional_data" as="reviews" template="review/product/view/list.phtml"/>
then
write this code in your view.phtml
<?php echo $this->getChildHtml('reviews') ?>
it will solve your problem...
add this line in template/review/product/view/list.phtml file
this line add anywere u want
$this->htmlEscape($_review->getStatusId())=='1'){ echo ' Approved Review';
I have modified my magento catalog page using list.phtml by adding manufacturer name next to product name. Now this works well for all categories which have 'Anchor' set as No. It does not show the changes in categories where Anchor is set to yes. Could you please help me on this.
Thanks.
The layout for anchor and non-anchor categories is different look here:
<catalog_category_default>
and
<catalog_category_layered>
in catalog.xml
Perhaps your template only uses the non anchor list.phtml and falls back to base/default for the anchor categories?
In list.phtml I added the manufacturer
<?php echo $_helper->productAttribute($_product, $_product->getAttributeText('manufacturer'),'name') ?> - <?php echo $_helper->productAttribute($_product, $_product->getName() , 'name'); ?></a>
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!
I have a custom page as my magento homepage. It's content is hardcoded on the default CMS page (which shows if a CMS homepage isn't enabled in the CMS pages section of the admin).
I have a list of products showing there (pulled from best-selling/highest rated etc). However, the review links and the add-to-compare links don't show on this page. The list of products is displayed using the same code as the default template/catalog/product/list.phtml, and everything else works except for these 2 things.
It seems that both the following code snippets have no effect on pages other than the default category listing page:
<?php $_compareUrl=$this->getAddToCompareUrl($_product); ?>
&
<?php echo $this->getReviewsUrl() ?>
I'm guessing that there's something else that needs to be called in order for these to work, but can't figure out what it is. Everything else from the product collection is available.
I load my product collection using the following code:
$_productCollection = Mage::getResourceModel('reports/product_collection')
->addAttributeToSelect('*')
->addAttributeToFilter('visibility', $visibility)
$_productCollection->load();
Any ideas?
OK, so after a while digging around, I found that you can use the following to get the compare url working:
<?php $_compareUrl=$this->helper('catalog/product_compare')->getAddUrl($_product) ?>
<span class="addto">
<?php echo $this->__('Add to Compare') ?>
</span>
Still not sure about the review urls, but I've made an acceptable workaround for that so I'm gonna mark this as answered.
If anyone comes up with an answer though please do still post it!
I'm guessing it's because the Block that is serving up your product list may not be correct. I believe it should be Mage_Catalog_Block_Catalog_Product_List. How exactly are you loading in the list of products?