?
Solved

Template issue for tabbed menu

Posted on 2012-09-20
10
Medium Priority
?
520 Views
Last Modified: 2012-09-20
Hi guys,

I'm trying to rearrange the layout for my theme which should be pretty simple as all I need to do is make a few css changes and add some javascript for decoration. However, whenever I add the ammended code it seems to break the script and nothing gets rendered in the browser apart from the header.

Here's the original code which works fine but looks ugly:
<?php if (($_products = $this->getProductCollection()) && $_products->getSize()): ?>

<h2 class="subtitle"><?php echo $this->__('New Products') ?></h2>
<?php $_columnCount = $this->getColumnCount(); ?>
    <?php $i=0; foreach ($_products->getItems() as $_product): ?>
        <?php if ($i++%$_columnCount==0): ?>
        
        <ul class="products-grid-tabs">
        <?php endif ?>
            <li class="item<?php if(($i-1)%$_columnCount==0): ?> first<?php elseif($i%$_columnCount==0): ?> last<?php endif; ?>">
                <a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->htmlEscape($_product->getName()) ?>" class="product-image"><img src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(140) ?>" width="140" height="140" alt="<?php echo $this->htmlEscape($_product->getName()) ?>" /></a>
                <div class="wrap-option">
               <?php
$_productName = $this->helper('core/string')->truncate($this->htmlEscape($_product->getName()),20,'...', $_remainder, true);
?>
<a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $_productName ?>"><?php echo $_productName ?></a>
                  <?php echo $this->getPriceHtml($_product, true, '-new') ?>        
                <div class="actions-tab">
              <button type="button" title="<?php echo $this->__('Add to Cart') ?>" class="button-lgtblue-tabs" onclick="setLocation('<?php echo $this->getProductUrl($_product) ?>')"><span><?php echo $this->__('Buy it now!') ?></span></button></div></div>
            </li>
        <?php if ($i%$_columnCount==0 || $i==count($_products)): ?>
        </ul>
        <?php endif ?>
    <?php endforeach; ?>
<?php endif; ?>

Open in new window


Here's the code for what I am trying to achieve:
<?php $_collectionSize = $_productCollection->count() ?>
    <?php $_columnCount = 6 //$this->getColumnCount(); ?>
    <?php $i=0; foreach ($_productCollection as $_product): ?>
        <?php if ($i++%$_columnCount==0): ?>
        <ul class="product-grid-tabs">
        <?php endif ?>
			
			<li class="item<?php if(($i-1)%3==0): ?> first<?php elseif($i%3==0): ?> last<?php endif; ?>">
				<div class="item-content">
					<div class="view">
						<a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>" class="product-image"><img src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(215); ?>" width="215" height="215" alt="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>" /></a>
						
					</div>
					<div class="wrap-option">
						<h2 class="product-name"><a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->stripTags($_product->getName(), null, true) ?>"><?php echo $_helper->productAttribute($_product, $_product->getName(), 'name') ?></a></h2>
						<?php if($_product->getRatingSummary()): ?>
							<?php echo $this->getReviewsSummaryHtml($_product, 'short') ?>
						<?php endif; ?>
						<div class="des">
							<p><?php echo $_helper->productAttribute($_product, $_product->getShortDescription(), 'short_description') ?></p>			
						</div>
						
						<?php echo $this->getPriceHtml($_product, true) ?>
						<div class="actions">
							<?php if($_product->isSaleable()): ?>
								<button type="button" title="<?php echo $this->__('Add to Cart') ?>" class="button btn-cart" onclick="setLocation('<?php echo $this->getAddToCartUrl($_product) ?>')"><span><span><?php echo $this->__('Add to Cart') ?></span></span></button>
							<?php else: ?>
								<p class="availability out-of-stock"><span><?php echo $this->__('Out of stock') ?></span></p>
							<?php endif; ?>
							
						</div>
					</div>
				</div>
			</li>
			
        <?php if ($i%$_columnCount==0 || $i==$_collectionSize): ?>
        </ul>
        <?php endif ?>
        <?php endforeach ?>
        <script type="text/javascript">decorateGeneric($$('ul.products-grid'), ['odd','even','first','last'])</script>
    <?php endif; ?>

    <div class="toolbar-bottom">
        <?php echo $this->getToolbarHtml() ?>
    </div>
</div>
<?php endif; ?>

