简体   繁体   中英

Link to a CMS product page in Magento

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> 

尝试类似的操作,您需要获取cms页面的“ URL密钥”

<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> 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM