Magento 电子商务 - 如何调用产品详细信息并将其显示到 CMS 页面中?

发布于 2024-12-04 04:56:59 字数 259 浏览 0 评论 0原文

我希望能够以与产品页面中显示的方式相同的方式插入和显示产品,但插入到 CMS 页面(包含属性、价格、订单按钮等...)

我已经成功创建了一个通过插入产品页面源代码的复制部分来创建页面,但考虑到我计划完成相当多的页面,这是一个相当漫长且耗时的过程。

因此我希望能够将产品详细信息调用到 CMS 页面中。

我以为我可以使用 view.phtml 并将其插入所需的 CMS 页面,但我也不知道如何定义product_id...

提前感谢大家的评论

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

神仙妹妹 2024-12-11 04:56:59

嗯,CMS 宏如下所示:

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

引用模板目录/产品/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>

请注意,这会引入一些您可能在系统上找不到的自定义属性和变量。最重要的是 CMS 宏

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

和这一行:

< code>loadByAttribute('sku',$this->getData('sku_id')); ?>

在 CMS 页面上根据需要多次使用宏。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文