我使用自定义页面的xml布局将评论表单放到我的自定义页面上。自定义页面位于我的帐户部分,显示客户订购的所有产品。
<reference name="content">
<block type="review/form" name="product.info.review_form" as="review_form" template="review/form.phtml"/>
</reference>
这会将表单放在我的自定义页面的底部,但是我想在显示每个产品后调用审阅表单。我尝试过以下方法:
echo $this->getChild('review_form');
但它不起作用,我将遇到的另一个问题是将产品ID插入到表单操作中。我是以错误的方式解决这个问题吗?
更新完整代码:
<?php
if (Mage::getSingleton('customer/session')->isLoggedIn()) {
/* Get the customer data */
$customer = Mage::getSingleton('customer/session')->getCustomer();
/* Get the customer's email address */
$customer_email = $customer->getEmail();
}
$collection = Mage::getModel('sales/order')->getCollection()->addAttributeToFilter('customer_email', array(
'like' => $customer_email
));
$uniuqProductSkus = array();
foreach ($collection as $order) {
$order_id = $order->getId();
$order = Mage::getModel("sales/order")->load($order_id);
$ordered_items = $order->getAllItems();
foreach ($ordered_items as $item)
{
if (in_array($item->getProduct()->getSku(), $uniuqProductSkus)) {
continue;
} else {
array_push($uniuqProductSkus, $item->getProduct()->getSku());
$_product = Mage::getModel('catalog/product')->load($item->getProductId());
$product_small_image_path = Mage::helper('catalog/image')->init($_product, 'small_image')->resize(200);
$product_thumbnail_path = Mage::helper('catalog/image')->init($_product, 'small_image')->resize(150);
$summaryData = Mage::getModel('review/review_summary')->load($item->getProductId());
echo "<li>";
echo "<div class='previous-name'><p><a style='color:black; font-weight:bold; font-size:14px;' href='" . $_product->getProductUrl() . "'>";
echo $item->getName() . "</a></p></div>";
echo "<div class='previous-image'><a href='" . $_product->getProductUrl() . "'>";
echo "<img src='" . $product_small_image_path . "' />";
echo "</a></div>";
echo "<div class='previous-rating'>";
echo "<p><a style='color:black; font-weight:bold; font-size:14px;' href='" . $_product->getProductUrl() . "#product_tabs_review_tabbed'>Review this beer now</a></p>";
echo $summaryData->getRatingSummary() . '% Would buy again <br/>';
echo "<div class='rating-box' style='float:left;'>";
echo "<div class='rating' style='width:" . $summaryData->getRatingSummary() . "%'></div></div>";
echo "<div class='previous-clear'></div></div>";
$productsreviews = Mage::getModel('review/review')->getProductCollection()->addCustomerFilter(Mage::getSingleton('customer/session')->getCustomerId())->setDateOrder();
foreach ($productsreviews as $productsreview)
{
$product = Mage::getModel('catalog/product')->load($productsreview->getData('entity_pk_value'));
}
echo $product->getRating();
?>
<script type="text/javascript">
function toggle_visibility(id) {
var e = document.getElementById(id);
if(e.style.display == 'block')
e.style.display = 'none';
else
e.style.display = 'block';
}
</script>
<?php
echo '<a href="#" onclick="toggle_visibility(\'ajaxpro-notice-form' . $_product->getId().'\');" >Review Now</a>';
echo "<div id='ajaxpro-notice-form" . $_product->getId()."' class='ajaxpro-form' style='display:none'>";
echo '<a href="#" onclick="toggle_visibility(\'ajaxpro-notice-form' . $_product->getId().'\');" class="btn-close ajaxpro-button" title="Remove This Item">Remove This Item</a>';
$productId ='43';
$this->getChild('review_form')->setData('productId', $productId);
echo $this->getChildHtml('review_form', false);
echo "</div>";
/**echo "<div class='previous-button'>";
echo '<button type="button" title="Add to Cart" class="button btn-cart" onclick="setLocation(\'';
echo $this->helper('checkout/cart')->getAddUrl($_product);
echo '\')"><span><span>Order Again</span></span></button>';
echo "</div>";**/
?>
<?php $i = $_product->getId();?>
<div class='previous-button'>
<form action="<?php echo $this->helper('checkout/cart')->getAddUrl($_product); ?>" method="post" id="product_addtocart_form_<?php echo $_product->getId()?>"<?php if($_product->getOptions()): ?> enctype="multipart/form-data"<?php endif; ?>>
<?php if($_product->isSaleable()): ?>
<input type="text" name="qty" id="qty<?php echo $i;?>" maxlength="12" value="1" title="Qty" class="cartnum" />
<?php $qtyforaction = 'qty'.$i; ?>
<script type="text/javascript">
var qty = document.getElementById('qty').value;
document.getElementById('buttonaddcart').innerHTML = '<button type="button" class="addtocartbutton" onclick="setLocation(\'' + url + 'qty/' + qty + '/\')"></button>';
</script>
<div id="buttonaddcart">
<button type="button" class="addtocartbutton button btn-cart" onclick="setLocation('<?php echo $this->helper('checkout/cart')->getAddUrl($_product); ?>qty/')" >
<span><span>Order Again</span></span>
</button>
</div>
<?php else: ?>
<p class="availability out-of-stock"><span><?php echo $this->__('Out of stock') ?></span></p>
<?php endif; ?>
</form>
</div>
<?php
echo "<div class='previous-clear'></div>";
echo "</li>";
}
}
}
?>
答案 0 :(得分:0)
请改为尝试:
echo $this->getChildHtml('review_form');
此外,如果您要检索产品ID,则一切都取决于加载自定义页面的方式。我假设您使用的是自定义控制器,它是使用寄存器的最佳位置:
Mage::register('current_product', $product);
然后,您只需在模板文件中调用Mage::registry('current_product')
即可。