0

I'm using SNM Mobile Admin to scan and add stock, and I've added a custom attribute called location_shelf, like this:

<div data-role="fieldcontain">
            <label for="product[location_shelf]"><?php echo $this->__('Locatiecode') ?></label>
                         <?php $_product = $this->getProduct(); ?>
            <input type="text" name="product[location_shelf]" id="product[location_shelf]" value="<?php echo $_product->getLocationShelf();?>"/>
        </div>

It shows perfectly when I scan a product. Now I want to do the same with the order-details page, but it just doesn't show up. The only things that works is:

    <?php $model = Mage::getModel('catalog/product')
    ->getCollection()
    ->addAttributeToSelect('location_shelf')

->addAttributeToFilter('entity_id',32)
->getFirstItem();?>


 <p><?php echo $model->getLocationShelf();?>
</p>

It only shows one location ofcourse, but editing this piece always leads to an error.

The module's original order view code is based on Mage_Sales_Model_Order And uses $_order = $this->getOrder(); and

<?php $_items = $_order->getItemsCollection();?>

to get all the product info. Is there a way to show my custom attribute somewhere in here?

<?php echo $_item->getLocationShelf();?>

doesn't work unfortunately

The errors I get are like this: Call to a member function getLocationShelf() on a non-object

Thanks in advance!

0

2 Answers 2

0

Take a look at Adding Custom Product Attribute To Quote And Order Items In Magento and product attribute to quote item and order item

The better way to do this is

  1. Add the attribute field to your product
  2. Add the attribute field to your quote_item and order_item
  3. Add an observer that get and set the quote_item from the product object when an item is added to cart
  4. Clear your cache
  5. Then you will be able to do <?php echo $_item->getLocationShelf();?>
0
0

@R.S

Well, I just got it working with adding this to /app/design/adminhtml/default/snm-mobile/template/auit/madmin/orders/show.phtml:

<?php $skulocation = $_item->getSku(); ?> 
<?php $model = Mage::getModel('catalog/product') 
->getCollection() ->addAttributeToSelect('location_shelf')
->addAttributeToFilter('sku',$skulocation) 
->getFirstItem();?>

and using

<h4><?php echo $this->__('Location')?></h4>
<p><?php echo $model->getLocationShelf();?>

underneath

<h4><?php echo $this->__('SKU')?></h4>
<p><?php echo $_item->getSku();?></p>

But I will try your method, I like to do this the right way.

Not the answer you're looking for? Browse other questions tagged or ask your own question.