Magento高级配置文件导出 - 将URL添加到IMAGE路径

时间:2014-02-14 20:57:29

标签: magento export-to-csv

进入Magento只需几周,设法使用高级导出配置文件(非常方便),我想要做的是将url值添加到其中一个输出列,特别是图像URL。我想将url追加到路径输出的开头。

有人可以帮忙吗?

<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>

4 个答案:

答案 0 :(得分:2)

在查看方法地图的类Mage_Dataflow_Model_Convert_Mapper_Column中,您现在只有2个变量:map和_only_specified。 您需要做的是覆盖此类和此方法,并在设置var之后在第125行添加类似的内容:

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

现在你有了一个新的变量prepend,可以用于这样的批处理数据 - 在同一个类的第138行:

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

将其更改为:

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

现在,您在上面发布的xml中,可以添加这样的前置变量:

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

我没有测试过这个,但这就是我先试试的方法。还没有添加关于如何覆盖这个模型类的部分,因为我认为那里有很多例子。

答案 1 :(得分:2)

我刚注册,所以我不能对Emi的答案发表评论。我要感谢他,因为他是对的,但是你必须改变一小部分代码。这是我的解决方案。

我还在我的私人博客中制作了更详细的博客文章:https://www.timoschindler.de/vollstaendige-urls-in-dataflow-exportierten-csv-dateien-von-magento/不幸的是,它是德语;)。如果您有任何问题,请告诉我,我可以翻译它。

首先我添加了文件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;
}
}

然后我将app / code / core / Mage / Dataflow / Model / Convert / Profile / Collection.php复制到app / code / local / Mage / Dataflow / Model / Convert / Profile / Collection.php并更改了一个代码:

/** @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 {

多数民众赞成!一个简单的Dataflow XML现在看起来像:

<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>

答案 2 :(得分:0)

我开发了一个简单的模块来解决这个问题。只需安装它,然后追加/添加你想要的任何东西。这是链接http://bkielbasa.pl/magento-advanced-profiles-export-prepend-url-image-path/

它不会编辑任何核心文件。

答案 3 :(得分:0)

如果有人想要这种变化,我会采用kabanek的解决方案并将其扩展为添加恒定的列变体。这样我们就可以将信息直接导出到需要不在数据库中的字段的模板中。

在Convert.php中更改了

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

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

然后在Column.php中添加:

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

并改变了:

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

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