1

I'm trying to modify the Mage_Adminhtml_Block_Sales_Order_Create_Search_Grid (where products are searched for in Magento Admin Order Create) in an attempt to add some custom inventory fields.

The inventory is stored as a product attribute against each individual product dependant on a warehouse location. The available locations are then defined in the config and called to fetch all locations and display stock. Below is the code I have in the grid.php

    $warehouseCodes = Mage::getStoreConfig('salesman/general/warehouse_code');
    $warehouses = explode(',',$warehouseCodes);
    foreach ($warehouses as $warehouse) {
        $this->addColumn($warehouse . "_stock", array(
        'header'=> Mage::helper('catalog')->__($warehouse . " Stock"),
        'width' => '30px',
        'type'  => 'number',
        'index' => Mage::helper('catalog')->__($warehouse . "_stock"),
    ));
    }

The good news is that the code works, however the stock figures do not show up against the products until the column is sorted in the grid. Whereas adding a column explicitly rather than using variables works as expected (code below).

    $this->addColumn('far_stock', array(
        'header'=> Mage::helper('catalog')->__('Far Stock'),
        'width' => '30px',
        'type'  => 'number',
        'index' => 'far_stock',
    ));
  • Thanks for the comment, I did manage to find my error in the collection instead it seems. Sorry about that! – Shaun Newrick Nov 16 '17 at 12:12
0

Turns out it was a very simple error in the collection of the items the collection was written with single quotation marks around the attributes to select which caused it not to work (or work as it did above)

    $warehouseCodes = Mage::getStoreConfig('salesman/general/warehouse_code');
    $warehouses = explode(',',$warehouseCodes);
    foreach ($warehouses as $warehouse) {
        $collection->addAttributeToSelect('$warehouse . '_stock'');
    }

Correct code

    $warehouseCodes = Mage::getStoreConfig('salesman/general/warehouse_code');
    $warehouses = explode(',',$warehouseCodes);
    foreach ($warehouses as $warehouse) {
        $collection->addAttributeToSelect($warehouse . '_stock');
    }

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.