私は私のテンプレートファイルに次のコードがあります:私は私のレイアウトXMLで設定変数
<?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; ?>
:
<reference name="root">
<block type="catalog/product_view" name="test" template="path/to/products.phtml"/>
</reference>
を私は出力をしたとして、私はそれが正常に呼び出される知っていますそこからの静的コンテンツただし、有効な製品インスタンスであっても、ブロックによってブロックが認識されない場合は、
$product
のように表示されます。
コードは、デフォルトで/ template/catalog/product/view.phtmlからまっすぐ持ち上げられ、うまく動作します。私のすべてのコードは/しようとする製品を変更することです。これは私がブロックを使って作業した最初のことで、どこに間違っていたのかについてのヘルプ/ヒント/ポインタについて感謝しています。
ありがとうございます:-)。
EDIT
これは、ブロック/ Magentoのの私の理解が間違っていたが判明しました。答えは、AlanStormのチュートリアルを読むことにあります。
あなたは '$のproduct'と混乱し、' $の_product'の両方を使用して、彼らは本質的に異なるなら、彼らに意味のある名前を付けます。また、ループを使用しないときにループの先頭にオブジェクトを登録するポイントは何ですか? – clockworkgeek
カタログ/ product_viewは、$ product変数を探します(getProduct()ではMageレジストリを検索します)。それは使用されます。命名規則はMagentoのコアコードから直接得られます。 – james