Domanda

I stava per mettere insieme una piccola estensione per abilitare sotto globale portata , ma è rimasto bloccato cercando di riscrivere core/template.

Classe riscrive solo il lavoro per le classi istanziate tramite uno dei metodi di Magento a farlo (helper, getModel, getSingleton). Per astratto e fortemente estesa dalle classi ti sembra di essere lasciato con la possibilità di sostituzioni local/Mage.

Due domande:

  1. C'è un modo intelligente per evitare di override local/Mage in ogni momento?
  2. Se non c'è, come si fa a fare compreso tali sostituzioni nelle estensioni della comunità?
È stato utile?

Soluzione

1) Any extension which you offer to the community should be under the community code pool.

2) You shouldn't, but you can, and sometimes you must because Demeter has been ignored a lot in Magento 1.

There is almost always a way around the need to override, including the use of Reflection as mentioned by Vinai awhile back.

If there is too much downside to workarounds, you simply must take ownership of the class definition. You can do one of the following, provided that users are made aware:

  1. In the community code pool, provide the modified definition under Mage | Varien | Zend namespace as appropriate. Possible concern would be that end user might have done the same.
  2. As above, but in a new code pool: prepend the new codepool to the bootstrapped include paths using set_include_path(). Drawback: more stat()ing caused by the autoloader, and your include path manipulation will be non-obvious as it is outside of the bootstrap.
  3. If possible, provide the definition yourself before it is loaded from its normal location, e.g. by explicitly include()ing it from a non-standard location under your namespace.

Sound your case-by-case needs out here - someone will have an idea. As for the template path hints in the admin scope, see my answer which doesn't even require PHP.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a magento.stackexchange
scroll top