Search This Blog

Tuesday, May 15, 2012

Customer and Product adapters



Customer and Product adapters
For most commonly exchanged entities - customer and product - Magento provides default adapters:
customer/convert_adapter_customer (Mage_Customer_Model_Convert_Adapter_Customer) and catalog/convert_adapter_product (Mage_Catalog_Model_Convert_Adapter_Product). Both inherit from Mage_Eav_Model_Convert_Adapter_Entity. To simply load all customers data for selected store you can use the following xml:

<action type="customer/convert_adapter_customer" method="load"> <var name="store">default</var> </action> Sometimes you may want to load only defined group of customers from database. To help you with this there are available following filtering variables: filter/firstname - to load only customers with firstname starting with value of this variable filter/lastname - to load only customers with lastname starting with value of this variable filter/email - to load only customers with email starting with value of this variable filter/group - to load only customers from group with id equal to value of this variable filter/adressType - to export only selected addressType; valid values are: both, default_billing, default_shipping filter/telephone - to load only customers with telephone starting with value of this variable filter/postcode - to load only customers with postcode starting with value of this variable filter/country - to load only customers with country iso code equal to value of this variable filter/region - to load only customers with region equal to value of this variable (for US just 2-letter state names) filter/created_at/from - to load only customers created after a date defined as value of this variable filter/created_at/to - to load only customers created before a date defined as value of this variable

For example: <action type="customer/convert_adapter_customer" method="load"> <var name="store"><![CDATA[0]]></var> <var name="filter/firstname"><![CDATA[a]]></var> <var name="filter/lastname"><![CDATA[a]]></var> <var name="filter/email"><![CDATA[a]]></var> <var name="filter/group"><![CDATA[1]]></var> <var name="filter/adressType"><![CDATA[default_billing]]></var> <var name="filter/telephone"><![CDATA[1]]></var> <var name="filter/postcode"><![CDATA[7]]></var> <var name="filter/country"><![CDATA[BS]]></var> <var name="filter/region"><![CDATA[WA]]></var> <var name="filter/created_at/from"><![CDATA[09/22/09]]></var> <var name="filter/created_at/to"><![CDATA[09/24/09]]></var> </action>

Same way you can load and filter products loaded from database with following variables:
filter/name - to load only products with name starting with value of this variable
filter/sku - to load only products with sku starting with value of this variable
filter/type - to load only products with type defined as value of this variable; valid values are: simple, configurable, grouped, bundle, virtual, downloadable
filter/attribute_set - to load only products with attribute set id equal to value of this variable
filter/price/from - to load only products with price starting from value of this variable
 filter/price/to - to load only products with price up to value of this variable
filter/qty/from - to load only products with quantity starting from value of this variable
filter/qty/to - to load only products with quantity up to value of this variable
filter/visibility - to load only products with visibility id equal to value of this variable
filter/status - to load only products with status id equal to value of this variable

Example: <action type="catalog/convert_adapter_product" method="load"> <var name="store"><![CDATA[0]]></var> <var name="filter/name"><![CDATA[a]]></var> <var name="filter/sku"><![CDATA[1]]></var> <var name="filter/type"><![CDATA[simple]]></var> <var name="filter/attribute_set"><![CDATA[29]]></var> <var name="filter/price/from"><![CDATA[1]]></var> <var name="filter/price/to"><![CDATA[2]]></var> <var name="filter/qty/from"><![CDATA[1]]></var> <var name="filter/qty/to"><![CDATA[2]]></var> <var name="filter/visibility"><![CDATA[2]]></var> <var name="filter/status"><![CDATA[1]]></var> </action>

No comments:

Post a Comment