David Garray
David Garray

Reputation: 1

Magento Ecommerce - How to call and display a product's details into a CMS page?

I would like to be able to insert and display a product the same way it is displayed in the product page, but into a CMS page (with attributes, prices, order button, etc...)

I've succeeded in creating a single page by inserting copied parts of the source code of a product page but this is quite a lenghty and time consuming process considering that I'm planning to have quite a few pages done.

Therefore I would like to be able to call the product details into a CMS page.

I thought I could use the view.phtml and insert it into the desired CMS page but I couldn't figure out how to define the product_id either...

Thank you all in advance for your comments

Upvotes: 0

Views: 2109

Answers (1)

Fiasco Labs
Fiasco Labs

Reputation: 6457

Hmm, CMS Macro like this:

{{block type="catalog/product" template="catalog/product/line-item.phtml" sku_id="CI 101"}}

Referencing template catalog/product/line-item.phtml:

<?php //Template_Name/catalog/product/line-item.phtml
      //{{block type="catalog/product" template="catalog/product/line-item.phtml" sku_id="CI 100"}}
      //Feed template SKU for product listing 
?>

<?php $_product = Mage::getModel('catalog/product')->loadByAttribute('sku',$this->getData('sku_id')); ?>

<?php /* get special freight messages from custom variables */
    $freightfree = Mage::getModel('core/variable')->loadByCode('free_freight_text')->getValue('plain');
    $hazmat = Mage::getModel('core/variable')->loadByCode('hazmat_text')->getValue('plain');
    $ormd = Mage::getModel('core/variable')->loadByCode('ormd_text')->getValue('plain');
?>

<!-- <div class="single-product"> -->
<div class="listing-type-list catalog-listing">
<div class="listing-item last">
    <?php $specialshipping = $_product->getAttributeText('special_shipping_group') ?>

        <?php // Product Image ?>
        <div class="product-image">
            <a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->htmlEscape($_product->getSmallImageLabel()) ?>">
                <img src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(135, 135); ?>" width="135" height="135" alt="<?php echo $this->htmlEscape($this->getImageLabel($_product, 'small_image')) ?>" title="<?php echo $this->htmlEscape($this->getImageLabel($_product, 'small_image')) ?>" />
            </a>
        </div>

        <?php // Product description ?id= echo $_product->getId();?>
        <div class="product-shop">
            <h2><a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->htmlEscape($_product->getName()) ?>"><?php echo $this->htmlEscape($_product->getName())?></a></h5>
            <?php if($_product->getRatingSummary()): ?>
            <?php echo $this->getReviewsSummaryHtml($_product) ?>
            <?php endif; ?>
            <?php echo $this->getPriceHtml($_product, true) ?>
            <?php if(!$_product->getNotforsale()): ?>
                <?php if(!$_product->getReplace_add_button()): ?>
                    <?php if($_product->isGrouped()): ?>
                        <button class="form-button" onclick="setLocation('<?php echo $this->getAddToCartUrl($_product) ?>')"><span><?php echo $this->__('View Selection') ?></span></button>
                    <?php elseif($_product->getHasOptions()): ?>
                        <button class="form-button" onclick="setLocation('<?php echo $this->getAddToCartUrl($_product) ?>')"><span><?php echo $this->__('View Options') ?></span></button>
                    <?php else: ?>
                        <button class="form-button" onclick="setLocation('<?php echo $this->getAddToCartUrl($_product) ?>')"><span><?php echo $this->__('Add to Cart') ?></span></button>
                    <?php endif; ?>
                <?php else: ?>
                    <button class="form-button" onclick="setLocation('<?php echo $_product->getProductUrl() ?>')"><span><?php echo $_product->getAttributeText('replace_add_button') ?></span></button>                    
                <?php endif; ?>
            <?php endif; ?>
            <div class="clear"></div>
            <?php  /* display special freight messages from custom variables */ ?>
            <?php if($specialshipping == "Free Ground" || $specialshipping == "Free Gnd ORMD"): ?>
                <?php echo '<span class="regular-price"><span class="freightfree">' . $freightfree . '</span></span>' ?>
            <?php endif; ?>
            <?php if($specialshipping == "ORM-D"): ?>
                <?php echo '<span class="freightfree">' . $ormd . '</span>' ?>
            <?php elseif($specialshipping == "Free Gnd ORMD"): ?>
                <?php echo '<br><span class="freightfree">' . $ormd . '</span>' ?>
            <?php elseif($specialshipping == "HazMat"): ?>
                <?php echo '<span class="freightfree">' . $hazmat . '</span>' ?>
            <?php endif; ?>
            <div class="description">
                <?php echo nl2br($_product->getShortDescription()) ?>
                <a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->htmlEscape($_product->getName()) ?>"><small><?php echo $this->__('Learn More') ?></small></a>
            </div>
            <p class="add-to">
                Brand Name: <?php echo $_product->getBrand() ?>
            </p>
        </div>
 </div>
 </div>

Be aware this is pulling in several custom attributes and variables you probably won't find on your system. The most important is the CMS Macro

{{block type="catalog/product" template="catalog/product/line-item.phtml" sku_id="CI 101"}}

and this line:

<?php $_product = Mage::getModel('catalog/product')->loadByAttribute('sku',$this->getData('sku_id')); ?>

Use Macro as many times on the CMS page as you want.

Upvotes: 3

Related Questions