Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

How to show “several” “single” products using a block (product_id reset issue)? 
 
julien.bernard
Jr. Member
 
Total Posts:  7
Joined:  2008-09-01
 

Dear all,

I’m currently facing an issue, and I would like to know if someone could give me some help (I’m using the last Magento release 1.2.1)…

What I want to do: I need to create a new block which I will call using the “product_id” variable, in order to show (where I want) a single product in my static pages. I want to be able to call this block many times within the same CMS page, in order to show several products on different locations.

Issue: This works well if I call this block only one. But if I want to show several products (calling the block several times) then only the fist “product_id” is used. It seems that I need to reset the product_id somewhere, but I can’t figure where!

Details:
I call my block using this kind of command:

<div class="page-content-center">
{{block type="catalog/product_view" product_id="32" template="catalog/product/view.phtml"}}
{{block type
="catalog/product_view" product_id="42" template="catalog/product/view.phtml"}}
{{block type
="catalog/product_view" product_id="12" template="catalog/product/view.phtml"}}
</div>

However in this case, the 3 blocks will use the product with ID=32…

I’ve seen in some threads and other forums that I should add something like this in my phtml file, but this doesn’t change anything:

<?php
Mage
::getSingleton('catalog/layer')->setData("product_collection",NULL);
$this->_productCollection null;
$_productCollection=$this->getLoadedProductCollection();
?>

I’m sure I’m not the only one to want to achieve this, and it should be right in front of my eyes…

Thanks for your help!

 
Magento Community Magento Community
Magento Community
Magento Community
 
julien.bernard
Jr. Member
 
Total Posts:  7
Joined:  2008-09-01
 

I just want to add that I don’t face this problem with categories.

For example, if I call these two blocks with different category_id:

{{block type="catalog/product_list" category_id="14" template="catalog/product/list.phtml"}}
{{block type
="catalog/product_list" category_id="39" template="catalog/product/list.phtml"}}
Then the two different categories will be displayed.
 
Magento Community Magento Community
Magento Community
Magento Community
 
julien.bernard
Jr. Member
 
Total Posts:  7
Joined:  2008-09-01
 

I found a way grin

In my CMS page, I’ve created a new polaroid.phtml (in app/template/catalog/product/polaroid.phtml):

<?php
    $productId 
$this->getProduct_id();
    
$product Mage::getModel('catalog/product')->load($productId);  //load the product                                                      
?>
<div class="polaroid">
    <
a href="<?php echo $product->getProductUrl() ?>" >
    <
img class="product-img" src="<?php echo $this->helper('catalog/image')->init($product, 'small_image')->resize(145, 145); ?>" width="145" height="145" alt="<?php echo $this->htmlEscape($product->getName()) ?>" />
    </
a>
</
div>

And from a CMS page:

{{block type="catalog/product_view" product_id="17" template="catalog/product/polaroid.phtml"}}
{{block type
="catalog/product_view" product_id="34" template="catalog/product/polaroid.phtml"}}
 
Magento Community Magento Community
Magento Community
Magento Community
 
kiatng
Enthusiast
 
Total Posts:  875
Joined:  2008-09-03
Kuala Lumpur, Malaysia
 

I have only one product in my store and I want to display the product details in the home page. I have this in the CMS>home>Content:

{{block type="catalog/product_view" product_id="10" template="catalog/product/view.phtml"}}

where view.phtml is the default file.  However, the homepage only shows partial information of the product. For example, it can get the product name but not the product image. The following is straight out from view.phtml:

<!-- the following seems to work oktested it and it will assign to another product as per product_id-->
<?php
    $_helper 
$this->helper('catalog/output');
    
$_product $this->getProduct(); 
?>
<script type="text/javascript">
    var 
optionsPrice = new Product.OptionsPrice(<?php echo $this->getJsonConfig() ?>);
</script>
<div id="messages_product_view"><?php echo $this->getMessagesBlock()->getGroupedHtml() ?></div>
<
div class="product-info-box">
    <
div class="product-essential">
    <
form action="<?php echo $this->getAddToCartUrl($_product) ?>" method="post" id="product_addtocart_form"<?php if($_product->getOptions()): ?> enctype="multipart/form-data"<?php endif; ?>>

<!--
the following doen't display-->
        <div class="product-img-box">
            <?php echo $this->getChildHtml('
media') ?> 
        </div>

<!--this following display ok-->
        <div class="product-shop">
            <h3 class="product-name">
                <?php echo $_helper->productAttribute($_product, $this->htmlEscape($_product->getName()), '
name') ?>
            </h3>

It seems that $this is not pointing to the right object. Anyone can help me sort this out? Thank you.

 
Magento Community Magento Community
Magento Community
Magento Community
 
lewis
Jr. Member
 
Total Posts:  20
Joined:  2008-02-20
 

I have the same problem with displaying a single product. The image doesnt show etc.
Magento ver. 1.3.1
have tried a few themes - seems the same on them all.

Cheers
Lewis

 
Magento Community Magento Community
Magento Community
Magento Community
 
kiatng
Enthusiast
 
Total Posts:  875
Joined:  2008-09-03
Kuala Lumpur, Malaysia
 

Hi Lewis

If you use CMS to display a product image, this statement :

<?php echo $this->getChildHtml('media'?>

will not work if ‘media’ is not defined in the block of layout update of the CMS page.  If you look at catalog.xml, under catalog_view_page, which defines all the blocks in the product page, you’ll find

<block type="catalog/product_view_media" name="product.info.media" as="media" template="catalog/product/view/media.phtml"/>

where the getChildHtml function retrieves the phtml file for ‘media’.  So you can do like julien.bernad in his #2 post, create a phtml file and reference that in the CMS with a block statement or paste the following in the CMS content (replacing the product_id with the one you want):

{{block type="catalog/product_view_media" product_id="10" template="catalog/product/view/media.phtml"}}

However, I have not tried Julien’s method and the block statement above.

 
Magento Community Magento Community
Magento Community
Magento Community
 
lewis
Jr. Member
 
Total Posts:  20
Joined:  2008-02-20
 

Cheers for the reply but i cant get this going. can you try and explain step by step what i should do?

Thanks

 
Magento Community Magento Community
Magento Community
Magento Community
 
rmaiolo
Jr. Member
 
Total Posts:  5
Joined:  2009-06-10
 
julien.bernard - 18 February 2009 01:36 AM

I found a way grin

After 2 days chasing my tail...I found this post with the solution I needed..THANK YOU!!

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top