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(); 

Saturday 26 March 2016

Remove specific color/white/Black from any type of image

//header('Content-type: image/png');
$strInputFile = '20160312105210_girls.jpg';
$target = 'car_transparent.png';
$im = new Imagick($strInputFile);
//$im->paintTransparentImage($im->getImageBackgroundColor(), 0, 10000);
$im->paintTransparentImage('#000', 0, 10000); //Which color you need to remove #000
$im->setImageFormat('png');
//$im->writeImage($target);
$im->destroy();
//echo $im;

Saturday 13 February 2016

Get customer addresses with admin formated

 $order = $this->getOrder();
 $address = $order->getShippingAddress()->getFormated(true);
 echo $address;

Thursday 11 February 2016

How to display product option/variant in category page in woocommerce wordpress

<?php
/**
* woocommerce_after_shop_loop_item_title hook
*
* @hooked woocommerce_template_loop_rating - 5
* @hooked woocommerce_template_loop_price - 10
*/
do_action( 'woocommerce_after_shop_loop_item_title' );
?>
</a>
<?php do_action( 'woocommerce_after_shop_loop_item' ); ?>
with this:
<?php
/**
* ADD PRODUCT VARIABLE WITH ADD TO CART ON CATALOG PAGE
ADDED BY GW
**/
?>
<div class="catbox">
<?php
//ADD SHORT DESCRIPTION TO PRODUCT
add_action('woocommerce_after_shop_loop_item_title','woocommerce_template_single_excerpt', 5); ?>
<?php
/**
* woocommerce_after_shop_loop_item_title hook
*
* @hooked woocommerce_template_loop_rating - 5
* @hooked woocommerce_template_loop_price - 10
*/
do_action( 'woocommerce_after_shop_loop_item_title' );
?>
<?php do_action( 'woocommerce_after_shop_loop_item' ); ?>
<?php
//ADD VARIATIONS BEFORE ADD TO CART
if($product->product_type == "variable"){
woocommerce_variable_add_to_cart();
} else {
woocommerce_template_loop_add_to_cart();
}
?>
</div>

Tuesday 26 January 2016

Get Shopping cart rule coupon code SKU Magento

<?php
    $couponCode = Mage::getSingleton('checkout/session')->getQuote()->getCouponCode();
    //echo '<pre>'; print_r($productModel); echo '</pre>';
    $couponarray = array();
    if($couponCode){
        $couponarray = explode(',', $couponCode);
    }
    $rules = Mage::getResourceModel('salesrule/rule_collection')->load();
    $havecoupon = 0;
    foreach ($rules as $rule) {
        if ($rule->getIsActive()) {
            $rule = Mage::getModel('salesrule/rule')->load($rule->getId());
            $conditions = $rule->getActions()->asArray();
            foreach($conditions['conditions'] as $_conditions ):
                if($_conditions['attribute'] == 'sku' && $_item->getSku() == $_conditions['value']){
                    if(in_array($rule->getCouponCode(), $couponarray)){
                        $havecoupon = 1;
                        echo 'Yes i have '.$rule->getCouponCode();
                        ?>
                            <a href="#" onclick="javascript: $('amcoupon_code_cancel_cus').value = '<?php echo $rule->getCouponCode() ?>'; $('canceldiscount').submit(); return false;">
                                <?php echo $this->__('Cancel'); ?>
                            </a>
                        <?php
                    }
                }
            endforeach;
        }
    }
    if($havecoupon == 0){
        ?>
        <input value="" name="coupon_code" id="coupon_code_<?php echo $_item->getId() ?>" class="input-text">
        <a href="#" class="button" onclick="javascript: $('amcoupon_code_cancel_cus').value = ''; $('canceldiscount').submit(); return false;">
            <?php echo $this->__('Submit'); ?>
        </a>
        <?php
    }
    ?>

Tuesday 29 December 2015

Add Field in Account Information in magento admin panel direct database

Add field in          ---------> eav_attribute table
Add field in          ---------> customer_eav_attribute table
Add field in          ---------> customer_form_attribute table