RO CSVI
Replacement: change text case
| RO CSVI
To add change the case of text you can use the Replacement feature of CSVI VirtueMart.
Since version 2.3.13.
Lowercase
Let's say you want to lowercase your product description field, here is how:
- Go to Replacement
- Make a new entry with the following settings
- Find: /(.*)/e
- Replace: strtolower('\1')
- Type: Regular expression
- Template: Select the template you use for the export
- Field: Select the field the replacement is to be used for
- Click on the Add icon
- Do an export of your template
Uppercase
Let's say you want to uppercase your product description field, here is how:
- Go to Replacement
- Make a new entry with the following settings
- Find: /(.*)/e
- Replace: strtoupper('\1')
- Type: Regular expression
- Template: Select the template you use for the export
- Field: Select the field the replacement is to be used for
- Click on the Add icon
- Do an export of your template
The magic
The magic here is the e modifier. In the Find field you put /(.*)/e, the e here is the e modifier. This allows you to use a PHP function to do something to the text found. The PHP functions used here are:
- strtolower -> lowercase the text found
- strtoupper -> uppercase the text found
Other PHP functions can be used, e.g.:
- str_ireplace -> replace some string
str_ireplace('a', 'aa', '\1') -> change all a to aa in the text found - substr -> take part of the string
substr('\1', 0, 5) -> take only the first 5 letters of the text found - see the PHP function reference for other functions
Replacement: Append text
| RO CSVI
To add some custom text to the end of a field you can use the Replacement feature of CSVI VirtueMart.
Let's say you want to add FREE POSTAGE to your product description field, here is how:
- Go to Replacement
- Make a new entry with the following settings
- New Old value: /$/
- New New value: FREE POSTAGE
- Type: Regular expression
- Template: Select the template you use for the export
- Field: Select the field the replacement is to be used for
- Click on the Add icon
- Do an export of your template
Replacements
| RO CSVI
Requirements
- CSVI Pro 6.0+
- Joomla 3.4.3+
- PHP 5.4
Background information
The replacement feature can be used to change data during export or before import.
Types of replacements
There are 2 types of replacements that can be done:
- Regular text
- Regular expressions
Regular text
A regular text replacement is a simple replacement where value x gets replaced with value y. For example replace NL with Netherlands. Any text found to match NL is being replaced with Netherlands.
Regular expressions
A regular expression replacement is a more advanced replacement using regular expressions. For example you can add extra text to the end of a field.
Creating replacement rules
From Components -> CSVI pro ->Templates tab -> Rules, Click New to add a new rule using replace plugin.
For example to create a rule to replacing text "NL" to "Netherlands" in virtuemart product description.
- Give a descriptive name for the rule in name field
- Select Action as Import
- Select Plugin as CSVI Replace
- Click on load plugin button
Find
Give here the text that CSVI needs to look for. When doing:
- A regular text replacement the text here is just plain text for example NL.
- A regular expression replacement the text here needs to be enclosed in forward slashes for example /NL/
It is possible to look for and replace multiple values in 1 replacement rule. Multiple values must be separated by a pipe symbol. When doing:
- A regular text replacement the text is only separated by a pipe symbol for example NL|DE|US
- A regular expression replacement each text is enclosed in forward slashes for example /NL/|/DE/|/US/
Replace
Give here the text CSVI needs to use for replacement for example Netherlands. Multiple values must be separated by a pipe symbol for example Netherlands|Germany|United States.
Multiple values
If your find and replace contains multiple values to look for, set this to Yes so all values will be searched for and replaced independently.
Method
Specify here if CSVI should do a regular text or a regular expression replacement
Examples
Add text at beginning of a value
This example adds the text Before to the value found
Find: /^/
Replace: Before
Method: Regular expression
Add text at the end of a value
This example adds the text After to the value found
Find: /$/
Replace: After
Method: Regular expression
Change text to lowercase
This changes the value to lowercase
Find: /(.*)/e
Replace: strtolower('\1')
Method: Regular expression
This will not work with PHP 7 and higher. CSVI 6.7.0 will have a new rule plugin that makes this possible.
Change text to uppercase
This changes the value to uppercase
Find: /(.*)/e
Replace: strtoupper('\1')
Method: Regular expression
This will not work with PHP 7 and higher. CSVI 7.0 will have a new rule plugin that makes this possible.
Change first letter to uppercase
This changes the first letter of the value to uppercase, if that letter is alphabetic
Find: /(.*)/e
Replace: ucfirst('\1')
Method: Regular expression
This will not work with PHP 7 and higher. CSVI 7.0 will have a new rule plugin that makes this possible.
Replace text
This replaces all occurences of a with aa in the value
Find: /(.*)/e
Replace: str_ireplace('a', 'aa', '\1')
Method: Regular expression
This will not work with PHP 7 and higher. CSVI 7.0 will have a new rule plugin that makes this possible.
Take part of the value
This takes the first 5 characters of the value
Find: /(.*)/e
Replace: substr('\1', 0, 5)
Method: Regular expression
This will not work with PHP 7 and higher. CSVI 7.0 will have a new rule plugin that makes this possible.
Excel and CSV
| RO CSVI
The flexibility of Excel with CSV files is quite limited, so limited even that you cannot use your own field delimiter, text enclosure and encoding when opening a CSV file.
Custom fields import and export
| RO CSVI
Requirements
- CSVI 6.0+
- Joomla 3.0+
- VirtueMart 3.0 or higher
- PHP 5.4
Background information
To import/export custom fields CSVI uses the Custom field import and Custom field export operations. These operations are available after choosing Import or Export -> VirtueMart under Options.
Required fields
The custom fields import requires the following fields:
- plugin_name
- custom_element
- custom_title
- custom_value
- field_type
Optional but recommended fields
- custom_field_desc
An example CSV file looks like this:
"plugin_name";"custom_element";"custom_title";"custom_value";"field_type"
"Customer text input";"textinput";"CSVI Import";"Type here";"E"
Let's have a closer look at the fields.
plugin_name
This field contains the name of the plugin that is used for the custom field. A list of supported plugins can be found in the Plug-in Manager: Plug-ins section. The Plug-in Name you see here is what needs to be put in the plugin_name field.
custom_element
This is a bit of an odd one. The custom_element you can find in the field called Default when you save the custom field when the Field Type is set to Plugins. When using another field type, this field is left empty.
custom_title
The name of the custom field.
custom_value
This is the same value as custom_element when importing a plugin field type. In any other case this is a text shown to the shopper.
field_type
This must be one of the following values, depending on the type of custom field you are importing:
- S: String
- I: Integer
- P: Parent
- B: Boolean
- D: Date
- T: Time
- M: Image
- V: Cart variant
- E: Plugins
custom_field_desc
A description of the custom field.
Once you have created the CSV file with the necessary data it can be imported like any other import.