Ver Mensaje Individual
  #10 (permalink)  
Antiguo 12/01/2013, 11:14
rodriguezm
 
Fecha de Ingreso: noviembre-2011
Mensajes: 14
Antigüedad: 12 años, 5 meses
Puntos: 1
Respuesta: Como insertar codigo PHP en un cms block en magento?

Pues al principio lo hice con nombres personalizados, pero al ver que no funcionaba lo que hice fue poner los mismos nombres de ficheros y carpertas que venian en el manual.

/httpdocs/app/etc/modules/Mayerwin.xml

/httpdocs/app/code/local/Mayerwin/Custom/etc/config.xml

/httpdocs/app/code/local/Mayerwin/Custom/Block/Test.php


archivo Mayerwin.xml

Código:
<?xml version="1.0"?>
<config>
  <modules>
    <Mayerwin_Custom>
      <active>true</active>
      <codePool>local</codePool>
    </Mayerwin_Custom>
  </modules>
</config>
archivo config.xml

Código:
<?xml version="1.0"?>
<config>
  <global>
    <blocks>
      <mayerwin_custom>
        <class>Mayerwin_Custom_Block</class>
      </mayerwin_custom>
    </blocks>
  </global>
</config>
archivo Test.php

Código PHP:
<?php

class Mayerwin_Custom_Block_Test extends Mage_Core_Block_Abstract
{
  protected function 
_toHtml()
  {
     
$page_id "ejemplo11111111111";
    
$xml = @simplexml_load_file("http://api.facebook.com/restserver.php?method=facebook.fql.query&query=SEL ECT%20fan_count%20FROM%20page%20WHERE%20page_id="$page_id."") or die ("a lot");
    
$fans $xml->page->fan_count;
     return 
$fans;

     
// put here your custom PHP code with output in $html;
     // use arguments like $this->getMyParam1() , $this->getAnotherParam()
  
}
}
La llamada que utilizo desde el bloque:

Código HTML:
 {{block type="mayerwin_custom/test"}}
Así es como lo tengo,
Gracias