Magento:在分组产品中获取产品网址

问题描述:

对于分组产品,我想显示它所组成的简单产品的链接。例如,如果我有一个名为Dining Set的分组产品,它由盘子,刀子,叉子等组成,我希望每个子产品都有一个与该子产品的链接(点击标签转到用于印版的简单产品)Magento:在分组产品中获取产品网址

<?php foreach ($_associatedProducts as $_item): ?> 
    <tr> 
     <td><?php echo $this->htmlEscape($_item->getName()) ?></td> 
     <td class="a-right"> 
      <?php echo $this->getPriceHtml($_item, true) ?> 
     </td> 
     <?php if ($_product->isSaleable()): ?> 
     <td class="a-center"> 
     <?php if ($_item->isSaleable()) : ?> 
      <a href="<?php $_item->getProductUrl() ?>">View</a> 
     <?php else: ?> 
      <p class="availability"><span class="out-of-stock"><?php echo $this->__('Out of stock.') ?></span></p> 
     <?php endif; ?> 
     </td> 
     <?php endif; ?> 
    </tr> 
<?php endforeach; ?> 

这是从grouped.phtml文件中的代码片段在

app/design/frontend/blank/default/template/catalog/product/view/type/grouped.phtml 

特别有$_item->getProductUrl()这不起作用行, ,我不知道,以获得所需的代码此相关产品项目的网址。如果有人可以在这里帮助,将不胜感激。

此外,我在哪里可以找到该方法可用(以及它们如何使用)的产品或类别或$_item等?

很容易找到所有的方法和功能。始终追溯至Core /app/code/core/Mage/Catalog/Model/Product.php或该文件夹中的任何其他文件。

你的代码是完美的。只需使用

$_item->getUrlPath() ; 

而不是productURL

+0

大多数时候你可以猜测...... 我创建了新的属性,如完成,尺寸,lead_time等在循环内,调用getData('lead_tim电子'),它只是工作!辉煌的ORM! – 2009-12-23 02:49:25

刚上获取可用的方法/数据的几点注意事项:

第一,得到实际编码到类的所有方法,你可以得到所有可用的方法:

$array = get_class_methods($_item); //yields an array of the methods in the class 
var_dump($array); // to see the methods 

要获得所有与数据相关的方法,首先找出班级中的数据成员。这适用于大多数对象在Magento:

$data = $_item->getData(); // $key => $value array 

然后你就可以得到任何数据,你想有两种方式:

// assuming I want 'my_data' 
$data = $_item->getMyData(); 
$data = $_item->getData('my_data'); 

<?php echo $this->htmlEscape($_item->getProductUrl()) ?> 

或这里是整个A HREF:

<a href="<?php echo $this->htmlEscape($_item->getProductUrl()) ?>"> 
      <?php echo $this->htmlEscape($_item->getName()) ?> 
</a>