Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

Adding a property to all stores
 
zburnham
Member
 
Avatar
Total Posts:  69
Joined:  2007-11-07
Westborough, MA
 

I need to modify the core Store model to include another flag (a boolean).  I’ve gone through and it looks like I just need to add a column to the database table that stores store configuration information.  I’ve already written the subclass to extend Mage_Core_Model_Store and verified that it works, but I’m kind of stuck on a couple of things:

1) How do I add this flag to the store model so it is stored in the database, and
2) Is there a tutorial or something on creating the ability to configure this flag in the admin backend?

I’ve gone through what I can find, especially the payment module tutorial, but it doesn’t seem directly applicable.  Any help is appreciated.

 
Magento Community Magento Community
Magento Community
Magento Community
 
Moshe
Magento Team
 
Avatar
Total Posts:  1770
Joined:  2007-08-07
Los Angeles
 

Only EAV models allow dynamic attributes extension, other models will need table alteration.

The correct way is to create a custom module that has a version in Mage/MyModule/etc/config.xml:

<?xml version="1.0"?>
<config>
    <
modules>
        <
Mage_MyModule>
            <
version>0.1.0</version>
        </
Mage_MyModule>
    </
modules>
    <global>
        <
resources>
            <
mymodule_setup>
                <
setup>
                    <
module>Mage_MyModule</module>
                </
setup>
                <
connection>
                    <use>
core_setup</use>
                </
connection>
            </
mymodule_setup>
        </
resources>
    </global>
</
config>

When the module is being installed the <engine>-install-<version>.php file will be called:
Mage/MyModule/sql/mymodule_setup/mysql4-install-0.1.0.php

<?php

$this
->startSetup()->run("

alter table `{
$this->getTable('core/store')}` add column `boolean_flag` tinyint;

"
)->endSetup();

Future upgrades should be done in <engine>-upgrade-<from_version>-<to_version>.php:
Mage/MyModule/sql/mymodule_setup/mysql4-upgrade-0.1.0-0.2.0.php

 
Magento Community Magento Community
Magento Community
Magento Community
 
zburnham
Member
 
Avatar
Total Posts:  69
Joined:  2007-11-07
Westborough, MA
 

OK, here’s a question then:  I’ve been developing this module right along in an installation of Magento, so there’s been no need for an ‘installation’ per se.. how would I get Magento to read that file if the files are already in place?

 
Magento Community Magento Community
Magento Community
Magento Community
 
mzentrale1
Guru
 
Total Posts:  731
Joined:  2007-12-06
Stuttgart, Germany
 

Hi,

i want to save payment datas in my new module to order_payment therefor i can use dynamic attributes from EAV models?
Where and how can i define that new attributes for my module? Also in the module_setup? For example i want to add bank account and
account owner to my order.

Is following way correct?

$this->startSetup()->run("
select 
    @entity_type_id:=entity_type_id from eav_entity_type
where 
    entity_type_code='order_payment';

insert into eav_attribute
    (entity_type_id, attribute_name, attribute_code, backend_type, frontend_input, frontend_label)
values 
    (@entity_type_id, 'hpda_account_owner', 'hpda_account_owner', 'varchar', 'text', 'Account owner'); 
"
)->endSetup();

KR

Stefan

 
Magento Community Magento Community
Magento Community
Magento Community
 
zburnham
Member
 
Avatar
Total Posts:  69
Joined:  2007-11-07
Westborough, MA
 

Could someone also explain to me what the deal is with EAV?  I’ve never heard of that term before starting to work with Magento, and I don’t understand how you use the eav_attributes to modify an existing model, what models you can change with it, and so forth.

Basically what I’m looking to do is to add a boolean to the store config, and then based on the value of that boolean, have Magento read data in from another table.  The information in the mysql-install file above is useful, but I need to know how to add a completely new table as well.

Also, how in the heck do you add something to an existing page in the admin?  I need to add a config item to allow the admin to turn the feature on or off by storefront, and also to input data that the feature uses.

Please help, I’ve been making good progress so far extending the models I need to, but have come to a deadend with the backend stuff.

 
Magento Community Magento Community
Magento Community
Magento Community
 
mzentrale1
Guru
 
Total Posts:  731
Joined:  2007-12-06
Stuttgart, Germany
 

Hi,

EAV - Entity-Attribute-Value model

Cheers

Stefan

 
Magento Community Magento Community
Magento Community
Magento Community
 
zburnham
Member
 
Avatar
Total Posts:  69
Joined:  2007-11-07
Westborough, MA
 

That article made my brain hurt [m]zentrale.  smile

 
Magento Community Magento Community
Magento Community
Magento Community
 
zburnham
Member
 
Avatar
Total Posts:  69
Joined:  2007-11-07
Westborough, MA
 

I could still use some help with creating a brand new table to store data for a new module, as well as some help in how I would install a module ‘in place’, ie get Magento to read the mysql-setup file and create what it needs to create.

Help with setting up the admin for configuring this data kind of goes with that, so any help is appreciated.

 
Magento Community Magento Community
Magento Community
Magento Community
 
zburnham
Member
 
Avatar
Total Posts:  69
Joined:  2007-11-07
Westborough, MA
 

I know it’s bad form to bump one’s own posts, but I really need some help here with figuring out how to add a brand new table to the database, how to “install” a module that you’ve been developing (so the SQL code is read) and how to set things up in the admin interface.

 
Magento Community Magento Community
Magento Community
Magento Community
 
mzentrale1
Guru
 
Total Posts:  731
Joined:  2007-12-06
Stuttgart, Germany
 

Hi,

i think the first step should be a explaination what you want to do.

Cheers

 
Magento Community Magento Community
Magento Community
Magento Community
 
zburnham
Member
 
Avatar
Total Posts:  69
Joined:  2007-11-07
Westborough, MA
 

OK [m]zentrale, this is the deal:

I have to add a boolean field to each store for a new feature I’m writing.  If this field is true, then it needs to pull from another table that contains a store id and a five digit sequence (in other words, a one-to-many relationship between the store id and the data. Each store ID will appear several times, but the data will only appear in one record for each store.)

I can’t think of another way to do this outside of adding a table.

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top