Pimcore "Import Definition" how to relocate object to relevant folder - pimcore

I have use “Import Definition” bundle to import csv and to create data-objects. (https://github.com/w-vision/ImportDefinitions)
Now I need to put imported data-Object to relevant folders. I need to do it automatically.
eg -
Import first row of the CSV
Check the CSV first row "Category" column value
According to column value need to move into relevant folder.
Setting object path "/products/%Text(mycolumn1);/%Text(mycolumn2);" is not solution to my requirement.
My csv it’s comes with category code not full name.
I need to do some mapping.
eg:-
csv column category value is - OFH
my data-object folder name is Office & Furniture Hardware
I need to match those two and place into correct folder.
What is the best way to do this with “Import Definitions”?
if best way is "interpreter" please let me know how to do it?
Thanks.

There is no much document about Pimcore but I have solve my issue using custom Interpreter.
Here is my solution -
Fist install Import Definition -
https://github.com/w-vision/ImportDefinitions
(it'll install into - /var/www/html/example2.loc/vendor/w-vision/import-definitions/src/ImportDefinitionsBundle/)
composer require w-vision/import-definitions:^2.0-dev
bin/console pimcore:bundle:enable ImportDefinitionsBundle
bin/console pimcore:bundle:install ImportDefinitionsBundle
Add new custom Interpreter
Add "categorymap.js" to
/var/www/html/example2.loc/vendor/w-vision/import-definitions/src/ImportDefinitionsBundle/Resources/public/pimcore/js/interpreters/categorymap.js
Add "CategoryMap.php" to
/var/www/html/example2.loc/vendor/w-vision/import-definitions/src/ImportDefinitionsBundle/Interpreter/CategoryMap.php
Add "CategoryMapInterpreterType.php" to
/var/www/html/example2.loc/vendor/w-vision/import-definitions/src/ImportDefinitionsBundle/Form/Type/Interpreter/CategoryMapInterpreterType.php
Update Service.yml in -
/var/www/html/example2.loc/vendor/w-vision/import-definitions/src/ImportDefinitionsBundle/Resources/config/services.yml
adding Following -
import_definition.interpreter.category_map:
class: ImportDefinitionsBundle\Interpreter\CategoryMap
tags:
- { name: import_definition.interpreter, type: category_map, form-type: ImportDefinitionsBundle\Form\Type\Interpreter\CategoryMapInterpreterType }
Update config.yml in -
adding follwing -
interpreter_categorymap: '/bundles/importdefinitions/pimcore/js/interpreters/categorymap.js'
To csv upload run following CLI command -
bin/console import-definitions:import -d 1 -p "{\"file\":\"sap_export1.csv\"}"

Related

Python - working with unkown directory name versions

I'm using python to download an application from a content distribution network. The application downloads as self extract file cabinet. When executed it creates a directory using a version naming format. For example app-version2/../app.exe, Thus I cannot rely on the folder name as it may change in the future. I'm trying to find the best way to work with the content inside the folder without depending on the actual folder name.
My idea was to rename the folder using os.listdir() and then os.rename(app-version2, myapp) This would work but is not automated. What would be the best automated method to find a folder name that contains version numbers and change that to something more static?
Assuming you want to find the path of the directory which begins with app, you can accomplish this using pathlib.Path:
from pathlib import Path
app_path = next(Path().glob('app*'))
This will give you the path to the first file or directory in your current directory whose name begins with "app".

Invoice2Data template not found

I am currently trying to parse some invoice data and came across this package on PyPi. It seems to be very handy for this task. There is one problem I can't run it due to 'no template found for ' error. From the documentation [https://pypi.org/project/invoice2data/0.2.31/#description]
it becomes clear that you need to specify a template and then run the following command: invoice2data <invoice_file>.pdf. To specify a template you need to run the command invoice2data --template-folder <yourfolder>.
When executing these commands in my wsl (Linux virtual machine, needed to run package) it keeps complaining. My invoice files are in the map 'tpl' (2 custom yml files), and the invoice file is called invoice.pdf see screenshots. I have attached the invoices too for clearity, please not these are all testfiles. My aim is to first make sure invoice2data operates, and then make my own custom YML template conforming the tutorial.
Somehow invoice2data does not get, it needs to assign a template ( I really don't care about which template at this stage) to execute the parsing. I have looked everywhere on google, there are topics on these, but none offer me a solution. I hope somebody can help me out. Much appreciated, tnx a lot in advance
Jeffrey
1. files and directories
2. YML template files
3. Command line execution gives error
4a. invoice sample 1
4b. invoice sample 2

Python cx_freeze Create dirs for included files in build

Is it possible to create dirs(folders) on cx_freeze build output, cause i include(include_files) many databases files and i want these to be in specific folder etc. I can take them easily from my folders.....
"include_files": ["databases/nations.txt","databases/newafrica.txt",
"databases/neweeurope.txt","databases/neweurope.txt","databases/newmeast.txt","graph.py",
"databases/newnamerica.txt","databases/plates.txt",
"databases/ACN/rigidA.txt","databases/ACN/rigidB.txt",
"databases/ACN/rigidC.txt","databases/ACN/rigidD.txt","databases/ACN/flexibleA.txt",
"databases/ACN/flexibleB.txt","databases/ACN/flexibleC.txt",
"databases/ACN/flexibleD.txt","alternates.xlsx",
but this will just copy all of them in exe build dir and its a mess.
Thanks in advance.
There are several ways you can go around solving the problem.
Method 1 - Using include_files
Rather than ask for each individual text file you could just put the file name in the setup script and leave out the individual text files. In your case it would be like this:
"include_files": ["databases"]
This would copy the entire databases folder with everything in it into you build folder.
Absolute file paths work as well.
If you are going to use the installer feature (bdist_msi) this is the method to use.
You can copy sub folders only using "include_files": ["databases/ACN"]
Method 2 - Manually
Ok it's rather un-pythonic but the one way to do it is to copy it manually into the build folder.
Method 3 - Using the os module
Much the same as method two it would copy the folder into your build folder but instead of coping it manually it would use Python. You also have the option of using additional Python features as well.
Hope I was helpful.

Bcp must be installed error when loading Adventureworks Azure datawarehouse

I'm trying to test the Azure Data Warehouse. I successfully created and connected to the database, but I've run into a snag as I attempt to load the tables. I'm trying to execute the following instructions:
To install AdventureWorksSQLDW2012:
-----------------------------------
4. Extract files from AdventureWorksSQLDW2012.zip file into a directory.
5. Edit aw_create.bat setting the following variables:
a. server=<servername> from step 1. e.g. mylogicalserver.database.windows.net
b. user=<username> from step 1 or another user with proper permissions
c. password=<passwordname> for user in step 5b
d. database=<database> created in step 1
e. schema=<schema> this schema will be created if it does not yet exist
6. Run aw_create.bat from a cmd prompt, running from the directory where the files were unzipped to.
This script will...
a. Drop any Adventure Works tables or views that already exist in the schema
b. Create the Adventure Works tables and views in the schema specified
c. Load each table using bcp
d. Validate the row counts for each table
e. Collect statistics on every column for each table
I completed the prerequisites of installing bcp and sqlcmd and used the -? command to confirm the installations.
Unfortunately, when I try to complete step 6 above I get the following error:
REM AdventureWorksSQLDW2012 sample database version 3.0 for DW Service Tue 06/27/2017 20:31:01.99 Bcp must be installed.
Has anyone else come across this error or can anyone suggest a potential solution.
UPDATE: I've also copied the path where BCP is located to my path environment variables. Still no luck.
The aw_create.bat contains a line where you need to provide the path of the bcp program. Once provided ans save the script worked like a charm.

Using a Twig Extension

I am trying to use teh Twig i18n Extension.
As far as I can tell the file I need is here:
https://github.com/fabpot/Twig-extensions/blob/master/lib/Twig/Extensions/Extension/I18n.php
Now I am not quite sure where to save this file
I have Twig in a folder called includes/lib (/includes/lib/Twig). I see a folder Extension under Twig. Do I save it here?
After I save it, do I need to do a "require_once" to the file or will Twig_Autoloader do the job for me?
I am not using Symfony2
Thanks
Craig
Here is the complete answer that worked for me:
Copy the file in Twig-Verzeichnis (extract i18n.zip in Twig).
For the I18n extension it would be Twig/Extensions/Extension/I18n.php
Eventually add other files requred by I18n. You will see what these are by the error messages that come. I had to add "Twig/Extensions/Node/Trans.php" and "Twig/Extensions/TokenParser/Trans.php".
In your config file add the following:
// Set language to German
putenv('LC_ALL=de_DE');
setlocale(LC_ALL, 'de_DE');
// Specify location of translation tables
bindtextdomain("project_de_DE", "./locale");
// Choose domain
textdomain("projectl_de_DE");
Register the Twig Extension
$twig->addExtension(new Twig_Extensions_Extension_I18n());
Create the directory locale/de_DE/LC_MESSAGES
Create the PO file (the easisest is to have a sample file to start from)
Open the file in a normal text editor (be sure to use utf-8 encoding) and start translating
Open the PO-Datei with PoEdit (www.poedit.net/)
Save to locale/de_DE/LC_MESSAGES (a MO-Datei will be created).
Add the translation to the appropriate places in the Twig-Template with
{% trans 'Text in the original language' %}`
You need to register this extension with Twig:
$twig->addExtension(new Twig_Extensions_Extension_I18n());
If your installation is configured correctly, the autoloader should do the job of including the file. If not, you could include the file manually or make the installation with composer.
It seems the "proper" way to install these extensions without Composer is as follows:
Download a release from https://github.com/fabpot/Twig-extensions/releases
Copy the contents of the lib/ directory somewhere to your project
include the file .../Twig/Extensions/Autoloader.php
Register autoloader: Twig_Extensions_Autoloader::register();
Continue as explained in the doc: http://twig.sensiolabs.org/doc/extensions/i18n.html

Resources