Pergunta

My site is a multi-vendor marketplace where I only allow customers to purchase items from one vendor at a time.

I'm trying to grab the vendor's name for the Recent Orders and My Orders tables, which seemed like it would be easy to do in my head, but is turning out to require a little more provoking of thought.

The only place on the site that successfully does this already is sales/order/items/renderer/default.phtml.

<?php $_item = $this->getItem() ?>

<tr class="border" id="order-item-row-<?php echo $_item->getId() ?>">

    <td><h3 class="product-name"><?php echo $this->htmlEscape($_item->getName()) ?></h3>

        <!--vendor  -->
        <?php $vendor = Mage::getModel('csmarketplace/vendor')->load($_item->getVendorId());
        if($vendor && $vendor->getId()){
        ?>

        <div><strong><?php echo $this->helper('sales')->__('Vendor') ?>:</strong>
    <?php $url =  $vendor->getVendorShopUrl();
        echo "<a href='". $url . "' target='_blank' >".$vendor->getPublicName()."</a>";?></div>

    <?php }?>

It's grabbing the vendor's ID and then the URL to their personal shop page, along with their name.

So I'm using this to help me find a way to do the same in sales/order/recent.phtml and sales/order/history.phtml.

I've tried the following:

$vendor = Mage::getModel('csmarketplace/vendor')->load($_order->getVendorId())->getPublicName();

And it results in no error, but also displays nothing.

Relevant variables/statements from recent.phtml and history.phtml:

$order = Mage::getModel('sales/order')->loadByIncrementId($orderId);
$_orders = $this->getOrders();


<?php foreach ($_orders as $_order):
<tr><td><span class="cell-label"><?php echo $this->__('Seller') ?></span>
//Insert Vendor name here
    </td></tr> ?>

My thought process thus far has been to try to grab the parent item or item collection and then getVendorId() using that, but have had no luck. I understand there's a lack of code from the multi-vendor part, but I'm really just looking for ideas that could work.

I can't seem to find the connection between getItem(), used in default.phtml and getItems() which is used in the recent.phtml and history.phtml.

Foi útil?

Solução

So I finally managed to successfully grab the vendor username using the following code:

$_items = $_order->getItemsCollection();
       foreach ($_items as $item){
          if ($item->getParentItem()) continue;
             $vendor = Mage::getModel('csmarketplace/vendor')->load($item->getVendorId());
             echo $vendor->getPublicName();

             break;
        }

The one issue, is that if there was more than one item in the order, it displays the the vendor username multiple times. Is there any way to manipulate the code to display the name of JUST one item? I assumed it would only display for the ParentItem, but I was wrong.

Update: I completely forgot about just using break; Above code is working code!

Licenciado em: CC-BY-SA com atribuição
Não afiliado a magento.stackexchange
scroll top