編集できないMagento CMSページを作成するにはどうすればよいですか?


16

Magentoの新規インストールには、で編集できるデフォルトのCMSページがいくつか付属していますCMS > Pages。しかし、それはまた、「非編集可能な」CMSページのカップルが付属しています:Orders and ReturnsそしてContact Us...それらのフォームを持つページですどちらも、そしてMagentoのCEでハイライト欠点:フォームの作成と編集します。

デフォルトのContact Usを独自のフォームで上書きできましたが、別のフォームを追加したいので、今後さらにフォームを追加する必要があります。これまでやってきたように、Magentoモジュールを作成して既存の機能やページをオーバーライドすることにある程度慣れています。

Magentoでフォームページを作成できるようにするモジュールの開発を始めましたが、デフォルトのフォームのように、CMS管理から見えないようにする必要があります。プログラムでCMSページを作成することに対する回答を見つけましたが、それがMagentoのに追加されCMS > Pagesます。

Magentoモジュールでのみ編集可能なCMSページを作成するにはどうすればよいですか?


知っておきたい!クロスポストするのはコーシャですか、それともすでにここに投稿しているので、受け入れられているプラ​​クティスは何ですか?
andyjv

「フラグ」リンクをクリックし、MODに移動してもらいます。一般的に、クロスポストは眉をひそめています。
ジョンコンデ

CMSページ内でカスタムの連絡先フォームを探している場合は、magento.stackexchange.com / questions / 79602 / またはより詳細なstackoverflow.com/q/1066127/664108
Fabian Schmengler

回答:


21

実際には、「お問い合わせ」と「注文と返品」はCMSページではありません。実際には、別のモジュールからのページです。これらは、CMSページのようなものではなく、「ログイン」または「登録」ページのようなものです。このようなページを作成するには、コントローラー、1つのブロック、1つのテンプレートを備えたシンプルなモジュールを作成します。拡張機能Easylife_Customformを呼び出しましょう。このためには、次のファイルが必要です。
app/etc/modules/Easylife_Customform.xml-モジュール宣言ファイル

<?xml version="1.0"?>
<config>
    <modules>
        <Easylife_Customform>
            <active>true</active>
            <codePool>local</codePool>
        </Easylife_Customform>
    </modules>
</config>

app/code/local/Easylife/Customform/etc/config.xml -設定ファイル

<?xml version="1.0"?>
<config>
    <modules>
        <Easylife_Customform>
            <version>0.0.1</version>
        </Easylife_Customform>
    </modules>
    <global>
        <blocks>
            <customform><!-- block alias -->
                <class>Easylife_Customform_Block</class>
            </customform>
        </blocks>
        <helpers>
            <customform><!-- helper alias -->
                <class>Easylife_Customform_Helper</class>
            </customform>
        </helpers>
    </global>
    <frontend>
        <routers>
            <customform>
                <use>standard</use>
                <args>
                    <module>Easylife_Customform</module>
                    <frontName>customform</frontName><!-- url key for module -->
                </args>
            </customform>
        </routers>
        <layout>
            <updates>
                <easylife_customform>
                    <file>easylife_customform.xml</file><!-- frontend layout file -->
                </easylife_customform>
            </updates>
        </layout>
        <translate>
            <modules>
                <Easylife_Customform>
                    <files>
                        <default>Easylife_Customform.csv</default><!-- translation file (not mandatory) -->
                    </files>
                </Easylife_Customform>
            </modules>
        </translate>
    </frontend>
</config>

app/design/frontend/base/default/layout/easylife_customform.xml -フロントエンドレイアウトファイル

<?xml version="1.0"?>
<layout>
    <customform_index_index translate="label" module="customform">
        <label>Custom form</label>
        <reference name="root">
            <action method="setTemplate"><template>page/2columns-right.phtml</template></action><!-- can be different -->
        </reference>        
        <reference name="content">
            <block type="core/template" name="customform" template="easylife_customform/form.phtml" /><!-- content of page -->
        </reference>
    </customform_index_index>
</layout>

app/code/local/Easylife/Customform/Helper/Data.php -デフォルトのモジュールヘルパー

<?php
class Easylife_Customform_Helper_Data extends Mage_Core_Helper_Abstract{
}

app/design/frontend/base/default/template/easylife_customform/form.phtml -フォームの実際のhtml-これを必要なように見せます

<form action="<?php echo $this->getUrl('customform/index/send')?>">
    <input type="text" name="name" />
    <input type="submit" />
</form>

app/code/local/Easylife/Customform/controllers/IndexController.php -モジュールコントローラー

<?php 
class Easylife_Customform_IndexController extends Mage_Core_Controller_Front_Action{
    public function indexAction(){ //this will display the form
        $this->loadLayout();
        $this->_initLayoutMessages('core/session'); //this will allow flash messages
        $this->renderLayout();
    }
    public function sendAction(){ //handles the form submit
        $post = $this->getRequest()->getPost();
        //do something with the posted data
        Mage::getSingleton('core/session')->addSuccess($this->__('Your message was sent'));//add success message.
        $this->_redirect('*/*');//will redirect to form page
    }
}

これであるはずです。キャッシュをクリアすると、フォームにアクセスできるはずです。mysite.com/customform
コードを正しく記述し、何かを見逃していないことを望みます。


2
あなたは本当にこの答えに余分な努力をしました。+1
philwinkle

@philwinkle:それは良いですか悪いですか?:)
マリウス

本当に素晴らしいガイドマリウス、ありがとう!ページタイトルを設定しようとしていますが、レイアウトxmlの<label>は無視されており、これ <reference name="head"> <action method="setTitle" translate="title"><title>Subscribe to our Newsletter</title></action> </reference> は機能しません。
loeffel

@loeffel。たぶん、タイトルを上書きする何か他のものがあります。理論的には、コードは機能するはずです。
マリウス

@Mariusこれは非常に便利ですが、どのようにエラーメッセージを追加できますか?追加しようとしましたMage::getSingleton('core/session')->addError("Error");が、運はありませんでした。その唯一の成功メッセージを示しています。助けがありますか?
アーミルシディケ
弊社のサイトを使用することにより、あなたは弊社のクッキーポリシーおよびプライバシーポリシーを読み、理解したものとみなされます。
Licensed under cc by-sa 3.0 with attribution required.