4

I was wondering how we could add a stock value in the 'backend new order creation' ... see image below

What we see now is that we enter an order, but in the next step are warned that ther is no stock ... so why not add the stock value as a column. Also we would very much like to filter on configurable products.

I was looking at app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Search/Grid.php

and wanted to add this code

if (Mage::helper('catalog')->isModuleEnabled('Mage_CatalogInventory')) {
    $this->addColumn('qty',
        array(
            'header'=> Mage::helper('catalog')->__('Qty'),
            'width' => '30px',
            'type'  => 'number',
            'index' => 'qty',
    ));
}

and the field itself in collection

 protected function _prepareCollection()
    {
        $attributes = Mage::getSingleton('catalog/config')->getProductAttributes();
        /* @var $collection Mage_Catalog_Model_Resource_Product_Collection */
        $collection = Mage::getModel('catalog/product')->getCollection();
        $collection
            ->setStore($this->getStore())
            ->addAttributeToSelect($attributes)
            ->addAttributeToSelect('sku')
            ->addStoreFilter()
            ->addAttributeToFilter('type_id', array_keys(
                Mage::getConfig()->getNode('adminhtml/sales/order/create/available_product_types')->asArray()
            ))
            ->addAttributeToSelect('gift_message_available');

        Mage::getSingleton('catalog/product_status')->addSaleableFilterToCollection($collection);

        if (Mage::helper('catalog')->isModuleEnabled('Mage_CatalogInventory')) {
            $collection->joinField('qty',
                'cataloginventory/stock_item',
                'qty',
                'product_id=entity_id',
                '{{table}}.stock_id=1',
                'left');
        }

but now the problems is that the 'order quantity' (most right column in image) is also called qty ... and now they are conflicting. Question: How would I get the stock qty as 'alternate name' and show it?

And could we also easily add configurable/simple product selector?

enter image description here

5

You can simply set a different alias for the inventory quantity. Something like inv_qty see edits below.

protected function _prepareCollection()
{
    $attributes = Mage::getSingleton('catalog/config')->getProductAttributes();
    /* @var $collection Mage_Catalog_Model_Resource_Product_Collection */
    $collection = Mage::getModel('catalog/product')->getCollection();
    $collection
        ->setStore($this->getStore())
        ->addAttributeToSelect($attributes)
        ->addAttributeToSelect('sku')
        ->addStoreFilter()
        ->addAttributeToFilter('type_id', array_keys(
                Mage::getConfig()->getNode('adminhtml/sales/order/create/available_product_types')->asArray()
            ))
        ->addAttributeToSelect('gift_message_available');

    Mage::getSingleton('catalog/product_status')->addSaleableFilterToCollection($collection);

    if (Mage::helper('catalog')->isModuleEnabled('Mage_CatalogInventory')) {
        $collection->joinField('inv_qty',
            'cataloginventory/stock_item',
            'qty',
            'product_id=entity_id',
            '{{table}}.stock_id=1',
            'left');
    }
    $this->setCollection($collection);
    return parent::_prepareCollection();
}

And then add this new column using the alias as the index and setting a new id for it.

if (Mage::helper('catalog')->isModuleEnabled('Mage_CatalogInventory')) {
    $this->addColumn('inv_qty',
        array(
            'header'=> Mage::helper('catalog')->__('Qty'),
            'width' => '30px',
            'type'  => 'number',
            'index' => 'inv_qty',
        ));
}
0

To add onto the above answer by David,

remember that you may have to

return Mage_Adminhtml_Block_Widget_Grid::_prepareCollection();

instead of

return parent::_prepareCollection();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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