質問

カスタムデータベーステーブルを使用してカスタムモジュールを作成しています 次のチュートリアル.

このモジュールはカスタム連絡先フォームであり、そのカスタム連絡先フォームの設定が1ストアごとにあることを望みます。つまり、私は作成した各ストアの電子メールアドレスからの送信を異なるものにしたいと思います。

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

他のヒント

モジュールで定義すると、マゼントはこれらを自動的に追加します 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帰属
所属していません magento.stackexchange
scroll top