我希望能夠插入和顯示產品被顯示在產品頁面同樣的方式,而是進入一個CMS頁面(帶屬性,價格,命令按鈕,等...)Magento電子商務 - 如何在CMS頁面中調用並顯示產品詳情?
我通過插入產品頁面的源代碼的複製部分,我成功地創建了單個頁面,但考慮到我打算完成相當多的頁面,這是相當長而耗時的過程。
因此,我希望能夠將產品詳細信息調入CMS頁面。
我想我可以使用view.phtml並將其插入到所需的CMS頁面,但我無法弄清楚如何可以定義的product_id ...
謝謝大家提前爲您的意見
我希望能夠插入和顯示產品被顯示在產品頁面同樣的方式,而是進入一個CMS頁面(帶屬性,價格,命令按鈕,等...)Magento電子商務 - 如何在CMS頁面中調用並顯示產品詳情?
我通過插入產品頁面的源代碼的複製部分,我成功地創建了單個頁面,但考慮到我打算完成相當多的頁面,這是相當長而耗時的過程。
因此,我希望能夠將產品詳細信息調入CMS頁面。
我想我可以使用view.phtml並將其插入到所需的CMS頁面,但我無法弄清楚如何可以定義的product_id ...
謝謝大家提前爲您的意見
嗯,CMS宏像這樣:
{{block type="catalog/product" template="catalog/product/line-item.phtml" sku_id="CI 101"}}
引用模板目錄/產品/線路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"}}
這行:
<?php $_product = Mage::getModel('catalog/product')->loadByAttribute('sku',$this->getData('sku_id')); ?>
使用宏爲你想要的CMS頁面上許多倍。
定期檢查您的CMS頁面。如果有人變得可愛並從您的目錄中刪除了一個SKU而沒有注意,它會拋出一個不存在的對象錯誤。當我得到時間時,我需要添加一個測試。 –
太棒了......這個工作做得很好......非常感謝;-) –
嗨Fiasco實驗室......如果我想從類別描述中做同樣的事情,我會怎麼做呢?當我粘貼相同的代碼(從CMS頁面完美地工作)不適用於/從類別描述。 我試過但無濟於事 請指教。 Thx很多;-) –