-
- mongolito404

-
Total Posts: 11
Joined: 2008-01-28
|
Hi,
I’m trying to add attributes to the Customer model with one a “backend model” to add some custom beforeSave behavior (data validation).
I did add my attributes to the eav_attribute table and set the “backend_model” for one of them. Like this:
INSERT INTO `eav_attribute` (`entity_type_id`, `attribute_code`, `attribute_model`, `backend_model`, `backend_type`, `backend_table`, `frontend_model`, `frontend_input`, `frontend_label`, `frontend_class`, `source_model`, `is_global`, `is_visible`, `is_required`, `is_user_defined`, `default_value`, `is_searchable`, `is_filterable`, `is_comparable`, `is_visible_on_front`, `is_unique`, `apply_to`, `use_in_super_product`) VALUES (1, 'vatnumber', NULL, 'customer_entity/customer_attribute_backend_vatnumber', 'varchar', NULL, NULL, 'text', 'VAT Number', NULL, NULL, 1, 1, 1, 0, NULL, 1, 0, 0, 0, 0, 0, 1); INSERT INTO `eav_attribute` ( `entity_type_id`, `attribute_code`, `attribute_model`, `backend_model`, `backend_type`, `backend_table`, `frontend_model`, `frontend_input`, `frontend_label`, `frontend_class`, `source_model`, `is_global`, `is_visible`, `is_required`, `is_user_defined`, `default_value`, `is_searchable`, `is_filterable`, `is_comparable`, `is_visible_on_front`, `is_unique`, `apply_to`, `use_in_super_product`) VALUES (1, 'vatcountry', NULL, NULL, 'varchar', NULL, NULL, 'select', 'VAT Country', NULL, 'vatcustomer_entity/customer_attribute_source_vatcountry', 1, 1, 1, 0, 'BE', 1, 1, 1, 1, 0, 0, 1); INSERT INTO `eav_attribute` ( `entity_type_id`, `attribute_code`, `attribute_model`, `backend_model`, `backend_type`, `backend_table`, `frontend_model`, `frontend_input`, `frontend_label`, `frontend_class`, `source_model`, `is_global`, `is_visible`, `is_required`, `is_user_defined`, `default_value`, `is_searchable`, `is_filterable`, `is_comparable`, `is_visible_on_front`, `is_unique`, `apply_to`, `use_in_super_product`) VALUES (1, 'vatvalid', NULL, NULL, 'int', NULL, NULL, NULL, 'VAT Number is valided by VIES', NULL, NULL, 1, 1, 0, 0, NULL, 1, 1, 0, 0, 0, 0, 1); INSERT INTO `eav_attribute` (`entity_type_id`, `attribute_code`, `attribute_model`, `backend_model`, `backend_type`, `backend_table`, `frontend_model`, `frontend_input`, `frontend_label`, `frontend_class`, `source_model`, `is_global`, `is_visible`, `is_required`, `is_user_defined`, `default_value`, `is_searchable`, `is_filterable`, `is_comparable`, `is_visible_on_front`, `is_unique`, `apply_to`, `use_in_super_product`) VALUES (1, 'vatlastcheck', NULL, NULL, 'datetime', NULL, NULL, NULL, 'Date of the last VAT Number validity check.', NULL, NULL, 1, 1, 0, 0, NULL, 0, 0, 0, 0, 0, 0, 1);
When testing I directly add the file in the app/code/core/Mage/Customer/Model/Entity/Customer/Attribute/Backend directory and changed the lat part of the name to my class/filename. Now I want to put it in a Module and I can’t get it to work.
I created the following files with no success:
app/etc/modules/VatCustomer.xml
<config> <modules> <Mage_VatCustomer> <active>true</active> <codePool>local</codePool> </Mage_VatCustomer> </modules> </config>
app/code/local/Mage/Vatcustomer/etc/config.xml
<?xml version="1.0"?> <config> <modules> <Mage_VatCustomer> <version>0.1.0</version> </Mage_VatCustomer> </modules> <global> <models> <vatcustomer> <class>Mage_VatCustomer_Model</class> </vatcustomer> </models> </global> </config>
app/code/local/Mage/Vatcustomer/Model/Entity/Customer/Attribute/Backend/Vatnumber.php
class Mage_VatCustomer_Model_Entity_Customer_Attribute_Backend_Vatnumber extends Mage_Eav_Model_Entity_Attribute_Backend_Abstract { public function beforeSave($object) { // doing some stuff here... } }
If I go to the /admin/customer/ page, I get
Warning: include(Mage/Customer/Model/Entity/Customer/Attribute/Backend/Vatnumber.php) [function.include]: failed to open stream: No such file or directory in /home/pbuyle/public_html/magento/app/code/core/Mage/Core/functions.php on line 44
. When I put my file directly in app/code/local/Mage/Customer/Model/Entity/Customer/Attribute/Backend/, with the proper prefix in the DB, it worked.
What did I miss ?
Also, has you can see in my eav_attributes addition, I’m trying to store boolean as int value. But I have to manually convert boolean to int (0 and 1) when using “generated” accessor (ie. $customer->setValid(false) doesn’t work, I’ve to do $customer->setValid(0)). Did I also miss something here ?
Finally, I added a “backend_source” to the vat_country attribute. It works to generate the dropdown in the admin’s “edit customer” page, but how do I re-use it to generate dropdown in templates (such as customer register and edit). Where can I put “helper” code. How can this code access the “source class” ?
|