Monday, 11 April 2016

Today's/Month sales report on admin dashboard in magento

The sales report is one of the main progress indicators in e-commerce. We often create a sales report using the default Magento features – just go to Reports -> Sales -> Orders, and then, fill in the filter form on that page. This way allows us to get full information about sales on the web store.

Nevertheless, getting back to all these actions every time is not handy, especially if we do not need the full report. So, let’s find out how to display the reports in different parts in the admin panel.

First of all, we add a part of the code that will display our report on the dashboard in the admin panel – so, to do this place the following code snippet to
[Magento root]/app/design/adminhtml/default/default/template/dashboard/index.phtml:

<div class="entry-edit cmsdas-1 todaysale">
                <div class="cms-entry-edit-head">
                <div class="lifetime-sales"><?php echo "Today's sales"  ?></div>
                    <div class="cms-va">
                        <span class="price"><?php echo Mage::helper('NAMESPACE_MODULE/todaysale')->getTotals();?></span>
                    <span style="font-size:14px; color:#686868;">
                    </span>
                    </div>
                </div>
            </div>
In this code snippet we have a standard markup and use custom helper Mage::helper('NAMESPACE_MODULE/todaysale')->getTotals(). In this case, the helper returns an information about the report.

Pay attention to the code helper which generates information about the report. Here are several methods that build the report.

class NAMESPACE_MODULE_Helper_Todaysale extends Mage_Core_Helper_Abstract {
    public function getTotals() {
       
        $isFilter= '';
        $todaysales = Mage::getResourceModel('reports/order_collection')
            ->calculateSales($isFilter);
        $todayStartOfDayDate  = Mage::app()->getLocale()->date()
            ->setTime('00:00:00')
            ->toString(Varien_Date::DATETIME_INTERNAL_FORMAT);
        //$todayStartOfDayDate ='2016-04-7 00:00:00';
        $todayEndOfDayDate  = Mage::app()->getLocale()->date()
            ->setTime('23:59:59')
            ->toString(Varien_Date::DATETIME_INTERNAL_FORMAT);
       
        $todaysales->addAttributeToFilter('created_at', array(
            'from'  => $todayStartOfDayDate,
            'to'    =>  $todayEndOfDayDate,                  
        ));
        $todaysales->load();
        $todaysale = $todaysales->getFirstItem();
        //$this->addTotal($this->__("Today's Sales"), $todaysale->getLifetime());
        return (string)Mage::helper('core')->currency($todaysale->getLifetime(), true, false);
    }
}

Enable template path hint in admin Panel - Magento

There are two ways to enable admin panel path hints.

1.
You can enable template and block path hints in every store (including the admin store) by setting them in the Magento configuration. To do this, simply edit your module's configuration file app/etc/config.xml (which gets injected into Magento's global configuration).

To enable template and block path hints in the admin area add this to your app/etc/config.xml file
<config>

    ...

    <stores>
        <admin>
            <dev>
                <debug>
                    <template_hints>1</template_hints>
                    <template_hints_blocks>1</template_hints_blocks>
                </debug>
            </dev>
        </admin>
    </stores>
</config>
To disable path hints simply change to 0, or delete the node.

2.

You can do it by changing the database directly. If you have something like phpMyAdmin that is a good way to gain access. Enter this SQL.

INSERT INTO `core_config_data` (`scope`, `scope_id`, `path`, `value`)
       VALUES ('websites', '0', 'dev/debug/template_hints', '1');

When you are done with path hints just delete the matching record from core_config_data Or update the value field to 0 instead of deleting the whole record, it will probably be the last one since you've just added it.

Saturday, 9 April 2016

How to get last week' date range in PHP, Codeigniter, CakePHP

$previous_week = strtotime("-1 week +1 day");
$start_week = strtotime("last sunday midnight",$previous_week);
$end_week = strtotime("next saturday",$start_week);
$start_week = date("Y-m-d",$start_week);
$end_week = date("Y-m-d",$end_week);
echo $start_week.' '.$end_week ;

Monday, 4 April 2016

How to add 00 after a number in php

$value = 100.25;
echo number_format($value, 2);

Curl automatically display the result? / Without print, response is displayed me in CURL php

By default, the curl extension prints out the result.
You need to enable the CURLOPT_RETURNTRANSFER option, like so:

curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);

After that option is enabled, curl_exec will return the result, instead.

Thursday, 31 March 2016

How to create import functionality on grid page in magneto


Open Grid.php
protected function _prepareMassaction()
    {
..................
..................
//Upload your csv file into var/import directory
$dir = new DirectoryIterator(Mage::getBaseDir() . DS . 'var' . DS . 'import' . DS);
$extensions = "csv";
$csv = array();
foreach ($dir as $fileinfo) {
    if ($fileinfo->isFile() && stristr($extensions, $fileinfo->getExtension())) {
        $csv[$fileinfo->getFilename()] = $fileinfo->getFilename();
    }            
}
$csv = array_merge(array(''=>'Please select'),$csv);
$this->getMassactionBlock()->addItem('import', array(
    'label'        => Mage::helper('metizsoft_taxgenerate')->__('Import'),
    'url'          => $this->getUrl('*/*/massCsv', array('_current'=>true)),
    'confirm'  => Mage::helper('metizsoft_taxgenerate')->__('Are you sure?'),
    'additional'   => array(
        'subgroup'    => array(
            'name'     => 'csv',
            'type'     => 'select',
            'class'    => 'required-entry',
            'label'    => Mage::helper('customer')->__('Select Csv'),
            'values'   => $csv
        )
    )
));
return $this;
}

Open your controller file. and put this code.public function massCsvAction()
{
$csvfile = $this->getRequest()->getParam('csv');
if (!$csvfile) {
  Mage::getSingleton('adminhtml/session')->addError(
      Mage::helper('metizsoft_taxgenerate')->__('Please select statetaxs.')
  );
} else {
  try {
     $csv = new Varien_File_Csv;
     $csvpath = Mage::getBaseDir() . DS . 'var' . DS . 'import' . DS . $csvfile;
             
     $datas = $csv->getData($csvpath);
     print_r($datas);
   } catch (Mage_Core_Exception $e) {
     Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
   } catch (Exception $e) {
     Mage::getSingleton('adminhtml/session')->addError(
        Mage::helper('metizsoft_taxgenerate')->__('There was an error updating statetaxs.')
     );
     Mage::logException($e);
   }
}
$this->_redirect('*/*/index');
}

Monday, 28 March 2016

How to get Controller, Action/Function/Method, URL informations in CodeIgniter PHP

You could use the URI Class:
$this->uri->segment(n); // n=1 for controller, n=2 for method, etc
You can also use this in-built functions of codeigniter.
$this->router->fetch_class();
$this->router->fetch_method();