Thursday, 15 September 2016

Magento programatically clear cache from particular section.


If your magento's cache is enable and for particular section your dynamically content not reflect and remains same for every category or product page  use following code.

<?php Mage::app()->saveUseCache('block_html'); ?>

If you just need to refresh one type, Bock Html OutPut for instance, you just need to use this :
$type= "block_html";
Mage::app()->getCacheInstance()->cleanType($type);

 

That's it. Hope it will help you  :)

Thursday, 11 December 2014

Export Category with it's id in magento

<?php

ini_set('memory_limit', '-1');
set_time_limit(0);
    require_once('app/Mage.php');
    umask(0);
    Mage::app('default');
    define('MAGENTO', realpath(dirname(__FILE__)));
   
$file_path =  MAGENTO . '/var/export/catwithid.csv';
$mage_csv = new Varien_File_Csv();

$products_row = array();
$products_row['0']['categoryid'] = 'categoryid';
$products_row['0']['categoryname'] = 'categoryname';




$category = Mage::getModel ( 'catalog/category' );
    $tree = $category->getTreeModel ();
    $tree->load ();
   
    $ids = $tree->getCollection ()->getAllIds ();

foreach ($ids as $id)
{

    $data['categoryid'] = $id;
   
    $data['categoryname'] =  $category->load($id)->getName();

  $products_row[] = $data;
   
}
 




    $mage_csv->saveData($file_path, $products_row);
    echo "Please find test1.csv file in your folder.....";
   
   
    ?>

Friday, 28 November 2014

password to be more secure , that includes minimum one capital latter ,one numeric character , minimum 8 characters in magento



For that i have change in Validation.js of magento

please find this code


['validate-password', 'Please enter 6 or more characters. Leading or trailing spaces will be ignored.', function(v) {
                var pass=v.strip(); /*strip leading and trailing spaces*/
                return !(pass.length>0 && pass.length < 6);
            }],

and replace it with below code


['validate-password', 'Please enter 8 or more characters.Password should contain one numeric character, one capital letter

. Leading or trailing spaces will be ignored.', function(v) {
                var pass=v.strip(); /*strip leading and trailing spaces*/
if (!(/[a-z]/i.test(v)) || !(/[0-9]/.test(v)) || !(/[A-Z]/.test(v))) {
                    return false;
                }

                return !(pass.length>0 && pass.length < 8);
            }],

Wednesday, 5 November 2014

Magento 1.8.0 and 1.8.1 issue with special price

I have fond a bug on Magento CE 1.8.0 and 1.8.1 that is related to special price.

If I set some special price on product and save that change, magento sets current date for Set Product as New from Date (news_from_date), Special Price From Date (special_from_date).

I have solved this issue.

for this issue take standard.php file in your local set up  file is in \app\code\local\Mage\Catalog\Model\Product\Attribute\Backend\standard.php



find the function  _getValueForSave($object)  and add this line,
 $object->setData('news_from_date', FALSE);

 after  if ($startDate == '' && $object->getSpecialPrice()) {

 it means
 if ($startDate == '' && $object->getSpecialPrice()) {
  $object->setData('news_from_date', FALSE);
            $startDate = Mage::app()->getLocale()->date();
        }
 . That's it . Now check.

Tuesday, 21 October 2014

MAGENTO : ONEPAGE CHECKOUT SCROLLING ISSUE.

Here i found good fix of this issue.
Open opcheckout.js and find gotoSection function and replace this function as follow.

gotoSection: function(section)
{
    var sectionElement = $('opc-'+section);
    sectionElement.addClassName('allow');
    this.accordion.openSection('opc-'+section);
    this.reloadProgressBlock(section);
    jQuery("html, body").delay(10).animate({scrollTop: jQuery("#opc-"+section).offset().top }, 1000);
},

Friday, 30 May 2014

Set user permission & role in Custom module in magento

For set user permission & role in your custom module, you have to change your custom module's ect/config.xml file
 remove these type of code
        <acl>
          <resources>
            <all>
              <title>Allow Everything</title>
            </all>
            <admin>
              <children>
                <Namespace_Contactsdetail>
                  <title>Contactsdetail Module</title>
                  <sort_order>10</sort_order>
                </Namespace_Contactsdetail>
              </children>
            </admin>
          </resources>
        </acl>
Add below Code instead of it.

        <acl>
          <resources>
            <all>
              <title>Allow Everything</title>
            </all>
            <admin>
              <children>
                <system>
                  <children>
                    <config>
                      <children>
                        <contactsdetail translate="title" module="contactsdetail">
                          <title>Contactsdetail</title>
                        </contactsdetail>
                      </children>
                    </config>
                  </children>
                </system>
                <contactsdetail>
                  <title>contactsdetail Module</title>
                  <sort_order>10</sort_order>
                  <children>
                    <items>
                      <title>Contactsdetail</title>
                      <sort_order>3</sort_order>
                    </items>
                  </children>
                </contactsdetail>
              </children>
            </admin>
          </resources>
        </acl>

Monday, 28 October 2013

Add gift options in invoice pdf in Magento

for Add gift message to Magento’s PDF packingslip you have to modified invoice.php file in (\app\code\local\Mage\Sales\Model\Order\Pdf\Invoice.php)
it is a core file ao you have to move this file in local directory
 then find getPdf($invoices = array()) function in it

before   $this->_afterGetPdf();  this line add below code in it.

/*    Draw gift options*/
                $message = Mage::getModel('giftmessage/message');
                   $oid= $item->getOrderItemId();
                  $sales =  Mage::getModel('sales/order_item')->load($oid);
           
        $gift_message_id = $sales->getGiftMessageId();
        if(!is_null($gift_message_id)) {
              $message->load((int)$gift_message_id);
              $gift_sender = $message->getData('sender');
              $gift_recipient = $message->getData('recipient');
              $gift_message = $message->getData('message');

              $page->drawText(Mage::helper('sales')->__('Message from:'), 55, $this->y, 'UTF-8');
              $page->drawText(Mage::helper('sales')->__($gift_sender), 120, $this->y, 'UTF-8');
             $this->y -=10;
              $page->drawText(Mage::helper('sales')->__('Message to:'), 55, $this->y, 'UTF-8');
              $page->drawText(Mage::helper('sales')->__($gift_recipient), 120, $this->y, 'UTF-8');
             $this->y -=15;
              $page->drawText(Mage::helper('sales')->__('Message:'), 55, $this->y, 'UTF-8');
              $page->drawText(Mage::helper('sales')->__($gift_message), 120, $this->y, 'UTF-8');
             
             // $gift_message = wordwrap($gift_message, 140, "\n", false);
              /*$token = strtok($gift_message, "\n");
              $y = 740;
              while ($token != false) {
              if ($y < 60) {
              $pdf->pages[] = ($page = $pdf->newPage(Zend_Pdf_Page::SIZE_A4));
              $page->setStyle($style);
              }
              else {
              $page->drawText($token, 40, $this->y);
              $this->y-=10;
              }
              $token = strtok("\n");
              }*/

            }
                  /*    Draw gift options end*/