我的模板文件中有以下代码:
<?php foreach($collection as $product): ?>
<?php Mage::unregister('product'); ?>
<?php Mage::register('product', $product); ?>
<?php $_product = $this->getProduct(); ?>
<div class="product-view">
<div class="product-essential">
<form action="<?php echo $this->getSubmitUrl($_product); ?>" method="post" id="product_addtocart_form"<?php if($_product->getOptions()): ?> enctype="multipart/form-data"<?php endif; ?>>
<div class="no-display">
<input type="hidden" name="product" value="<?php echo $product->getId() ?>" />
<input type="hidden" name="related_product" id="related-products-field" value="" />
</div>
<div class="product-shop">
<div class="product-name">
<h1><?php echo $_product->getName(); ?></h1>
</div>
<?php echo $this->getChildHtml('alert_urls') ?>
<?php echo $this->getChildHtml('product_type_data') ?>
<?php echo $this->getTierPriceHtml() ?>
<?php echo $this->getChildHtml('extrahint') ?>
<?php if (!$this->hasOptions()):?>
<div class="add-to-box">
<?php if($_product->isSaleable()): ?>
<?php echo $this->getChildHtml('addtocart') ?>
<?php if( $this->helper('wishlist')->isAllow() || $_compareUrl=$this->helper('catalog/product_compare')->getAddUrl($_product)): ?>
<span class="or"><?php echo $this->__('OR') ?></span>
<?php endif; ?>
<?php endif; ?>
<?php echo $this->getChildHtml('addto') ?>
</div>
<?php echo $this->getChildHtml('extra_buttons') ?>
<?php endif; ?>
<?php if ($_product->getShortDescription()):?>
<div class="short-description">
<h2><?php echo $this->__('Quick Overview') ?></h2>
<div class="std"><?php echo $_helper->productAttribute($_product, nl2br($_product->getShortDescription()), 'short_description') ?></div>
</div>
<?php endif;?>
<?php echo $this->getChildHtml('other');?>
<?php if ($_product->isSaleable() && $this->hasOptions()):?>
<?php echo $this->getChildChildHtml('container1', '', true, true) ?>
<?php endif;?>
</div>
<div class="product-img-box">
<?php echo $this->getChildHtml('media') ?>
</div>
<div class="clearer"></div>
<?php if ($_product->isSaleable() && $this->hasOptions()):?>
<?php echo $this->getChildChildHtml('container2', '', true, true) ?>
<?php endif;?>
</form>
</div>
</div>
<?php endforeach; ?>
在我的布局XML中,我有:
<reference name="root">
<block type="catalog/product_view" name="test" template="path/to/products.phtml"/>
</reference>
我知道它被成功调用,因为我输出了静态内容。但是,它看起来好像是
$product
未被块识别,即使它是有效的产品实例。
代码直接从default / template / catalog / product / view.phtml解除,它可以正常工作。我的所有代码确实/尝试做的是更改产品。这是我第一次使用积木,对于我出错的地方有任何帮助/提示/指示,我将不胜感激。
提前致谢: - )。
修改
事实证明我对块/ Magento的理解是不正确的。答案在于阅读AlanStorm教程。
答案 0 :(得分:0)
我有类似的问题,首先尝试用布局xml中的单引号替换所有double
我希望你只是虚拟引用template="path/to/products.phtml"
进行演示,并在你的代码中使用真正的Magento路径
不能告诉你更多因为我也是Magento的初学者。只有一些有用的链接:
http://www.magentocommerce.com/knowledge-base/entry/magento-for-dev-part-1-introduction-to-magento
http://inchoo.net/category/ecommerce/magento/