2

I use the import/export functionality in order to import products each night. I additionally use AvS_FastSimpleImport, but this should not really matter. Many of my products have custom options. In the data I import, I set something like this in order to import the custom option:

'_custom_option_title'       => 'My super funky option title',
'_custom_option_type'        => Mage_Catalog_Model_Product_Option::OPTION_TYPE_CHECKBOX,
'_custom_option_is_required' => false,
'_custom_option_row_title'   => 'My super funky option row title',
'_custom_option_row_price'   => 50,
'_custom_option_row_sku'     => 'MY_SKU'

The problem is that the custom option is not updated, but always added again. Hence, I have the same custom option multiple times.

I tried to set a _custom_option_sku and hoped that this would work, but the SKU is ignored completely (source).

Another alternative would be to completely replace all products and not update them (Mage_ImportExport_Model_Import::BEHAVIOR_REPLACE instead of Mage_ImportExport_Model_Import::BEHAVIOR_APPEND), but I would rather like to avoid this.

So any idea how an existing custom option can be updated with the ImportExport module?

2 Answers 2

2

The simple answer: use Replace. Or do a separated, not import/export based, deletion process. The real problem is, that those custom options are more complex relations than simple Attributes. It is the same with upsell/crosssell/related products. Either do a Replace or do a manual handled deletion, because the import cannot decide which of these relations it should "update" becuase there is no unique identifier for them. Another example is category<>product relations there is no "before<>after" stuff in there to tell the importer which one to update.

1

Thanks @Nils for clarifying. The missing unique identifier is a good point. In theory, custom options have a SKU (stored in the DB table catalog_product_option) which could be used as an identifier. Anyway, this SKU field is not used at all - only the SKU field of the option values (stored in the DB table catalog_product_option_type_value) is used. I decided to use a custom deletion process, which is quite straightforward: I listen to the event fastsimpleimport_import_products_before and delete all custom options in there.

In your config.xml:

<global>
    <events>
        <fastsimpleimport_import_products_before>
            <observers>
                <namespace_module>
                    <class>namespace_module/observer</class>
                    <method>fastsimpleimportImportProductsBefore</method>
                </namespace_module>
            </observers>
        </fastsimpleimport_import_products_before>
    </events>
</global>

In your app/code/local/Namespace/Module/Model/Observer.php:

<?php

class Namespace_Module_Model_Observer
{

    /**
     * @param Varien_Event_Observer $observer
     */
    public function fastsimpleimportImportProductsBefore(Varien_Event_Observer $observer)
    {
        // remove all existing custom options
        Mage::getModel('catalog/product_option')->getCollection()->walk('delete');
    }

}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.