RO CSVI

Override import/export routines

Background information

An override is where you create your own routine and place it in a specific folder for RO CSVI to use. This way you can add or modify the behavior of RO CSVI when importing or exporting to suit your own needs. The system allows for great flexibility so you can write your own override import/export routines and not having to worry that by updating RO CSVI your changes are lost.

Creating an override routine

The default location for import routines is plugins/csviaddon/<component>/com_<component>/model/import and for export routines plugins/csviaddon/<component>/com_<component>/model/export

The problem with having your modification in the CSVI folder is, when you update CSVI your modification is lost. Instead of putting your modification directly in the CSVI folder you can put it in your template folder.

1. Location

The import routine overrides are located in the folder:
plugins/csviaddon/<component>/com_<component>/model/import/

The export routine overrides are located in the folder:
plugins/csviaddon/<component>/com_<component>/model/export/

  • <template>
    This refers to the administrator template e.g. isis
  • <component>
    This refers to the component you are doing the import or export for e.g. com_virtuemart

The default administrator template in Joomla is isis, so the location of the import routines for VirtueMart becomes:
administrator/templates/isis/html/com_csvi/com_virtuemart/model/import/

The default administrator template in Joomla is isis, so the location of the export routines for VirtueMart becomes:
administrator/templates/isis/html/com_csvi/com_virtuemart/model/export/

2. Procedure

To use the override feature take the following steps:

  1. Copy the import routine you want to modify to the override folder e.g. You can copy the plugins/csviaddon/virtuemart/com_virtuemart/model/import/product.php to administrator/templates/isis/html/com_csvi/com_virtuemart/model/import/productcustom.php
  2. Open the file productcustom.php, since the name of the file has been changed from product.php to productcustom.php, it is a must that the class name for productcustom.php to be changed. Look for text "class Product" inside productcustom.php and change it to "class Productcustom" and save the file.
  3. Also, modify the productcustom.php file according to your needs.
  4. Set the override file in the template by going to template settings and click on Advanced button. A new dropdown Override will appear under Operations. Select the override file you just created and save the template.
  5. Perform the import.

You can follow the same steps for export by changing the folder import to export.

RO CSVI 8 changes

If you created your own export override, you will need to adjust any custom exports you have created that make use of the Group By and Sort By options.

In the old situation the code looks like this:


// Group by fields
$groupbyfields = json_decode($this->template->get('groupbyfields', '', 'string'));
$groupBy       = array();

if (isset($groupbyfields->name))
{
	$groupByFields = array_flip($groupbyfields->name);
}
else
{
	$groupByFields = array();
}

// Sort selected fields
$sortfields = json_decode($this->template->get('sortfields', '', 'string'));
$sortBy = array();

if (isset($sortfields->name))
{
	$sortByFields = array_flip($sortfields->name);
}
else
{
	$sortByFields = array();
}

 

In the new situation the code needs to look like this:


// Group by fields
$groupFields   = $this->template->get('groupbyfields', [], 'array');
$groupBy       = array();
$groupByFields = [];

if (!empty($groupFields))
{
	foreach ($groupFields as $groupField)
	{
		$groupByFields[$groupField->name] = $groupField->name;
	}
}

// Sort selected fields
$sortFields   = $this->template->get('sortfields', [], 'array');
$sortBy = array();
$sortByFields = [];

if (!empty($sortFields))
{
	foreach ($sortFields as $sortName)
	{
		$sortByFields[$sortName->name] = $sortName->sortby;
	}
}