1

I am looking for some advice on how best to link to a CMS product page from a template phtml file. I need to generate a link using 'foreach' as each product will have its own CMS product page. For example I have six products currently being displayed on the homepage I would like to have an 'order now' button that will take the user to the 'add to cart' page (view.phtml) and a 'more info?' button that will take the user to the CMS page for that product... is there a way to achieve this?

Here's the code from new.phtml

<div class="new-product-content"> <?php if (($_products = $this->getProductCollection()) && $_products->getSize()): ?> <h3 class="subtitle new-products"><?php echo $this->__('HOT PRODUCTS') ?></h3> <?php $_columnCount = $this->getColumnCount(); ?> <?php $i=0; foreach ($_products->getItems() as $_product): ?> <?php if ($i++%$_columnCount==0): ?> <ul> <?php endif ?> <li class="thumb<?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()) ?>" ><img src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(175) ?>" width="175" height="175" alt="<?php echo $this->htmlEscape($_product->getName()) ?>" /> </a> <div class="caption"> <h4 class="product-name"> <?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 ?><?php echo $this->__('&#8482;'); ?></a></h4> <?php echo $this->getPriceHtml($_product, true, '-new') ?> <div class="clearfix"></div> <div class="desc"> <?php $sdesc = $_product->getShortDescription(); $sdesc = trim($sdesc); $limit = 180; if (strlen($sdesc) > $limit) { $sdesc = substr($sdesc, 0, strrpos(substr($sdesc, 0, $limit), ' ')); } ?> <?php echo $sdesc."..."; ?> </div> <div class="clearfix"></div> <div class="btn-group"> <button class="btn" type="button" title="<?php echo $this->__('Add to Cart') ?>" onclick="setLocation('<?php echo $this->getProductUrl($_product) ?>')"><?php echo $this->__('Order now...') ?></button> <!--I NEED TO CHANGE THE DESTINATION OF THIS LINK <button class="btn" type="button" title="<?php echo $this->__('More info') ?>" onclick="setLocation('<?php echo $this->getProductUrl($_product) ?>')"><?php echo $this->__('More info?') ?></button> ---> </div> </li> <?php if ($i%$_columnCount==0 || $i==count($_products)): ?> </ul> <div class="clearfix"></div> <?php endif ?> <script type="text/javascript"> $j('.thumb li').last().css('border-right', 'none'); </script> <script type="text/javascript">decorateGeneric($$('ul.products-grid'), ['odd','even','first','last'])</script> <?php endforeach; ?> <?php endif; ?> <div class="clearfix"></div> </div> 
4
  • Not sure what you are trying to do but the get the link for a cms page you can do <?php echo $this->getUrl('cms_product_page_id');?> Commented Dec 4, 2012 at 21:57
  • @R.S Thanks for the response basically I need to find a way to link to the product pages for each product shown in new.phtml there are six in total each has its own CMS product page. Specifying the CMS id would mean only one page is called for every product but each product has its own... Hope that makes more sense. I think maybe I need to somehow link the CMSid with the product Commented Dec 4, 2012 at 22:03
  • What is a 'CMS product page'? Commented Dec 4, 2012 at 22:07
  • @R.S CMS/Page/addpage then on the CMS page i have products showing for each category using the catalog/product_list_related block type and specifying the product_id. I created a module which works well as product can be added to cart from this page. i now need to link to the CMS pages from say the homepage where new products are shown.. Commented Dec 4, 2012 at 22:11

1 Answer 1

2

Try something like, you need to get the 'url key' for the cms pages

<button class="btn" type="button" title="<?php echo $this->__('More info') ?>" onclick="setLocation('<?php echo $this->getUrl('url key'); ?>')"><?php echo $this->__('More info?') ?></button> 
Sign up to request clarification or add additional context in comments.

7 Comments

The problem lies herein. I need to somehow link the CMS page_id with each product_id so when the 'more info' link is clicked the correct CMS page loads which belongs that product. If i simply add the url key the the same page will load for all products in my store...
One of the easy way to do this is to make each cms page url key include the product id or sku etc. eg product-123, where product_id = 123... Then <?php echo $this->getUrl('product-' . $_products->getId()); ?>
I will try this out it sounds like the right solution. If the cms URL is: my site.com/shoes then specifying the product id would load my site.com/shoes.html and load View.phtml file???
The url would be site.com/shoes-{product_id}, all the cms page key would need to start with 'shoes-'
Terrible for SEO but it seems the only way
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.