Jump to content

[HELP] PS 1.6 Override: AdminStockManagementController to display image


realayumi

Recommended Posts

Hello,

 

I want to display image in AdminStockManagementController using override because i dont want to touch the core.

 

What i have done so far:

 

Create file in: /override/controllers/admin/AdminStockManagementController.php

<?php

class AdminStockManagementController extends AdminStockManagementControllerCore
{
	
	public function __construct()
	{
		parent::__construct();

		$pos = 3; //Change this to the position you want
		$this->fields_list = array_slice($this->fields_list, 0, $pos, true) +
		array(
		    'image' => array(
		    	'title' => $this->l('Photo'),
				'align' => 'center',
				'image' => 'p',
				'orderby' => false,
				'filter' => false,
				'search' => false
			)
		) + array_slice($this->fields_list, $pos, count($this->fields_list)-$pos, true) ;

		$part1 = array_slice($this->fields_list, 0, 4);
		$part2 = array_slice($this->fields_list, 5);
		$this->fields_list = array_merge($part1, $part2);
		var_dump($this->fields_list);
		
	}
	
	public function renderList()
	{
		
		parent::renderList();
		
		$alias_image = 'image_shop';
		$id_shop = Shop::isFeatureActive() && Shop::getContext() == Shop::CONTEXT_SHOP? (int)$this->context->shop->id : 'a.id_shop_default';		
		// sets actions	
		$this->_select = $this->_select.', MAX('.$alias_image.'.id_image) AS id_image ';
		//echo $this->_select;
		$this->_join  = $this->_join.' LEFT JOIN `'._DB_PREFIX_.'image` i ON (i.`id_product` = a.`id_product`) 
						   LEFT JOIN `'._DB_PREFIX_.'image_shop` image_shop ON (image_shop.`id_image` = i.`id_image` AND image_shop.`cover` = 1 AND image_shop.id_shop = '.$id_shop.') ';
		
		return parent::renderList();
	}
}




But its not display any image. For me, its easier to see the image than the SKU/reference.
Any help would be appreciate.

 

PS: I use PS 1.6.0.5

Advance Stock Management ON

If i direct edit to /controllers/admin/AdminStockManagementController.php it works.

 

Best regards

 

 

Edited by realayumi (see edit history)
Link to comment
Share on other sites

Yes, here i copy from class_index.php

 'AdminStockManagementController' => 
  array (
    'path' => 'override/controllers/admin/AdminStockManagementController.php',
    'type' => 'class',
  ),
  'AdminStockManagementControllerCore' => 
  array (
    'path' => 'controllers/admin/AdminStockManagementController.php',
    'type' => 'class',
  ),
Link to comment
Share on other sites

I have change the code below, it works so far :

<?php

class AdminStockManagementController extends AdminStockManagementControllerCore
{
	
	public function __construct()
	{

		parent::__construct();
		
		$this->fields_list['image'] = array(
			'title' => $this->l('Photo'),
			'align' => 'center',
			'image' => 'p',
			'orderby' => false,
			'filter' => false,
			'search' => false
		);
	}
	
	public function renderList()
	{

		//AdminController::renderList();

		parent::renderList();

		// overrides query
		$alias = 'sa';
		$alias_image = 'image_shop';
		$id_shop = Shop::isFeatureActive() && Shop::getContext() == Shop::CONTEXT_SHOP? (int)$this->context->shop->id : 'a.id_shop_default';		

		//$this->_select = $this->_select . ', MAX('.$alias_image.'.id_image) AS id_image ';
		$this->_select = $this->_select . ', MAX(i.id_image) AS id_image ';
		
		$this->_join = $this->_join .
						' LEFT JOIN `'._DB_PREFIX_.'image` i ON (i.`id_product` = a.`id_product`)		
						  LEFT JOIN `'._DB_PREFIX_.'image_shop` image_shop ON (image_shop.`id_image` = i.`id_image` AND image_shop.`cover` = 1 AND image_shop.id_shop = '.$id_shop.') ';
		return AdminController::renderList();
	}
}

Since i use this setting in defines.inc.php

 

define('_PS_MODE_DEV_', true);

and

define('_PS_DEBUG_PROFILING_', true);

 

Warning show (around 22x line like:

Notice on line 277 in file D:\apache\html\com\classes\helper\HelperList.php
[8] Undefined index: id_image

Please help.

 

Best regards

 

Link to comment
Share on other sites

  • 1 year later...
  • 8 months later...

I show my code in AdminStockManagementController.php ():

public function renderList()
{
// sets actions
$this->addRowAction('details');
$this->addRowAction('addstock');
$this->addRowAction('removestock');


if (count(Warehouse::getWarehouses()) > 1)
$this->addRowAction('transferstock');


// no link on list rows
$this->list_no_link = true;


// inits toolbar
$this->toolbar_btn = array();


// overrides query
$id_shop = Shop::isFeatureActive() && Shop::getContext() == Shop::CONTEXT_SHOP? (int)$this->context->shop->id : 'a.id_shop_default';
$this->_select = 'a.id_product as id, COUNT(pa.id_product_attribute) as variations, image_shop.id_image AS id_image';
$this->_join = 'LEFT JOIN `'._DB_PREFIX_.'product_attribute` pa ON (pa.id_product = a.id_product)'.Shop::addSqlAssociation('product_attribute', 'pa', false);
$this->_join .= 'LEFT JOIN `'._DB_PREFIX_.'image` i ON (i.`id_product` = a.`id_product`)
          LEFT JOIN `'._DB_PREFIX_.'image_shop` image_shop ON (image_shop.`id_product` = a.`id_product` AND image_shop.`cover` = 1 AND image_shop.id_shop = '.$id_shop.')';
$this->_where = 'AND a.is_virtual = 0';
$this->_group = 'GROUP BY a.id_product';


// displays informations
$this->displayInformation($this->l('This interface allows you to manage product stock and their variations.').'<br />');
$this->displayInformation($this->l('Through this interface, you can increase and decrease product stock for an given warehouse.'));
$this->displayInformation($this->l('Furthermore, you can move product quantities between warehouses, or within one warehouse.').'<br />');
$this->displayInformation($this->l('If you want to increase quantities of multiple products at once, you can use the "Supply orders" page under the "Stock" menu.').'<br />');
$this->displayInformation($this->l('Finally, you need to provide the quantity that you\'ll be adding: "Usable for sale" means that this quantity will be available in your shop(s), otherwise it will be considered reserved (i.e. for other purposes).'));


return parent::renderList();
}

In 'select' I add: image_shop.id_image AS id_image

After I see IMAGES of all products in StockManagement and HAVE NOT any error for HelperList.php

Edited by LiTiNuM (see edit history)
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...