English 中文(简体)
Magento: Getting Product Url s for Products within a Grouped Product
原标题:

For a grouped product, I would like to display a link to the simple products it is composed of. For example, if I have a grouped product called Dining Set composed of plates, knives, forks, etc. I d like each of the subproducts to have a link to that subproduct (click plates goes to the Simple Product for plates)

<?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; ?>

This is a code snippet from the grouped.phtml file in

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

In particular the line that has $_item->getProductUrl(), this does not work, and I don t know the code needed to get the url for this associated product item. If anyone could help here it would be much appreciated.

Also, where on earth can I find the method s available (and how they re used) for Products or Categories or $_item and the like?

最佳回答

Easy to find all methods and functions. Always trace back to the Core /app/code/core/Mage/Catalog/Model/Product.php or any of the other files in that Folder.

Your code is perfect. Just use

$_item->getUrlPath() ;

instead of productURL.

问题回答

Just a few notes on getting the available methods / data:

First, to get all methods actually coded into the classes, you can get all the available methods with:

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

To get all data-related methods, first find out the data members in the class. This works with most objects in Magento:

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

Then you can get any piece of data you want two ways:

// assuming I want  my_data 
$data = $_item->getMyData();
$data = $_item->getData( my_data );
<?php echo $this->htmlEscape($_item->getProductUrl()) ?>

or here is the whole A HREF:

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




相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...

热门标签