I want to filter my data to csv using the "Manufacturer" field. I tried this, but it didn't work:
<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>
Any thoughts on how to get this to work with filtering on other attributes than the default ones?
Unfortunately, from reading the code it looks like the set of attributes you can filter on is very limited.
$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';
To filter on other attributes requires a minor extension to the class.
/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>
I know this topic is old but this may help someone - works in Magento 1.9. This would be better as a Module but this is a "quick fix". Back up all files before uploading. I needed to add Product ID (from > to) and Manufacturer dropdown field but can easily be adopted for most attribute types.
FOR System > Import/Export > DataProfiles > Export All Products
app/code/core/Mage/Catalog/Model/Convert/Adapter/Product.php
copy to
app/code/local/Mage/Catalog/Model/Convert/Adapter/Product.php
FIND public function load()
Add Attributes to $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';
If type ="fromTo" you need to add an extra filter before return parent::load();
The following is for 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'
));
}
Add the fields to the form
app/design/adminhtml/default/default/template/system/convert/profile/wizard.phtml
Duplicate as a Backup
Find
<div class="profile_entity_type_product">
Add extra Field Sets within this div
The following is for the fromTo for entity id
<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>
The following is for the Manufacturer dropdown
<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>
来源:https://stackoverflow.com/questions/7194756/how-do-i-add-a-filter-on-a-product-attribute-to-magento-advanced-export-profiles