我正在使用自定义数据库表创建一个自定义模块 以下教程.

该模块是一个自定义联系表,我希望该自定义联系表的设置为每个商店,这意味着我希望从电子邮件地址发送的发送给我创建的每个商店。

我是否需要在数据库中添加特定字段才能获得Magento?还是Magento自动执行此操作?

有帮助吗?

解决方案

您可以使用Magento的现有行为,该行为允许为每个商店视图定义并获得联系电子邮件地址,并取决于部门(销售,客户支持,一般)。然后,您可以在自定义模块中使用特定的每个商店视图。

这是电子邮件地址的配置后端:backend email addresses

在您的自定义模块中使用此特定电子邮件,在您的情况下,重要的部分是 $sender多变的。这是一个代码示例(检查其中的评论,请注意,它是从我的代码中获取的,因此可以适应您的需求):

$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);

其他提示

当您在模块中定义它们时,Magento将自动添加它们 system.xml 文件。

<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>

然后,您可以通过...检索有关商店的配置值

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

app/Mage.php

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

反过来呼叫...

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);
}

注意如何根据商店代码在此处确定配置值的路径...

$fullPath = 'stores/' . $this->getCode() . '/' . $path;
许可以下: CC-BY-SA归因
scroll top