X-Cart: shopping cart software

X-Cart forums (https://forum.x-cart.com/index.php)
-   Dev Questions (X-Cart 5) (https://forum.x-cart.com/forumdisplay.php?f=56)
-   -   Trouble adding column to admin product list (https://forum.x-cart.com/showthread.php?t=73333)

kirkbauer 12-24-2015 04:53 AM

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,
        );
    }





All times are GMT -8. The time now is 09:06 PM.

Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.