Magento - Display Category information in Sales Or

2019-09-07 21:13发布

问题:

EDIT: So a guy in this thread says the following: "All order data in Magento is product-specific. It doesn't store anything about what category the products are in. So, as you have found out, there are no reports available in Magento for that sort of thing." Is this true? Is what I am trying to do a lost cause?

I am trying to display product categories on Magento's backend Sales > Order > specific order view > Information > Items Ordered grid. This is not the main "Orders grid" that you see when navigating to Sales > Order. I want to alter the more detailed one that you see after clicking on a specific order in that first grid.

Following advice from this thread, I've made a new column and given it the proper title (Categories).

Then, to try to populate that column, I added code from Joost de Valk's solution on this thread to app/design/adminhtml/default/default/template/sales/order/view/items/renderer/default.phtml

I feel like I should be close (or not) but currently that code is just returning the word "Array". Any thoughts?

My current code is below. The column in question is the second td - the one that echoes $cats:

<?php $_item = $this->getItem() ?>
// Here is the snippet I pasted in to define variables.
<?php $product = Mage::getModel('catalog/product')->load($productId);

$cats = $product->getCategoryIds();
foreach ($cats as $category_id) {
    $_cat = Mage::getModel('catalog/category')->load($category_id) ;
    echo $_cat->getName();
}  ?>
<?php $this->setPriceDataObject($_item) ?>
<tr<?php if (!$this->canDisplayGiftmessage()): ?> class="border"<?php endif; ?>>
    <td>
        <?php if ($this->canDisplayContainer()): ?>
        <div id="<?php echo $this->getHtmlId() ?>" class="item-container">
        <?php endif; ?>
        <div class="item-text">
            <?php echo $this->getColumnHtml($_item, 'name') ?>
        </div>
        <?php if ($this->canDisplayContainer()): ?>
        </div>
        <?php endif ?>
    </td>
// Here is the column in question.
    <td class="a-center"><?php echo $cats ?></td>
    <td class="a-center"><?php echo $_item->getStatus() ?></td>
    <td class="a-right"><?php echo $this->displayPriceAttribute('original_price') ?></td>

etc, etc, etc ...

回答1:

$_cat is an object

$_cat = Mage::getModel('catalog/category')->load($category_id) ;

<td class="a-center"><?php echo $cats ?></td>

You need to know which property you want to display

echo $_cat->getXyz();

eg.

echo $_cat->getName();

To see a list of some of it properties try

print_r($_cat->getData());


回答2:

So it seems that categories are really complicated and certainly beyond my abilities. I figured out a work-around, however ugly. Since I am not using the manufacturer field and have only 4 relevant categories, I am creating "manufacturers" for each of those 4 categories, going through and assigning them to all products, and then calling for manufacturer in the relevant file. The code for manufacturer is as follows:

 <?php 
$manufacturer = Mage::getModel('catalog/product')->load($_item['product_id'])->getAttributeText('manufacturer'); 
echo $manufacturer;
?> 

Thanks to this post for that snippet and thanks to everyone else for their help.



标签: php magento