How do I add a filter on a product attribute to Magento Advanced Export Profiles?

☆樱花仙子☆ 提交于 2019-12-03 20:59:11

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>

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!