[TomatoCart] Show variants in the products grid table

It’s really not effective to verify variants linked to products in the admin panel. The store owner must click the edit button in the products grid to open the products dialog to check the variants.

Snip20141214_2

So, it would be better to show the variants directly in the products grid as follow:

Snip20141214_4

It is not difficult to apply it for your store. You just need to update a few of code:

Step 1. Open products.php under admin > includes > jsons fold and then find following code snippet:

$Qstatus = $osC_Database->query('select products_id from :table_products_frontpage where products_id = :products_id');
        $Qstatus->bindInt(':products_id', $Qproducts->value('products_id'));
        $Qstatus->bindTable(':table_products_frontpage', TABLE_PRODUCTS_FRONTPAGE);
        $Qstatus->execute();

Add following code after it:

$Qvariants = $osC_Database->query('select * from :table_products_variants where products_id = :products_id order by is_default DESC');
        $Qvariants->bindTable(':table_products_variants', TABLE_PRODUCTS_VARIANTS);
        $Qvariants->bindInt(':products_id', $Qproducts->value('products_id'));
        $Qvariants->execute();
        
        $groups = array();
        while ($Qvariants->next()) {
        	$Qvalues = $osC_Database->query('select pve.products_variants_groups_id as groups_id, pve.products_variants_values_id as variants_values_id, pvg.products_variants_groups_name as groups_name, pvg.sort_order as groups_sort_order, pvv.products_variants_values_name as variants_values_name, pvv.sort_order as sort_order from :table_products_variants_entries pve, :table_products_variants_groups pvg, :table_products_variants_values pvv where pve.products_variants_groups_id = pvg.products_variants_groups_id and pve.products_variants_values_id = pvv.products_variants_values_id and pvg.language_id = pvv.language_id and pvg.language_id = :language_id and pve.products_variants_id = :products_variants_id order by pvg.sort_order, pvg.products_variants_groups_name, pve.products_variants_groups_id');
        	$Qvalues->bindTable(':table_products_variants_entries', TABLE_PRODUCTS_VARIANTS_ENTRIES);
        	$Qvalues->bindTable(':table_products_variants_groups', TABLE_PRODUCTS_VARIANTS_GROUPS);
        	$Qvalues->bindTable(':table_products_variants_values', TABLE_PRODUCTS_VARIANTS_VALUES);
        	$Qvalues->bindInt(':language_id', $osC_Language->getID());
        	$Qvalues->bindInt(':products_variants_id', $Qvariants->valueInt('products_variants_id'));
        	$Qvalues->execute();
        	
        	while ($Qvalues->next()) {
        		$groups[$Qvalues->value('groups_name')] = $Qvalues->value('variants_values_name');
        	}
        	
        	$Qvalues->freeResult();
        }
        
        $Qvariants->freeResult();
        
        $variants_groups = '';
        if (count($groups) > 0) {
        	foreach ($groups as $group_name => $entry_value) {
        		$variants_groups .= $group_name . ': ' . $entry_value . '<br />';
        	}
        }
        
        if (empty($variants_groups)) {
        	$variants_groups = '--';
        }

Find following code snippet:

$records[] = array(
          'products_id'         => $Qproducts->value('products_id'),
          'products_name'       => $Qproducts->value('products_name'),
        	'products_sku'				=> $Qproducts->value('products_sku'),
          'products_frontpage'  => $products_frontpage,
          'products_status'     => $Qproducts->value('products_status'),
          'products_price'      => $products_price,
          'products_quantity'   => $Qproducts->value('products_quantity')
        );

Replace it with:

$records[] = array(
          'products_id'         => $Qproducts->value('products_id'),
          'products_name'       => $Qproducts->value('products_name'),
        	'products_sku'				=> $Qproducts->value('products_sku'),
          'products_frontpage'  => $products_frontpage,
          'products_status'     => $Qproducts->value('products_status'),
          'products_price'      => $products_price,
          'products_quantity'   => $Qproducts->value('products_quantity'),
		  'variants_groups' => $variants_groups
);

Step 2. Open products_grid.php under admin > includes > extmodules/products fold and then find following code snippet:

{name: 'products_id'},
{name: 'products_name'},
{name: 'products_sku'},
{name: 'products_frontpage'},
{name: 'products_status'},
{name: 'products_price', type: 'string'},
{name: 'products_quantity', type: 'int'},
{name: 'products_status'}

Replace it with:

      {name: 'products_id'},
      {name: 'products_name'},
      {name: 'products_sku'},
      {name: 'products_frontpage'},
      {name: 'products_status'},
      {name: 'products_price', type: 'string'},
      {name: 'products_quantity', type: 'int'},
      {name: 'products_status'},
      {name: 'variants_groups'}

Find following code:

{header: "<?php echo $osC_Language->get('table_heading_quantity'); ?>", dataIndex: 'products_quantity', sortable: true, width: 80, align: 'center'},

Add following code after it:

{header: "<?php echo $osC_Language->get('table_heading_variants'); ?>", dataIndex: 'variants_groups', width: 150, align: 'center'},

That’s it. If you can’t update code by yourself, don’t hesitate to contact me(support@tomatocart.com).

 Looking for quality TomatoCart hosting? Check out Arvixe Web Solutions

Posted under TomatoCart | RSS 2.0

Author Spotlight

Jack Yin

TomatoCart Developer & Co Founder - Arvixe Web Hosting / TomatoCart Community Liaison

2 Comments on [TomatoCart] Show variants in the products grid table

  1. Martin says:

    This works, but if there are two different values ​​from a group of options – shows only one value.
    Quantity: 10 and 20
    Shows; Quantity: 10

    • Jack Yin says:

      Hi,

      You may apply the code incompletely. Please send following information to support@tomatocart.com:

      1. Url address, username and password of your admin panel.

      2. Host, username and password of your ftp account.

      I will arrange time to have a look for you. M

      My skype: tocjack

Leave a Reply

Your email address will not be published. Required fields are marked *