如何将产品属性的过滤器添加到Magento Advanced Export Profiles?

时间:2011-08-25 17:38:32

标签: magento magento-1.4

我想使用“制造商”字段将我的数据过滤到csv。我试过这个,但它不起作用:

<action type="catalog/convert_adapter_product" method="load">
    <var name="store"><![CDATA[0]]></var>
    <var name="filter/manufacturer"><![CDATA[898]]></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="sku"><![CDATA[sku]]></map>
        <map name="name"><![CDATA[name]]></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[safety-gates-export.csv]]></var>
</action>

有关如何使用过滤除默认属性之外的其他属性的任何想法?

2 个答案:

答案 0 :(得分:4)

不幸的是,通过阅读代码,您可以过滤的属性集非常有限。

$attrFilterArray = array();
$attrFilterArray ['name']           = 'like';
$attrFilterArray ['sku']            = 'startsWith';
$attrFilterArray ['type']           = 'eq';
$attrFilterArray ['attribute_set']  = 'eq';
$attrFilterArray ['visibility']     = 'eq';
$attrFilterArray ['status']         = 'eq';
$attrFilterArray ['price']          = 'fromTo';
$attrFilterArray ['qty']            = 'fromTo';
$attrFilterArray ['store_id']       = 'eq';

要过滤其他属性,需要对该类进行较小的扩展。

<强> /app/code/local/YourCompany/YourModule/Model/DataFlow/Catalog/Product/Adapter.php

<?php
class YourCompany_YourModule_Model_DataFlow_Catalog_Product_Adapter 
extends Mage_Catalog_Model_Convert_Adapter_Product
{

    /**
     * Extend the parent method to add filtering capability for additional fields
     *
     * This is required since the parent load() uses a parent::setFilter instead of $this->setFilter
     *
     * @return Mage_Dataflow_Model_Convert_Adapter_Interface
     */
    public function load()
    {
        // Add any additional attributes you want to filter on here
        $attrFilterArray = array(
            'manufacturer' => 'eq',
        );

        $this->setFilter($attrFilterArray, array());

        return parent::load();
    }

}

<强> /app/code/local/YourCompany/YourModule/etc/config.xml

<?xml version="1.0"?>
<config>
    <modules>
        <YourCompany_YourModule>
            <version>0.0.1</version>
        </YourCompany_YourModule>
    </modules>
    <global>
        <models>
            <catalog>
                <rewrite>
                    <convert_adapter_product>YourCompany_YourModule_Model_DataFlow_Catalog_Product_Adapter</convert_adapter_product>
                </rewrite>
            </catalog>
        </models>
    </global>
</config>

答案 1 :(得分:0)

我知道这个话题很老但是这可能有助于某人 - 在Magento 1.9中工作。这可以作为一个模块更好,但这是一个“快速解决方案”。在上传之前备份所有文件。我需要添加产品ID(来自&gt;到)和制造商下拉字段,但很容易被大多数属性类型采用。

FOR System&gt;导入/导出&gt; DataProfiles&gt;导出所有产品

应用程序/代码/核心/法师/目录/型号/转换/适配器/ Product.php
复制到
应用程序/代码/ 本地 /Mage/Catalog/Model/Convert/Adapter/Product.php

查找公共功能负载()
将属性添加到$ attrFilterArray = array();

$attrFilterArray = array();
$attrFilterArray ['name']           = 'like';
$attrFilterArray ['entity_id']      = 'fromTo'; //Custom Field
$attrFilterArray ['manufacturer']   = 'eq';     //Custom Field
$attrFilterArray ['sku']            = 'startsWith';
$attrFilterArray ['type']           = 'eq';
$attrFilterArray ['attribute_set']  = 'eq';
$attrFilterArray ['visibility']     = 'eq';
$attrFilterArray ['status']         = 'eq';
$attrFilterArray ['price']          = 'fromTo';
$attrFilterArray ['qty']            = 'fromTo';
$attrFilterArray ['store_id']       = 'eq';

如果type =“ fromTo ”,您需要在返回parent :: load(); 之前添加额外的过滤器 以下是entity_id

if ($productId = $this->getFieldValue($filters, 'entity_id')) {
    $this->_filter[] = array(
    'attribute' => 'entity_id',
    'from'      => $productId['from'],
    'to'        => $productId['to']
    );  

    $this->setJoinAttr(array(
    'alias'     => 'entity_id',
    'attribute' => 'catalog_product/entity_id',
    'bind'      => 'entity_id',
    'joinType'  => 'LEFT'
    ));
}

将字段添加到表单

应用程序/设计/ adminhtml /默认/默认/模板/系统/转换/简档/ wizard.phtml
重复备份

<强>查找

<div class="profile_entity_type_product">

在此div中添加额外的字段集

以下内容适用于实体ID

fromTo
<span class="field-row">
    <label for="product_filter_entity_id_from"><?php echo $this->__("Product ID:") ?></label>
    <input class="input-text" style="width:5em" id="product_filter_entity_id_from" name="gui_data[product][filter][entity_id][from]" value="<?php echo $this->getValue('gui_data/product/filter/entity_id/from') ?>"/> <?php echo $this->__('to') ?>
    <input class="input-text" style="width:5em" id="product_filter_entity_id_to" name="gui_data[product][filter][entity_id][to]" value="<?php echo $this->getValue('gui_data/product/filter/entity_id/to') ?>"/>
</span>

以下是制造商下拉列表

<span class="field-row">
<label for="product_filter_manufacturer"><?php echo $this->__("Manufacturer Name:") ?></label><select id="product_filter_manufacturer" name="gui_data[product][filter][manufacturer]">
    <?php $manufacturer = Mage::getSingleton('eav/config')->getAttribute('catalog_product','manufacturer')->getSource()->getAllOptions(); ?>
    <?php foreach ($manufacturer as $option): ?>
        <option value="<?php echo $option['value'] ?>" <?php echo $this->getSelected('gui_data/product/filter/manufacturer', $option['value']) ?>><?php echo htmlspecialchars($option['label']) ?></option>
    <?php endforeach ?>
</select>