X

Добавление своего пункта в Export to на странице Orders

Пример на картинке (кликабельна):

app/code/community/NAMESPACE/MODULENAME/etc/config.xml

<events>
<core_block_abstract_to_html_before>
<observers>
<NAMESPACE_MODULENAME_sales_grid>
<type>singleton</type>
<class>NAMESPACE_MODULENAME/observer</class>
<method>addNewExportTypeToSalesOrderGrid</method>
</NAMESPACE_MODULENAME_sales_grid>
</observers>
</core_block_abstract_to_html_before>
</events>
</adminhtml>

 

app/code/community/NAMESPACE/MODULENAME/Model/Observer.php

public function addNewExportTypeToSalesOrderGrid(Varien_Event_Observer $observer)
{
$block = $observer->getBlock();
if($block instanceof Mage_Adminhtml_Block_Sales_Order_Grid){
/** @var $block Mage_Adminhtml_Block_Sales_Order_Grid */// namespace/modulename/ordersMyActionExportGrid = путь по которому отправятся данные, должен соответствовать нужному контроллеру и методу в нем
$block->addExportType('<code class="source">adminhtml</code>/modulename/ordersMyActionExportGrid', Mage::helper('namespace_modulename')->__('NEW ACTION'));
}

 

app/code/community/NAMESPACE/MODULENAME/controllers/Adminhtml/SOMEController.php

public function ordersMyActionExportGridAction()
{
$orderIdsParam = $this->getRequest()->getParam('internal_order_ids');
$orderIds = $orderIdsParam ? explode(',', $orderIdsParam) : null;
if (!empty($orderIds))
{
foreach($orderIds as $orderId){
$order = Mage::getModel('sales/order')->load($orderId);
Mage::helper('namespace_modulename')->exportOrder($order);
}
}
else
{
$errorMessage = Mage::helper('namespace_modulename')->__('Export orders: No selected orders');
Mage::getSingleton('adminhtml/session')->addError( $errorMessage );
}
$this->_redirect('*/*/log');
}

 

 

Категории: Magento
Тэги: adminhtml