10 September 2013

Magento dataflow batch exports and parent SKUs of configurable products

At work, I've been scratching my head how to easily batch export and import Magento products. Importing is covered pretty well by <a href="http://sourceforge.net/apps/mediawiki/magmi/index.php?title=Magmi_Wiki">Magmi</a>, but the exports are a bit lacking. Found an extension to add extra abilities to the Dataflow export, including category exports, in here - http://www.magentocommerce.com/boards/viewthread/60113/ - but the one thing I wanted was to be able to export the parent SKUs of complex products, as Magmi can handle them in their own field (simple_skus). However, I then realised I'd done it completely the wrong way around, and I actually needed child products. So I've extended the extension, and thrown it up on GitHub, hopefully it'll save someone else the hassle for either purpose. Seems to work well, but let me know if there's any issues, I'll see what I can do to help.

Usage is the same as the original extension, with the addition of a few options at the bottom:

<action method="unparse" type="exportextension/modifier">
    <var name="remove_line_breaks">true</var>
    <var name="remove_html_tags">true</var>
    <var name="add_categories">true</var>
    <var name="category_field_name">category</var>
    <var name="category_delimiter">#</var>
    <var name="category_first_level">-1</var>
    <var name="category_path_delimiter"><![CDATA[>]]></var>
    <var name="add_absolute_url_to_field">product_url</var>
    <var name="add_image_url_to_field">image_url</var>
    <var name="add_parent_sku">parent_sku</var>
    <var name="add_child_sku">child_skus</var>
    <var name="child_sku_delimiter">,</var>
</action>

remove_line_breaks: if the value of this tag is “true”, linebreaks will be removed from the content 
remove_html_tags: if the value of this tag is “true”, html tags will be removed from the content 
- add_categories: if the value of this tag is “true”, each product will be extended with category names. 
The following tags, are only used, if “add_categories” is “true”. They configure the additional category field: 
category_field_name: this value defines the used name of the category field. The default value of this tag is “category”. This tag is only expedient, if you export the fieldnames aor if you allready have another field with the defaultname “category”. 
category_delimiter: if a product is at more than one categories, each category will added and they will be delimited by this string. The default value is “#”. 
category_first_level: this value defines the level of the first exportable category. If it is 2 or greater, the first category names of the category tree won’t be added to the data. The values 1 and 0 are the same, because there is no level 0 - the root category has level 1. If the value is set to “-1”, only the proper category name will be added to the product. The default value of this tag is “1”. 
category_path_delimiter: if the category paths are exported (category_first_level is not -1), each category at the path will be delimited by this string. The default value is “>”. Example: catA1>catA2#catB1>catB2>catB3 
add_absolute_url_to_field; wit this tag you can set a field name, which will be used to add the absolute product link. if this field does not exists, it will be added. if it exists, it will be overwritten. 
add_image_url_to_field; this tag works at the same way, but exports the absolute image link.
- add_parent_sku: If this field is added, the parent SKU of any simple products associated with a configurable product will be added as a field.
- add_child_skuIf this field is added, the child SKUs of any configurable products will be added as a field. If intended for use with Magmi, this should be named as simple_skus.
- child_sku_delimiter: Delimiter for the add_child_sku field, default if unspecified is a comma.


Limitations: This will only currently pull up the first parent SKU of a simple product, if it is assigned to multiple configurables. I didn't look into that any further at the time. This does not affect child products of configurables, which will be properly seperated by the delimiter specified.


I've uploaded the source to GitHub,at https://github.com/microchip/Magento-ExportExtension - both the main extension code, and a prepackaged version in the package folder. Hope it helps save someone the pain I went through trying to figure this damn thing out. The only answer you seem to find online is "Well, if you're struggling with this, here's an extension we'll sell you to fix the issue!" Open source at its best, huh, guys? Don't get me wrong, I understand the desire to write extensions and make money, but the amount people seem to charge is a bit ridiculous, especially if you only want one feature out of the 10 the extensions that are being peddled do.


Anyway. Rant over...