Open in new window


As I said the new code just stops the page from loading after the header not sure why? been searching allnight.

Any help would be more than welcomed
0
Comment
Question by:rafique12
  • 5
  • 4
10 Comments
 
LVL 45

Expert Comment

by:Chris Stanyon
ID: 38417206
Haven't gone through all your code, but a few thoughts. My first concern is the first line:

<?php $_collectionSize = $_productCollection->count() ?>

Nowhere in your code are you creating the $_productCollection object, and you should use getSize() for the size. Something like this:

$_productCollection = $this->getProductCollection();
$_collectionSize = $_productCollection->getSize();

Also, lines 41 to the end don't make any sense - you have closing IF statements without openings and closing DIV tags without openings.
0
 
LVL 25

Expert Comment

by:lwadwell
ID: 38417207
Not sure if it a cut and paste issue or not ... but the snippet above has more "endif" statements then there are "if" statements.
0
 

Author Comment

by:rafique12
ID: 38417241
The end IF statements in the first code are not the issue s removing them at lines 49 and 51 cause the code to break as it is running a foreach loop to show a certain number of products in the grid...

As for the second code well... I simply don't know (scratches head in dispair)! This is a pasted code from a different theme that I have styled using the same css and javascript class so should work as is in the demo...
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 45

Expert Comment

by:Chris Stanyon
ID: 38417268
The IF statements are fine in the first code - it's the second block that's wrong (you code snippets don't have a line 49 and 51!).

Make sure your collection is populated as per my comments above.

Trim your script right back to basics and go from there:

<?php
$_productCollection = $this->getProductCollection();
$_collectionSize = $_productCollection->getSize();
printf("<h1>Num of products in collection: %s</h1>", $_collectionSize);
?>

Open in new window

If that works, introduce your foreach loop and build up 1 bit at a time.
0
 

Author Comment

by:rafique12
ID: 38417354
Sorry I'm not understanding...

Here's the demo of the live site
http://www.venustheme.com/demo/ves_store/

Open in new window

. I'm trying to replicate the products grid and use tabbed navigation to browse two categories NEW and REFURBISHED... I hope this makes it a bit clearer for eveyone involved here as we attempt to solve the problem :-)

p.s lines 49 and 51 are 23 and 23 for the first code...

TBH I only really need the second block from the second code snippet as the items will be listed in a grid not a list...

HELP ME PLEASE!!!
0
 
LVL 45

Expert Comment

by:Chris Stanyon
ID: 38417401
We can't see the code on the live demo - this is server-side code!

I'll say it again - the first code is correct - don't remove anything. The second code block  (your code) is wrong as it has too many closing ifs and divs.

In your original question, you say it should be fairly simple as you only need to change some CSS and javascript. If this is the case, why are you changing the PHP.

If you're getting a blank file when loading the page, then something is wrong with your template, which is why I suggested stripping it back to basics and building from there

Have you tried that and did it work?

If the original code worked, but is 'ugly' then why not just edit that - the bit that displays the product list is the bit inside the foreach loop
0
 

Author Comment

by:rafique12
ID: 38417449
We may have got lost in translation. The first code is my code - no issues. The second code is the code from the example I posted - which is giving problems.

I agree it should be simple but there is to many ifs and divs in the second (it isn't my code) I just wanted some ideas as to what might be causing the code to break I have tried what you suggested but the sam thing happens...

p.s I know its server side code which is why I posted the code in the original post (the second code) I just wanted you to visually see what I am a trying to achieve..

I'm sorry still leaning Magento and this place has helped me alot :-(
0
 
LVL 45

Accepted Solution

by:
Chris Stanyon earned 2000 total points
ID: 38417660
OK. I think I'll need a little more info.

Firstly how are you trying to use these templates. From looking at your code, the first block is a copy of the new.phtml template and is a complete file. The second block is from list.phtml and is only part of the template. Both files use different classes to handle their data.

Which file are you trying to change?
0
 

Author Closing Comment

by:rafique12
ID: 38417922
Ahhh! That's what is causing the code to break. See, this is why I love this forum because I learn from each problem or mistake.

Thanks again Chris!
0
 
LVL 45

Expert Comment

by:Chris Stanyon
ID: 38417987
Nice one...

It sometimes takes some digging but we usually get there in the end :)
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses
Course of the Month14 days, 7 hours left to enroll

807 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question