문제

가 젠토 CE1.9.2.4 되는 시스템입니다.

지금 내가 원하사 모듈의 시스템을 구성할 때 저장"구성"버튼을 클릭합니다.

아래에 나의 관찰자 코드:

<?php
class Mycompany_StoreLocator_Model_Observer extends Varien_Event_Observer
{
    public function validateDefaultCountry($observer) {
        echo "<pre/>";print_r($observer->getEvent());die;
    }
}

아래에 나 config.xml:

<?xml version="1.0"?>
<!--
/**
 * Mycompany_Mymodule extension
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Open Software License (OSL 3.0)
 * that is bundled with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://opensource.org/licenses/osl-3.0.php
 *
 * @category   Mycompany
 * @package    Mycompany_Mymodule
 * @copyright  Copyright (c) 2008 Mycompany LLC
 * @license    http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
 */

/**
 * @category   Mycompany
 * @package    Mycompany_Mymodule
 * @author     Boris (Moshe) Gurevich <moshe@Mycompany.com>
 */
-->
<config>
    <modules>
        <Mycompany_Mymodule>
            <version>0.2.6</version>
        </Mycompany_Mymodule>
    </modules>
    <global>
        <models>
            <mymodule>
                <class>Mycompany_Mymodule_Model</class>
                <resourceModel>mymodule_mysql4</resourceModel>
            </mymodule>
            <mymodule_mysql4>
                <class>Mycompany_Mymodule_Model_Mysql4</class>
                <entities>
                    <location>
                        <table>mymodule_location</table>
                    </location>
                </entities>
            </mymodule_mysql4>
        </models>
        <events>
            <admin_system_config_changed_section_mymodule>
                <observers>
                    <mymodule>
                        <type>singleton</type>
                        <class>mymodule/observer</class>
                        <method>validateDefaultCountry</method>
                    </mymodule>
                </observers>
            </admin_system_config_changed_section_mymodule>
        </events>
        <resources>
            <mymodule_setup>
                <setup>
                    <module>Mycompany_Mymodule</module>
                </setup>
                <connection>
                    <use>core_setup</use>
                </connection>
            </mymodule_setup>
            <mymodule_write>
                <connection>
                    <use>core_write</use>
                </connection>
            </mymodule_write>
            <mymodule_read>
                <connection>
                    <use>core_read</use>
                </connection>
            </mymodule_read>
        </resources>
        <helpers>
            <mymodule><class>Mycompany_Mymodule_Helper</class></mymodule>
        </helpers>
        <blocks>
            <mymodule><class>Mycompany_Mymodule_Block</class></mymodule>
        </blocks>
        <mymodule>
            <private_fields></private_fields>
        </mymodule>
    </global>
    <frontend>
        <routers>
            <mymodule>
                <use>standard</use>
                <args>
                    <module>Mycompany_Mymodule</module>
                    <frontName>mymodule</frontName>
                </args>
            </mymodule>
        </routers>
        <translate>
            <modules>
                <Mycompany_Mymodule>
                    <files>
                        <default>Mycompany_Mymodule.csv</default>
                    </files>
                </Mycompany_Mymodule>
            </modules>
        </translate>
          <layout>
              <updates>
                  <mymodule module="Mycompany_Mymodule">
                      <file>mymodule.xml</file>
                  </mymodule>
              </updates>
          </layout>
    </frontend>
    <admin>
         <routers>
            <mymoduleadmin>
                <use>admin</use>
                <args>
                    <module>Mycompany_Mymodule</module>
                    <frontName>mymoduleadmin</frontName>
                </args>
            </mymoduleadmin>
        </routers>
    </admin>
    <adminhtml>
        <menu>
          <mycompany>
             <title>Mycompany</title>
                <sort_order>71</sort_order>
                <children>
                    <mymodule translate="title" module="mymodule">
                        <title>Advance Store Locator</title>
                        <sort_order>3</sort_order> 
                        <action>mymoduleadmin/adminhtml_location</action>
                    </mymodule>
                 </children>
           </mycompany>
    </menu>
        <acl>
            <resources>
                <admin>
                    <children>
                        <system>
                            <children>
                                <config>
                                    <children>
                                        <mymodule translate="title" module="mymodule"> 
                                            <title>Advance Store Locator</title>
                                            <sort_order>50</sort_order>
                                        </mymodule>
                                    </children>                         
                                </config>
                            </children>
                        </system>
                    </children>
                </admin>
            </resources>
        </acl>
        <translate>
            <modules>
                <Mycompany_Mymodule>
                    <files>
                        <default>Mycompany_Mymodule.csv</default>
                    </files>
                </Mycompany_Mymodule>
            </modules>
        </translate>
    </adminhtml>
    <default>
        <mymodule>
            <general>
                <google_geo_url><![CDATA[https://maps.google.com/maps/geo]]></google_geo_url>
                <show_search>1</show_search>
                <show_map>0</show_map>
            </general>
        </mymodule>
    </default>
</config>

어떻게 받을 수 있는 시스템 구성 분야 되는 저장할 때는 관찰자가 트리거되는?

처럼 점점에서 인용한 점검 이벤트 $observer->getEvent()->getQuote()

도움이 되었습니까?

해결책

을 추가할 필요가 없는 관찰자니다.
시스템->설정 값을 사용할 수 있습 백 엔드 모델이다.
system.xml 는 선언의 필드 마이:

<field_name_here translate="label">
    <label>Label here</label>
    <frontend_type>text</frontend_type>
    <backend_model>[module]/something_here</backend_model><!-- add this one -->
    <sort_order>10</sort_order>
    <show_in_default>1</show_in_default>
    <show_in_website>1</show_in_website>
    <show_in_store>1</show_in_store>
</field_name_here>

그때는 모델을 만들 [Namespace]_[Module]_Model_Something_Here

<?php 
class [Namespace]_[Module]_Model_Something_Here extends Mage_Core_Model_Config_Data
{
    protected function _beforeSave()
    {   
        //get the value being saved
        $value = $this->getValue();
        $isValid = your custom validation here
        if (!$isValid) {
            Mage::throwException(
                Mage::helper('[module]')->__('your error message here')
            );
        }

    }
}

이를 막을 것이 값을 저장하는 경우에 그것이 잘못하고 당신은 오류 메시지가 표시됩니다.에서 최고의 페이지입니다.
당신이 볼 수 있는 작업에 대한 예 분야 base_urlapp/code/core/Mage/Core/etc/system.xml 을 사용하는 백 엔드 모델 adminhtml/system_config_backend_baseurl 로 변환하는 클래스 Mage_Adminhtml_Model_System_Config_Backend_Baseurl

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 magento.stackexchange
scroll top