문제

나는 인용문을 사용자 정의 데이터 유형으로 변환하고 Mage_Core_Helper_Data::copyFieldset 동일한 소스 속성으로 설정해야 하는 두 개의 대상 속성이 있을 때까지는 정말 잘 작동했습니다.나는 몇 가지 다른 것을 시도했습니다.

        <other_thing_convert_quote>
            <grand_total>
                <to_varien_object>total</to_varien_object>
            </grand_total>
            <quote_currency_code>
                <to_varien_object>currency</to_varien_object>
            </quote_currency_code>
            <quote_id>
                <to_varien_object>refnum</to_varien_object>
                <to_varien_object>txn_uuid</to_varien_object>
            </quote_id>
        </other_thing_convert_quote>

위는 하나 quote_id 노드, 다중 to_varien_object 노드.

        <other_thing_convert_quote>
            <grand_total>
                <to_varien_object>total</to_varien_object>
            </grand_total>
            <quote_currency_code>
                <to_varien_object>currency</to_varien_object>
            </quote_currency_code>
            <quote_id>
                <to_varien_object>refnum</to_varien_object>
            </quote_id>
            <quote_id>
                <to_varien_object>uuid</to_varien_object>
            </quote_id>
        </other_thing_convert_quote>

위에는 다중 quote_id 노드, 각각 하나씩 to_varien_object 마디.

이러한 접근 방식 중 어느 것도 성공적으로 적용되지 않습니다. quote_id 둘 다에게 refnum 그리고 txn_uuid.

코드를 보면 내가 찾고 있는 것이 가능한지 확신할 수 없지만, 내가 틀렸다는 것이 증명될 수 있기를 바랍니다!

감사해요

도움이 되었습니까?

해결책

또 다른 해결책은 다음과 같은 경우 전달되는 이벤트를 사용하는 것입니다. copyFieldset 함수는 다음과 같이 호출됩니다.

$eventName = sprintf('core_copy_fieldset_%s_%s', $fieldset, $aspect);
Mage::dispatchEvent($eventName, array(
    'target' => $target,
    'source' => $source,
    'root'   => $root
));

보시다시피 이벤트 이름은 동적이므로 이 경우 호출하면 copyFieldset('other_thing_convert_quote', 'to_varien_object', ...) 이벤트 이름은 core_copy_fieldset_other_thing_convert_quote_to_varien_object 그리고 이것이 모듈의 config.xml에 넣을 내용입니다:

<events>
    <core_copy_fieldset_other_thing_convert_quote_to_varien_object>
        <observers>
            <modulename>
                <type>singleton</type>
                <class>modulename/observer</class>
                <method>coreCopyFieldsetOtherThingConvertQuoteToVarienObject</method>
            </modulename>
        </observers>
    </core_copy_fieldset_other_thing_convert_quote_to_varien_object>
</events>

그리고 마지막으로 관찰자 메서드에서는 다음을 수행하여 필요한 값을 설정합니다.

public function coreCopyFieldsetOtherThingConvertQuoteToVarienObject($observer) {
    // your 'other_thing'
    $src = $observer->getSource();

    // your 'varien_object'
    $target = $observer->getTarget();

    $target->setData('refnum', $src->getQuoteId());
    $target->setData('txn_uuid', $src->getQuoteId());
}

다른 팁

이 문제에 대해 그다지 큰 관심은 없는 것 같지만, 나중에 누군가가 이 문제를 우연히 발견할 경우를 대비하여 제가 결정할 수 있는 최선의 해결책은 다음과 같습니다.Magento는 소스에서 데이터를 가져오고 다음을 사용하여 대상에 데이터를 설정합니다. getDataUsingMethod/setDataUsingMethod 노드 이름을 기반으로 "카멜화된" 메소드 호출을 시도합니다.예를 들어:

<my_module_convert_thing>
  <property_a>
    <to_another>*</to_another>
  </property_a>
</my_module_convert_thing>

전화를 시도할 것이다 setPropertyA 그리고 getPropertyA 두 개체에 대해.위임하는 통화 대신 getData 그리고 setData ~을 통해 Varien_Object::__call 정의된 방법이 있으므로 유연성에는 거의 제한이 없습니다.하나의 소스에서 두 개의 속성을 설정해야 하는 경우 다음 XML 필드 세트가 작동합니다.

<my_module_convert_thing>
  <property_a>
    <to_another>properties_ab</to_another>
  </property_a>
</my_module_convert_thing>

그리고 방법이라면 setPropertiesAb 에 정의되어 있습니다. another 클래스, 해당 메서드는 두 가지 모두의 설정을 처리할 수 있습니다. property_a 그리고 property_b 사용하여 property_a 가치 thing.

이 사용자 지정 접근 방식이 필요한 모든 클래스를 기본적으로 확장할 필요가 없는 더 나은 솔루션이 있다면 좋겠지만 이것이 문제를 해결하는 데 가장 좋은 방법입니다!

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