View Single Post
  #1  
Old 12-24-2015, 04:53 AM
 
kirkbauer kirkbauer is offline
 

Member
  
Join Date: Dec 2015
Posts: 26
 

Default Trouble adding column to admin product list

I added a new column on xc_inventory and want to show it on the main admin product list right next to the "In Stock" column. The column appears but there is no data in it. But when I use inline editing I can view and modify the value. So it seems to only be an issue when displaying the search results.

Here is the relevant code. First I added the column to the inventory table:

PHP Code:
namespace XLite\Module\KB\TDT\Model;

class 
Inventory extends \XLite\Model\Inventory implements \XLite\Base\IDecorator
{
    
/**
     * Product reserved inventory
     *
     * (min: 0)
     *
     * @var integer
     *
     * @Column (type="integer", options={ "unsigned": true }, nullable=true)
     */
    
protected $reservedInventory;

    
/**
     * Set reserved inventory
     *
     * @param string $reservedInventory field value
     *
     * @return Product
     */
    
public function setReservedInventory($reservedInventory)
    {
        
$this->reservedInventory $this->correctAmount$reservedInventory );

        return 
$this;
    }


Then I extended the model for Product to cover this field (similar to the inventory qty field):

PHP Code:
namespace XLite\Module\KB\TDT\Model;

class 
Product extends \XLite\Model\Product implements \XLite\Base\IDecorator
{
    public function 
getReservedInventory()
    {
        return 
$this->getInventory()->getReservedInventory();
    }


And then I added the column to the product search/list results:

PHP Code:
namespace XLite\Module\KB\TDT\View\ItemsList\Model\Product\Admin;

class 
Search extends \XLite\View\ItemsList\Model\Product\Admin\Search implements \XLite\Base\IDecorator
{   
    protected function 
defineColumns()
    {
        
$columns parent::defineColumns();

        
$columns['reservedInventory'] = array(
            static::
COLUMN_NAME    => 'Reserved',
            static::
COLUMN_CLASS   => 'XLite\Module\KB\TDT\View\FormField\Inline\Input\Text\Integer\ReservedInventory',
            static::
COLUMN_ORDERBY => 600,
        );
    
        return 
$columns;
    }


I think that should be it, but for completeness here is what I added to get the field to show up on the Inventory tab (which works just fine):

PHP Code:
namespace XLite\Module\KB\TDT\View\Model;

class 
InventoryTracking extends \XLite\View\Model\InventoryTracking implements \XLite\Base\IDecorator
{   
    public function 
__construct(array $params = array(), array $sections = array())
    {
        
parent::__construct($params$sections);

        
$schema = array();

        foreach (
$this->schemaDefault as $name => $value) {
            
$schema[$name] = $value;
        }

        
$schema['reservedInventory'] = $this->defineReservedInventory();

        
$this->schemaDefault $schema;
    }
    
    protected function 
defineReservedInventory()
    {
        return array(
            static::
SCHEMA_CLASS    => 'XLite\View\FormField\Input\Text\Integer',
            static::
SCHEMA_LABEL    => 'Reserved Inventory',
            static::
SCHEMA_REQUIRED => false,
        );
    }


__________________
X-Cart Business 5.3.6.8
Reply With Quote