2

I've got a Module that allows someone to add products to a warehouse. In the products listing under the warehouse, I've got the product_id, stock etc.

What I would like is for the product_id to be represented by the SKU and the name instead as the product_id doesn't give anyone much.

/**
 * Override of the Prepare Collection method on the Mage_Adminhtml_Block_Widget_Grid
 * Defines the collection for the data within the grid
 *
 * @return Mage_Adminhtml_Block_Widget_Grid
 * @author Dan Hanly
 **/
public function _prepareCollection()
{
    if (!$this->_model) {
        $this->setModel(Mage::getModel('inventorymanagement/warehouse_product'));
    }

    // Override the Collection for the Class
    $collection = $this->_model->getCollection();
    $this->setCollection($collection);

    // Return the Completed Grid
    return parent::_prepareCollection();
}

/**
 * Override of the Prepare Columns method on the Mage_Adminhtml_Block_Widget_Grid
 * Defines the columns for the grid
 *
 * @return Mage_Adminhtml_Block_Widget_Grid
 * @author Dan Hanly
 **/
public function _prepareColumns()
{
    $this->addColumn('product_id', array(
        'header' => $this->__('Product'),
        'index' => 'product_id'
    ));

    $this->addColumn('stock', array(
        'header' => $this->__('Current Stock'),
        'index' => 'stock'
    ));

    $this->addColumn('low_level', array(
        'header' => $this->__('Low Level Notification'),
        'index' => 'low_level'
    ));

    $this->addColumn('critical_level', array(
        'header' => $this->__('Critical Level Notification'),
        'index' => 'critical_level'
    ));

    return parent::_prepareColumns();
}

Above is what I have so far, and I have a feeling that it's either going to be done in the prepareCollection method or the prepareColumns one.

Can anybody help?

1 Answer 1

2

Dan Just the below code at _prepareCollection() function

$collection = $this->_model->getCollection();

After

   $proname = Mage::getResourceModel('catalog/product')->getAttribute('name');
   //modify here
    $product = Mage::getResourceSingleton('catalog/product');
    $collection->getSelect()->joinLeft(
        array('product' => $proname->getBackend()->getTable()),
        'product.entity_id = main_table.product_id
        AND product.attribute_id = '.(int) $proname->getAttributeId().'',
        array('product_name'=>'value')
        )
    ->joinLeft(
        array('skutable' => $product->getEntityTable()),
        'skutable.entity_id = main_table.product_id',
        array(
            'product_sku' => 'skutable.sku',
        ));

And add below code for show this two columns at __prepareColumns()

$this->addColumn('product_name', array(
    'header' => Mage::helper('subscribe')->__('Product Name'),
    'align' =>'left',
    'index' => 'product_name',
    'filter_index' =>'product.value'
  ));

  $this->addColumn('product_sku', array(
    'header' => Mage::helper('subscribe')->__('Product Sku'),
    'align' =>'left',
    'index' => 'product_sku',
    'filter_index' =>'skutable.sku'
  ));
9
  • This gives me a ` Call to undefined method CompanyName_InventoryManagement_Model_Resource_Warehouse_Product_Collection::joinLeft()` Commented Sep 4, 2014 at 9:45
  • change $collection = $this->_model->getCollection(); to $collection = Mage::getModel('inventorymanagement/warehouse_product') Commented Sep 4, 2014 at 9:48
  • hey try to check stackoverflow.com/questions/14369497/… Commented Sep 4, 2014 at 9:54
  • I've used ->getSelect() before the joins and now it's working fine. However, for the SKU, i'm getting a 1054 Unknown column 'skutable.attribute_id' in 'on clause' Commented Sep 4, 2014 at 12:08
  • For reference, the product name is being outputted flawlessly. :) Commented Sep 4, 2014 at 12:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.