Friday, October 29, 2010

Magento: Get url stores

$stores = Mage::getModel('core/store')->getCollection();
foreach(  $stores as $store ){
            $url = Mage::getModel('core/url') ->setStore($store)->getUrl('');
            echo $url."\n";
}

Magento: Request to do in case of duplication in the flat catalog

SELECT entity_id, count( * )
FROM catalog_category_flat_store_x
GROUP BY entity_id
ORDER BY count( * ) DESC
LIMIT 0 , 30

PHP: 301 redirect

<?
Header( "HTTP/1.1 301 Moved Permanently" );
Header( "Location: http://www.new-url.com" );
?>

Wednesday, October 27, 2010

fileclass: cannot open '/etc/mail/local-host-names sendmail

fileclass: cannot open '/etc/mail/local-host-names sendmail
problem

sendmail is not working. Giving the error '/etc/mail/sendmail.cf: line 91: fileclass: cannot open '/etc/mail/local-host-names': World writable directory'.

Solution

1). Edit the file /etc/mail/sendmail.cf and add -o ('oh') to line 91 and 588 that is change Fw/etc/mail/local-host-names to Fw-o /etc/mail/local-host-names.

2). Similarly edit /etc/mail/submit.cf and add -o to line 544( i think it may differ) that is change Ft/etc/mail/trusted-users to Ft-o /etc/mail/trusted-users.

3). save both files and restart sendmail

Tuesday, October 26, 2010

Centos: Restore Root password

1. Start your computer
2. At the GRUB prompt, choose the line on your linux and press e
3. Select the second line (the one that starts with kernel ...) with the cursor and press e again to edit it also.

4. Go to the end of the line and add the word single (this also works with the letter s or the number 1 on most distributions, the choice is yours)

5. Press b to boot with these new parameters

The system will boot into single user mode and offer you a command prompt as root without asking any password.

You can then choose a new password and reboot the
computer.

Wednesday, October 20, 2010

Magento: Use Filter template

            $filter = Mage::getModel('core/email_template_filter');
            $vars = array( 'value'=>'toto');
            $filter->setVariables( $vars );
            $filterdResult = $filter->filter( '  Text Text Text Text Text {{var value}} Text Text Text Text   ' );

Tuesday, October 19, 2010

Magento: .htaccess 301 Redirect

Redirect 301 /oldpage.html http://www.yoursite.com/redirectpage.html
Redirect 301 /redirectpage2.html http://www.yoursite.com/folder/

Magento: RESET MAGENTO FILE PERMISSIONS VIA SSH

find . -type f -exec chmod 644 {} \;
   find . -type d -exec chmod 755 {} \;
   chmod o+w var var/.htaccess includes includes/config.php app/etc
   chmod 550 pear
   chmod -R o+w med

Magento : How to show cart total

<?php getQuote();
$total = $quote->getGrandTotal();
// format total in order to have a user friendly price
$total = $this->helper('checkout')->formatPrice($total); ?>

Monday, October 18, 2010

Function to download file with Magento

In the controller use this function

    protected function _sendFile($pdfPath) {
        if (! is_file ( $pdfPath ) || ! is_readable ( $pdfPath )) {
            throw new Exception ( );
        }
        $this->getResponse ()
                    ->setHttpResponseCode ( 200 )
                    ->setHeader ( 'Pragma', 'public', true )
                    ->setHeader ( 'Cache-Control', 'must-revalidate, post-check=0, pre-check=0', true )
                    /* View in browser */
                    //->setHeader ( 'Content-type', 'application/pdf', true )
                    /*  Download */
                    ->setHeader ( 'Content-type', 'application/force-download' )
                    ->setHeader ( 'Content-Length', filesize($pdfPath) )
                    ->setHeader ('Content-Disposition', 'inline' . '; filename=' . basename($pdfPath) );
        $this->getResponse ()->clearBody ();
        $this->getResponse ()->sendHeaders ();
        readfile ( $pdfPath );
        //exit(0);
    }

The passed parameter is the path of the File ( here i used this function to download a PDF file )

Friday, October 15, 2010

Instalers: CGV Model

This instaler is used to create a new CGV ( General Sales Conditions ) : 
 
$text = <<<TXT

text here

TXT;


$model = Mage::getModel('checkout/agreement');
$model->setName ();
$model->setContent ( $text );
//$model->setContentHeight ();
$model->setCheckboxText ();
$model->setIsActive (1);
$model->setIsHtml (1);

$model->save();

[URL] Current and home Url

To get the current url with his parameters use: 
Mage::helpet('core/url')->getCurrentUrl()

Fo the home, use: 
Mage::helpet('core/url')->getHomeUrl()


Tuesday, October 12, 2010

Show / Hiden rows of table (Jquery)

For show hidden rows of a table, the toggle function of Jquery freamwork can be used like this
    jQuery(".link-view").toggle(
              function () {
                   // Show treatment
              },
              function () {
                  // hidden treatment
              }
    );

Powered by Blogger.