Magento 2, Magento Development, Customization, Extension Development and Integration, Optimization, SEO and Responsive Design

Magento 2, Magento Development, Customization, Extension Development and Integration, Optimization, SEO and Responsive Design

How to call custom module's phtml file into core phtml file of magento

This basic question for many people that how to call core phtml file into custom module. Before few days i have no answer. But today i have. If you want to call any custom file into for custom module's phml file you can do it as following.

In this example i call core list.phml into my custom module file.

<catalog_category_layered translate="label">
        <reference name="product_list">
            <action method="setTemplate">
                <template>customoption/customoption.phtml</template>
            </action>
        </reference>
</catalog_category_layered>

See how it works. customoption is my module name and customoption.phtml is my module phml file. And i replaced my default magento list.phml file with my module's phtml file. So suppose if you open your list page it will saw what ever in my customoption.phtml.


How to Create CSV files in Magento

If you want to create downloadable csv of you ordered item's you can use following script.

$orders = Mage::getModel("sales/order")->getCollection();
// prepare CSV header
$csv = '';
$_columns = array(
     "Order Id",
     "Product Name",
     "Sku",
     "Price"
);
$data = array();
// prepare CSV header...
foreach ($_columns as $column) {
       $data[] = '"'.$column.'"';
}
$csv .= implode(',', $data)."\n";
foreach ($orders as $order) {
         $items = $order->getAllItems();
         foreach ($items as $item) {
               $loadProduct = Mage::getModel('catalog/product')->load($item->getProductId());
               //prepare csv contents
                $data = array();
                $data[] = $order->getId();
                $data[] = $loadProduct['name'];
                $data[] = $loadProduct['sku'];
                $data[] = $loadProduct['price'];

                $csv .= implode(',', $data)."\n";
               //now $csv varaible has csv data as string
    }
}
     
$this->_redirect('*/*/');
$this->_prepareDownloadResponse('file.csv', $csv, 'text/csv');

 

Copyright @ 2017 HKBlog.