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

Page 1 of 3
Display new products on Home - Help with layout and PHP
 
magento-marie
Member
 
Avatar
Total Posts:  37
Joined:  2008-06-01
France
 

Hello people,

Here is my issue: I have enabled “new products” on my Homepage.
I used the Custom Design field of my CMS homepage as follows:

<reference name="content">
<
block type="catalog/product_new" name="home.catalog.product.new" alias="product_new" template="catalog/product/new.phtml" after="cms_page"/>

I also played around with catalog/product/new.phtml
I want the products to display like:
- first line : 2 products
- second line : 2 products…

So I changed this value

<?php $i=0; foreach ($_products->getItems() as $_product): ?>
    <?php 
if ($i>5): continue; endif; ?>
and set the <?php if ($i>5): to <?php if ($i>2)

When only 2 products are set to "new", everything's fine and 2 products display on the same line.
But when I set 3 or 4 products to "new", three products appear on the first line, and then no news of the last 4th product I added.

Here is the full code for my new.phtml file:

<?php if (($_products $this->getProductCollection()) && $_products->getSize()): ?>

<div class="box recently">
<
h3><?php echo $this->__('New Products'?></h3>
<
table cellspacing="0" class="recently-list" id="recently-compared-list-table" width="520">
<
tr>
<?php $i=0; foreach ($_products->getItems() as $_product): ?>
    <?php 
if ($i>2): continue; endif; ?>

    
<td>
        <
div>
        <
p><class="product-name" href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->htmlEscape($_product->getName()) ?>)"><?php echo $this->htmlEscape($_product->getName()) ?></a></p>
        
            <
a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->htmlEscape($_product->getName()) ?>">
                <
img class="product-image" src="<?php echo $_product->getSmallImageUrl() ?>" width="80" height="80" alt="<?php echo $this->htmlEscape($_product->getName()) ?>" />
            </
a>
            <
div class="description">
                
<?php echo $_product->getShortDescription() ?>
            
</div>
            
<?php //echo $this->helper('review/product')->getSummaryHtml($_product, 'short') ?>
            
        
</div>
            
            
<?php //echo $this->helper('catalog/product')->getPriceHtml($_product) ?>
            
<div class="clear"></div>
            <
div class="product-price-box">
                
