1

I am creating a custom module with a custom database table using the following tutorial.

This module is a custom contact form, and I would like the settings for that custom contact form to be on a per store basis, meaning, I want the send from email address to be different for each store I create.

Do I need to add specific fields to the database for Magento to pick up on this? Or does Magento do this automagically?

dotancohen
1,1306 silver badges21 bronze badges
asked Jan 30, 2013 at 22:12

2 Answers 2

3

You could use the existing behavior of Magento which allows to define and get a contact email address for each store view and depending on the department (sales, customer support, general). You can then use theses specific contact per store view in your custom module.

Here is the configuration backend for email addresses: backend email addresses

And to use this specific email in your custom module, the important part in your case is the $sendervariable. Here is a code sample (check the comment in it, be aware that it is taken from a code of me, so adapt to your needs):

$recipient = $item->getRecipient();
$template = $item->getTemplate();
if (!Mage::getConfig()->getNode(Mage_Core_Model_Email_Template::XML_PATH_TEMPLATE_EMAIL .'/' . $template)){
 Mage::throwException(Mage::helper('customer')->__('Wrong transactional notification email template.'));
}
$customer = Mage::getModel('customer/customer')->load($customer->getId());
$recipient = array('name' => $customer->getName(), 'email' => $customer->getEmail());
 /**
 * $senderType can be support, general, sales, custom1, custom2
 * You can also replace the array by a string and provide only the string 'general', 'support', etc
 */
 $sender = array(
 'name' => Mage::getStoreConfig('trans_email/ident_' . $senderType . '/name', $storeId),
 'email' => Mage::getStoreConfig('trans_email/ident_' . $senderType . '/email', $storeId)
 );
}
$translate = Mage::getSingleton('core/translate');
$translate->setTranslateInline(false);
/* @var $emailTemplate Mage_Core_Model_Email_Template */
$emailTemplate = Mage::getModel('core/email_template');
if (Mage::app()->getStore()->isAdmin()) Mage::app()->getLocale()->emulate($storeId);
$variables += array(
 'name' => $customer->getName()
);
if (Mage::app()->getStore()->isAdmin()) Mage::app()->getLocale()->revert();
$emailTemplate->setDesignConfig(array('area' => 'frontend', 'store' => $storeId))
 ->sendTransactional($template, // xml path email template
 $sender,
 $recipient['email'],
 $recipient['name'],
 $variables
 );
$translate->setTranslateInline(true);
answered Jan 31, 2013 at 9:10
3

Magento will add these automagically when you define them in your modules system.xml file.

<some_setting>
 <label>Some Setting Label</label>
 <frontend_type>text</frontend_type>
 <sort_order>1</sort_order>
 <show_in_default>1</show_in_default>
 <show_in_website>1</show_in_website>
 <show_in_store>1</show_in_store>
</some_setting>

You then retrieve the config value for the store in question via...

Mage::getStoreConfig( '/path/to/setting', $store_id );

app/Mage.php

public static function getStoreConfig($path, $store = null)
{
 return self::app()->getStore($store)->getConfig($path);
}

Which, in turn, calls...

app/code/core/Mage/Core/Model/Store.php

public function getConfig($path)
{
 if (isset($this->_configCache[$path])) {
 return $this->_configCache[$path];
 }
 $config = Mage::getConfig();
 $fullPath = 'stores/' . $this->getCode() . '/' . $path;
 $data = $config->getNode($fullPath);
 if (!$data && !Mage::isInstalled()) {
 $data = $config->getNode('default/' . $path);
 }
 if (!$data) {
 return null;
 }
 return $this->_processConfigValue($fullPath, $path, $data);
}

Notice how it's determining the path to the config value based upon the store code here...

$fullPath = 'stores/' . $this->getCode() . '/' . $path;
answered Jan 30, 2013 at 23:03

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.