How to create multi store module in the Magento - magento

I want to create my custom module multi store compatible. I want to get the value from my custom database table as per configuration scope. While adding the values to the database table, i have specified the scope_id and scope like as Magento does in the core_config_data table. Now how can i fetch those inserted value from the table according to the selected website on the front end.
I have the following database value snippet.
ID value scope_id scope
1 test 0 default
2 test1 4 store
3 test12 5 website
Can anybody help me in this? Thanks

It is not so easy to reuse Magento's config loading for your own needs.
What you want is to inherit your values from default -> website -> store (if not overwritten in there).
Magento converts the database config to the internal XML representation in Mage_Core_Model_Resource_Config::loadToXml and does the merging and inheritance logic in there.
The inheritance logic is all in the loadToXml() function - so you could implement something similar if you want to take the same approach and build your values for each store scope.
If you simply need to get one value for a specific scope you just have to read the database row with that store, if not found with the website the store is in, if not found the default value.

Related

How does beforeSaveAddressInformation plugin

I was looking at this post: Magento 2 Add a custom input field on chackout forrm and save it
I have tried the same way but I am not sure how this part came
$customField = $shippingAddressExtensionAttributes->getFiscalCode();
$shippingAddress->setFiscalCode($customField);
Where is this getFiscalCode?
It's a Custom AttributeCode.
the getFiscalCode() method is an accessor method that is used to identity fields such as the one that is created with the extension attribute fiscal_code mentioned in the example.
It is not just extension attributes, but all collection models in magento use the following camel casing structure where for example the column entity_id in database table, can be accessed via either $modelCollection->getEntityId() or $modelCollection->setEntityId($valueOfEntityId)
This is a good read to understand the idea Magento 2: CRUD Models for Database Access

Servicenow - Service Catalog Reference Field - Insert different column than the display value

Let me describe my problem:
I have a table for all my IT-Services. I reference to this table more than once, for different purposes. Most of the time I need to reference to the name of the service. That's why I keep the name as displayed value.
One Column of that table is a service_id (custom field) which is for example "Service_004". Now in a catalog request Item the User has to fill in the service_id in a reference field.
But since I have the name as displayed value, and I need it in other forms, I am unable to reference to the service_id.
Using the variable attributes field I managed to let the service be found using the autocomplete function. But in the reference field I still get the servicename. I know that I can change the display value in the dictionary, but this breaks other functions. So what I need is to change the display value just for one reference field.
Also I tried to create a new table called IT-Services2 with reference to my table IT-Services. Then I switched the display to true in the new table for my service_id, but this will even change it in the parent table.
Perhaps an onChange client script utilizing g_form.setLabelOf() ?
http://wiki.servicenow.com/index.php?title=GlideForm_(g_form)#setLabelOf
Maybe I'm not fully understanding your question...
I ran into this issue before, what you can do is create select box variable and use an on load client script to populate the list with the service_id(s) from the table you are referencing.
I would write a script include to pull the data from the table and call it from the client script via GlideAjax.

How to find out the Joomla components base table name

I want to know in which table a joomla component stores its data and I want to achieve this programmatically. (I already know through phpmyadmin the relevant tables a component stores data in.) For eg. if I know that the base component is com_content then how can the Joomla 3.1 platform a.p.i tell me that it stores its data in #__content table.
The content types table provides information on this if your component has stored rows there. Using this you can programmatically get both the db table as well as the JTable data. In 3.2. there are a couple of places where this is used nicely such as in the ordering field and in versioning.

Magento - Store Config only added to database after being saved

I have noticed that in Magento the core_config_data table is very small just after installation and it gradually gets populated over time ONLY when sections of the system config are saved. For example there are no values in the core_config_data table for the contacts settings - yet i can still do Mage::getStoreConfig('contacts/contacts/enabled') and get the correct value.
So, does this mean that magento is simply reading the config xml until a value is saved, and at which point it saves to the database and then the value is read from there?
If this is the case, then surely this is a bad design pattern, having these values stored in two places?
I think this post may help.
The Magento Config: Loading System Variables

Adding columns to DB after publishing using EF CodeF and mvc nugget Scaffold

I have created a web site using mvc 3 and Ef code first , now after publishing the site and it's DB I have found out that I need to add a new columns to one of my DB table,
(the DB already has a lot of data in it )
should I add the columns direct to the DB or should I add to the class?
(just a simple string with get and set)
And how can I do it without losing my data in the DB ?
thanks
Adding the columns to the class should be enough. Evidence you can find here.
Here is the full list of changes that migrations can take care of automatically:
Adding a property or class
Nullable columns will be assigned a value of null for any existing rows of data
Non-Nullable columns will be assigned the CLR default for the given data type for any existing rows of data
Renaming a property or class
See ‘Renaming Properties & Classes’ for the additional steps required here
Renaming an underlying column/table without renaming the property/class
(Using data annotations or the fluent API)
Migrations can automatically detect these renames without additional input
Removing a property
See ‘Automatic Migrations with Data Loss’ section for more information
I suggest you to add the columns direct to the DB and to the class, and test it on the local machine.

Resources