Domanda

I'm tryng to add an admin form with no success.

To do this i use a controller. If I add this code to the controler:

public function indexAction() {

    $this->loadLayout();
    $this->_setActiveMenu('ebay_menu');
    $block = $this->getLayout()
    ->createBlock('core/text', 'example-block')
    ->setText('<h1>This is a text block</h1>');
    $this->_addContent($block);
    $this->renderLayout();
} 

it works.

But if i try to show a form doesn't:

public function indexAction() {

    $this->loadLayout();
    $this->_setActiveMenu('ebay_menu');
    $this->_addContent($this->getLayout()->createBlock('ebaysync/adminhtml_form_edit'));
    $this->renderLayout();
}

The form's blocks are:

/app/code/local/Bileamara/EbaySync/Block/Adminhtml/Form/Edit.php

class Bileamara_EbaySync_Block_Adminhtml_Form_Edit extends Mage_Adminhtml_Block_Widget_Form_Container
{

    /**
     * Constructor
     */
    public function __construct()
    {
        parent::__construct();
        $this->_blockGroup = 'ebaysync';
        $this->_controller = 'ebaysync_orders';
        $this->_headerText = Mage::helper('ebaysync')->__('Ebay Orders Paid Not Shipped');
        $this->_removeButton('back');
        $this->_removeButton('reset');
        $this->_removeButton('save');
    }

}

/app/code/local/Bileamara/EbaySync/Block/Adminhtml/Form/Edit/Form.php

class Bileamara_EbaySync_Block_Adminhtml_Form_Edit_Form extends Mage_Adminhtml_Block_Widget_Form
{
    /**
     * Preparing form
     *
     * @return Mage_Adminhtml_Block_Widget_Form
     */
    protected function _prepareLayout()
    {
        parent::_prepareLayout();
    }

    protected function _prepareForm()
    {
        $ebaystores = array('x','y');
        foreach ($ebaystores as $ebaystore){
            $userToken = Mage::helper('ebaysync')->getToken($ebaystore);
            $orders[$ebaystore] = Mage::getModel('ebaysync/api')->getSellingManagerSoldListings($userToken);
        }

        $form = new Varien_Data_Form(
            array(
                'id'     => 'edit_form',
                'action' => $this->getUrl('*/*/post'),
                'method' => 'post',
            )
        );

        $form->setUseContainer(true);
        $this->setForm($form);

        $helper = Mage::helper('ebaysync');

        //configurazione
        foreach($ebaystores as $ebaystore){

            $fieldset = $form->addFieldset('config', array(
            'legend' => $helper->__('Ebay Store: ').$ebaystore,
            'class' => 'fieldset'
            ));
            foreach ($orders[$ebaystore]->SaleRecord as $order){
                $fieldset->addField('order_ids', 'checkbox', array(
                'label' => $order->SaleRecordID,
                'name' => 'order_ids',
                'value' => $order->SaleRecordID.'*'.$order->SellingManagerSoldTransaction->OrderLineItemID
                ));
            }
        }

        return parent::_prepareForm();
    }
}

/app/code/local/Bileamara/EbaySync/etc/config.xml

<?xml version="1.0" encoding="utf-8"?>
<config>
  <modules>
    <Bileamara_EbaySync>
      <version>0.1.0</version>
    </Bileamara_EbaySync>
  </modules>
  <global>
    <bolcks>
      <ebaysync>
        <class>Bileamara_EbaySync_Block</class>
      </ebaysync>
    </bolcks>
    <models>
      <ebaysync>
        <class>Bileamara_EbaySync_Model</class>
      </ebaysync>
    </models>
    <helpers>
      <ebaysync>
        <class>Bileamara_EbaySync_Helper</class>
      </ebaysync>
    </helpers>
  </global>
  <adminhtml>
    <translate>
      <modules>
        <ebaysync>
          <files>
            <default>Bileamara_EbaySync.csv</default>
          </files>
        </ebaysync>
      </modules>
    </translate>
  </adminhtml>
  <admin>
    <routers>
      <adminhtml>
        <args>
          <modules>
            <ebaysyncadmin after="Mage_Adminhtml">Bileamara_EbaySync_Adminhtml</ebaysyncadmin>
          </modules>
        </args>
      </adminhtml>
    </routers>
  </admin>
  <frontend>
    <routers>
      <ebaysync>
        <use>standard</use>
        <args>
          <module>Bileamara_EbaySync</module>
          <frontName>ebay</frontName>
        </args>
      </ebaysync>
    </routers>
    <translate>
      <modules>
        <ebaysync>
          <files>
            <default>Bileamara_EbaySync.csv</default>
          </files>
        </ebaysync>
      </modules>
    </translate>
  </frontend>
</config>

Can anybody tell me what is wrong?

È stato utile?

Soluzione

Change

$this->_controller = 'ebaysync_orders';

to

$this->_controller = 'adminhtml_form';

In the following class:

app/code/local/Bileamara/EbaySync/Block/Adminhtml/Form/Edit.php

Another fix:

Directory name Bloacks should be Block

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