<?php echo $this->helper('catalog/product')->getPriceHtml($_producttrue?>
                
</div>
                <
div class="product-action-box">
                    <
button class="form-button btn_details" onclick="setLocation('<?php echo $_product->getProductUrl() ?>')"><span><?php echo $this->__('Learn More'?></span></button>
                    <
div class="clear" style="height: 2px;"></div>
                    
<?php if($_product->isSaleable()): ?>
                    
<button class="form-button btn_cart" onclick="setLocation('<?php echo $this->getAddToCartUrl($_product) ?>')"><span><?php echo $this->__('Add to Cart'?></span></button>
                    
<?php else: ?>
                    
<div class="out-of-stock"><?php echo $this->__('Out of stock'?></div>
                    
<?php endif; ?>
                
</div>
            </
div>

        </
td>
        <
td class="separator"></td>
<?php $i++; endforeach; ?>
<?php 
for($i;$i%2!=0;$i++): ?>
        
<td>&nbsp;</td>
    
<?php endfor ?>
    
</tr>
</
table></div>
<?php endif; ?>

Another smaller issue : I can't make the short description to appear!
I used this : <?php echo $_product->getShortDescription() ?> but nothing appears on my product sheet.

I’d be happy if anybody could help. I can tip back on some design issues !!
Thanks
Marie

 
Magento Community Magento Community
Magento Community
Magento Community
 
dreamHD
Jr. Member
 
Total Posts:  3
Joined:  2008-06-17
 

i think an even better solution is if Magento can implement these type of solution within the admin

kind of like how we have layouts now, but layouts with these features enabled (something like pre-made-layouts)

i might be mistaken since i’m still really new to magento, in that case, does magento already have this? if so what do i have to do?

 
Magento Community Magento Community
Magento Community
Magento Community
 
lotusseedsD
Mentor
 
Avatar
Total Posts:  1144
Joined:  2007-08-31
 

this <?php if ($i>2): continue; endif; ?> isn’t really control table row, but the number of products it shows.

If you eliminate the table layout and replace with div class with floated element, you can display any way you wanted it be.

 
Magento Community Magento Community
Magento Community
Magento Community
 
magento-marie
Member
 
Avatar
Total Posts:  37
Joined:  2008-06-01
France
 

Thanks ChineseDream.
It works well with divs and float.

By the way, is there any reason why these tables are tables and no divs ?

Just a last question. I can’t have the short description to display.
I use the code from list.phtml :

<?php echo nl2br($_product->getShortDescription()) ?>

I even tried with

<?php echo $_product->getShortDescription() ?>

But nothing works.
Is there anybody who had to face this ?

Thanks again for your help !!
Marie

 
Magento Community Magento Community
Magento Community
Magento Community
 
lotusseedsD
Mentor
 
Avatar
Total Posts:  1144
Joined:  2007-08-31
 

Great that you figured the floated div out.

with short description, you also need to add the ‘short_description’ attribute in the core/Mage/Catalog/Product/New.php. Somewhere in line#45 I think.

->addAttributeToSelect(array(’name’, ‘price’, ‘small_image’, ‘short_description’), ‘inner’)

 
Magento Community Magento Community
Magento Community
Magento Community
 
davinder
Member
 
Total Posts:  56
Joined:  2008-06-26
 

@Magento Marie

How did you make float:left work? In which class did you put this property? For me it works fine in Firefox but still messing design in IE 7 http://www.newagestyles.com/index.php/.

Thanks,

Davinder

 
Magento Community Magento Community
Magento Community
Magento Community
 
magento-marie
Member
 
Avatar
Total Posts:  37
Joined:  2008-06-01
France
 

Sorry Davinder, I did not see your last request…

Are you using Firefox ?
Try download the “Firebug” extension.
It will allow you to point out elements and to see which class is related to the element you want to style.

If you experience any problem, let me know and I’ll go further with an explanation.

 
Magento Community Magento Community
Magento Community
Magento Community
 
brianpat
Member
 
Total Posts:  44
Joined:  2008-04-05
 

Hi,

I had installed the latest release and when I set for my new products to appear on home page. I get them but with “out of stock” message instead of Add to cart button. I checked everywhere and found that all the products set for new are in stock. Has any one got same problems?

Also I see 2 products per row. I want to have 5 products per row for New category on home page.

My new.phtml file looks like:

?>
<?php 
if (($_products $this->getProductCollection()) && $_products->getSize()): ?>
<div class="box recently">
<
h3><?php echo $this->__('New Products'?></h3>
<
table cellspacing="0" class="recently-list" id="recently-compared-list-table">
<
tr>
<?php $i=0; foreach ($_products->getItems() as $_product): ?>
    <?php 
if ($i>5): continue; endif; ?>

    
<td>
        <
div>
            <
a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->htmlEscape($_product->getName()) ?>">
                <
img class="product-image" src="<?php echo $_product->getSmallImageUrl() ?>" width="80" height="77" alt="<?php echo $this->htmlEscape($_product->getName()) ?>" />
            </
a>
        </
div>
            <
p><class="product-name" href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->htmlEscape($_product->getName()) ?>)"><?php echo $this->htmlEscape($_product->getName()) ?></a></p>
            
<?php echo $this->getReviewsSummaryHtml($_product'short'?>
            <?php 
echo $this->getPriceHtml($_product?>
            <?php 
if($_product->isSaleable()): ?>
            
<button class="form-button" onclick="setLocation('<?php echo $this->getAddToCartUrl($_product) ?>')"><span><?php echo $this->__('Add to Cart'?></span></button>
            
<?php else: ?>
            
<div class="out-of-stock"><?php echo $this->__('Out of stock'?></div>
            
<?php endif; ?>
            
<div class="clear"></div>
            <
class="add-to">
                
<?php if ($this->helper('wishlist')->isAllow()) : ?>
                
<a href="<?php echo $this->getAddToWishlistUrl($_product) ?>" class="link-cart"><?php echo $this->__('Add to Wishlist'?></a>
                
<?php endif; ?>
                <?php 
if($_compareUrl=$this->getAddToCompareUrl($_product)): ?><br />
                <
a href="<?php echo $_compareUrl ?>"><?php echo $this->__('Add to Compare'?></a>
                
<?php endif; ?>
            
</p>
        </
td>
<?php $i++; endforeach; ?>
<?php 
for($i;$i%5!=0;$i++): ?>
        
<td>&nbsp;</td>
    
<?php endfor ?>
    
</tr>
</
table></div>
<?php endif; ?>
 
Magento Community Magento Community
Magento Community
Magento Community
 
Michal_s
Sr. Member
 
Total Posts:  111
Joined:  2008-05-15
The Netherlands
 

If got the same problem as you Brianpat, the problem lies inside this code

<?php if($_product->isSaleable()): ?>
<button class="form-button" onclick="setLocation(’<?php echo $this->getAddToCartUrl($_product) ?>’)"><span><?php echo $this->__('Add to Cart'?></span></button>
<?php else: ?>
<div class="out-of-stock"><?php echo $this->__('Out of stock'?></div>
<?php endif; ?>

It seems the function isSaleable() isnt send right, if i find the awnser ill post it here

 
Magento Community Magento Community
Magento Community
Magento Community
 
Michal_s
Sr. Member
 
Total Posts:  111
Joined:  2008-05-15
The Netherlands
 

I dont know enough php to fix this one but it seems to me that the array $_product->isSaleable() is not propery declared in
app/code/core/Mage/Catalog/Block/Product/New.php

The array always echos 1

 
Magento Community Magento Community
Magento Community
Magento Community
 
manubass
Jr. Member
 
Total Posts:  3
Joined:  2008-06-19
Paris / France
 

I have the same problem but no solution yet !

 
Magento Community Magento Community
Magento Community
Magento Community
 
Michal_s
Sr. Member
 
Total Posts:  111
Joined:  2008-05-15
The Netherlands
 

Don’t see this as a fix, but if you know you always have the new product enough in stock just change rule 52 to

<?php /* DELETE THE !-sign when bug is fixed */ if( !$_product->isSaleable() ): ?>

this way it will always show the add to cart button, and you dont have to delete any code so when its fixed it will be easy to changed it back.

 
Magento Community Magento Community
Magento Community
Magento Community
 
Michael_1
Enthusiast
 
Total Posts:  826
Joined:  2007-08-31
 

Can you try to add the following line into app\code\core\Mage\Catalog\Block\Product\New.php:

45:->addAttributeToSelect(array('special_price''special_from_date''special_to_date'), 'left')
     ->
addAttributeToSelect('status'// this is new line to add
46: ;
 
Magento Community Magento Community
Magento Community
Magento Community
 
Michal_s
Sr. Member
 
Total Posts:  111
Joined:  2008-05-15
The Netherlands
 

Thanks Michael that did it!

 
Magento Community Magento Community
Magento Community
Magento Community
 
brianpat
Member
 
Total Posts:  44
Joined:  2008-04-05
 

Hi,
There is also another solution . I tried that and it worked for me. The link is

http://www.magentocommerce.com/boards/viewthread/13434/#t49588

Thanks
Brian

 
Magento Community Magento Community
Magento Community
Magento Community
 
brianpat
Member
 
Total Posts:  44
Joined:  2008-04-05
 

Hi Michael,

Thanks for your solution. Your solution also works fine. Do you know how to show more than 5 products in the home page with page options like setting each page with number of products.

Thanks
Brian

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top
Page 1 of 3