Exporting Magento Advanced Profiles - Prepare IMAGE Path URL

In just a couple of weeks, Magento managed to get extended export profiles (Very Handy), what I would like to do is provide a url value for one of the output columns, in particular the image URL. I would like to add a URL at the beginning of the output path.

Can anyone help?

<action type="catalog/convert_adapter_product" method="load"> <var name="store"><![CDATA[0]]></var> <var name="filter/price/from"><![CDATA[0.01]]></var> <var name="filter/price/to"><![CDATA[999999]]></var> <var name="filter/visibility"><![CDATA[4]]></var> <var name="filter/status"><![CDATA[1]]></var> </action> <action type="catalog/convert_parser_product" method="unparse"> <var name="store"><![CDATA[0]]></var> <var name="url_field"><![CDATA[0]]></var> </action> <action type="dataflow/convert_mapper_column" method="map"> <var name="map"> <map name="name"><![CDATA[ItemTitle]]></map> <map name="upc"><![CDATA[EANBarCode]]></map> <map name="description"><![CDATA[ItemTextDescription]]></map> <map name="sku"><![CDATA[SKU]]></map> <map name="qty"><![CDATA[StockLevel]]></map> <map name="price"><![CDATA[CostPrice]]></map> <map name="manufacturer"><![CDATA[Brand]]></map> <map name="ebaycategory1"><![CDATA[eBayCategory1]]></map> <map name="ebaycategory2"><![CDATA[eBayCategory2]]></map> <map name="image"><![CDATA[Image1]]></map> <map name="description"><![CDATA[ListingDescription]]></map> <map name="name"><![CDATA[ListingTitle]]></map> <map name="msrp"><![CDATA[OriginalRetailPrice]]></map> <map name="conditionnote"><![CDATA[SellerNotes]]></map> </var> <var name="_only_specified">true</var> </action> <action type="dataflow/convert_parser_csv" method="unparse"> <var name="delimiter"><![CDATA[,]]></var> <var name="enclose"><![CDATA["]]></var> <var name="fieldnames">true</var> </action> <action type="dataflow/convert_adapter_io" method="save"> <var name="type">file</var> <var name="path">var/export</var> <var name="filename"><![CDATA[testing123.csv]]></var> </action> 
+6
source share
4 answers

In the Mage_Dataflow_Model_Convert_Mapper_Column class, which looks at the methods map, you only have 2 vars right now: map and _only_specified. What you need to do is override this class and this method and add something like this on line 125 after installing var:

 if ($this->getVar('prepend') && is_array($this->getVar('prepend'))) { $prepend = $this->getVar('prepend'); } else { $prepend = array(); } 

Now you have a new prepend variable that you can use for package data, for example: line 138 in the same class as you:

 $newRow = array(); foreach ($attributesToSelect as $field => $mapField) { $newRow[$mapField] = isset($row[$field]) ? $row[$field] : null; } 

Change this to:

 $newRow = array(); foreach ($attributesToSelect as $field => $mapField) { $prepend = isset($prepend[$field]) ? $prepend[$field] : ''; $newRow[$mapField] = isset($row[$field]) ? $prepend . $row[$field] : null; } 

Now in your xml, which you posted above, you can add the preend variable as follows:

 <action type="dataflow/convert_mapper_column" method="map"> <var name="prepend"> <map name="image"><![CDATA[http://example.com/]]></map> 

I did not test it, but as if I tried it in the first place. Also, no part has been added on how you can override this model class, since I think there are many examples.

+2
source

I just registered, so I can not comment on Amy's answer. I want to thank him because he is right, but there is one small piece of code that you must change too. Here is my short decision.

I also made a more detailed blog entry on my personal blog: https://www.timoschindler.de/vollstaendige-urls-in-dataflow-exportierten-csv-dateien-von-magento/ Unfortunately, this is in German;) . If you have any problems, just let me know and I can translate it.

First I added the file app / code / local / Mage / Dataflow / Model / Convert / Mapper / MyColumn.php

 <?php class Mage_Dataflow_Model_Convert_Mapper_MyColumn extends Mage_Dataflow_Model_Convert_Mapper_Column { public function map() { $batchModel = $this->getBatchModel(); $batchExport = $this->getBatchExportModel(); $batchExportIds = $batchExport ->setBatchId($this->getBatchModel()->getId()) ->getIdCollection(); $onlySpecified = (bool)$this->getVar('_only_specified') === true; if (!$onlySpecified) { foreach ($batchExportIds as $batchExportId) { $batchExport->load($batchExportId); $batchModel->parseFieldList($batchExport->getBatchData()); } return $this; } if ($this->getVar('map') && is_array($this->getVar('map'))) { $attributesToSelect = $this->getVar('map'); } else { $attributesToSelect = array(); } if ($this->getVar('prepend') && is_array($this->getVar('prepend'))) { $prepend = $this->getVar('prepend'); } else { $prepend = array(); } if (!$attributesToSelect) { $this->getBatchExportModel() ->setBatchId($this->getBatchModel()->getId()) ->deleteCollection(); throw new Exception(Mage::helper('dataflow')->__('Error in field mapping: field list for mapping is not defined.')); } foreach ($batchExportIds as $batchExportId) { $batchExport = $this->getBatchExportModel()->load($batchExportId); $row = $batchExport->getBatchData(); $newRow = array(); foreach ($attributesToSelect as $field => $mapField) { $prepend_2 = isset($prepend[$field]) ? $prepend[$field] : ''; $newRow[$mapField] = isset($row[$field]) ? $prepend_2 . $row[$field] : null; } $batchExport->setBatchData($newRow) ->setStatus(2) ->save(); $this->getBatchModel()->parseFieldList($batchExport->getBatchData()); } return $this; } } 

then I copied the application / code / kernel /Mage/Dataflow/Model/Convert/Profile/Collection.php to app / code / local / Mage / Dataflow / Model / Convert / Profile / Collection.php and changed it. if in code:

 /** @var $varNode Varien_Simplexml_Element */ foreach ($actionNode->var as $key => $varNode) { if ($varNode['name'] == 'map') { $mapData = array(); foreach ($varNode->map as $mapNode) { $mapData[(string)$mapNode['name']] = (string)$mapNode; } $container->setVar((string)$varNode['name'], $mapData); } else { 

That's all! Now a simple XML data stream looks like this:

 <action type="dataflow/convert_mapper_myColumn" method="map"> <var name="map"> <map name="sku"><![CDATA[Artikelnummer]]></map> <map name="name"><![CDATA[Artikelbezeichnung]]></map> <map name="image"><![CDATA[image]]></map> </var> <var name="prepend"> <map name="image"><![CDATA[https://www.bier-kaufen.de/media/catalog/product]]></map> </var> <var name="_only_specified">true</var> </action> 
+1
source

I developed a simple module to solve the problem. Just install it and add / add whatever you want. Here is the link http://bkielbasa.pl/magento-advanced-profiles-export-prepend-url-image-path/

It does not edit core files.

0
source

If someone wants this option, I took the kabanek solution and expanded it to add a constant column variation. Thus, we can export information directly to a template that needs fields not in the database.

In Convert.php changed

 if ($varNode['name'] == 'map' || $varNode['name'] == 'prepend' || $varNode['name'] == 'append' ) { 

to

 if ($varNode['name'] == 'map' || $varNode['name'] == 'prepend' || $varNode['name'] == 'append' || $varNode['name'] == 'const') { 

Then in Column.php added:

 if ($this->getVar('const') && is_array($this->getVar('const'))) { $constCol = $this->getVar('const'); } else { $constCol = array(); } 

and changed:

 $newRow[$mapField] = isset($row[$field]) ? ($prependText . $row[$field] . $appendText) : null; 

to

 $constText = isset($constCol[$field]) ? $constCol[$field] : null; $newRow[$mapField] = isset($row[$field]) ? ($prependText . $row[$field] . $appendText) : $constText; 
0
source

All Articles