Pages

Wednesday, December 12, 2012

TV image preview modx Revo

There is a bug in modx revo that in manager i can't see image preview in TV.

Solutions is :

So, following the method mentioned in the bug report, I simply changed Line 219 in core/model/phpthumb/phpthumb.class.php:

From :
$this->config_document_root = (@$_SERVER['DOCUMENT_ROOT'] ? $_SERVER['DOCUMENT_ROOT'] : $this->config_document_root);

To :
$this->config_document_root = (@$_SERVER['DOCUMENT_ROOT'] ? '/home/username/public_html' : $this->config_document_root);

and it's worked for me.

Thursday, May 10, 2012

Display product list Randomly and limited numbers in Magento HomePage

Create new file product_list.phtml and copy content from list.phtml to product_list.phtml, log in to your magento admin go to cms -> pages -> home page
paste step1 to contact area. click save.

step 1.

{{block type="catalog/product_list_random"  category_id="4" template="catalog/product/product_list.phtml"}}

now open product_list.phtml use the code below to display 4 products at once

step 2.
<?php
$_productCollection=$this->getLoadedProductCollection();
$_helper = $this->helper('catalog/output');
    if ($_productCollection->count()):
    $_productCollection = $_productCollection->getItems();

    $i = 0;
             foreach ($_productCollection as $_product):
        if ($i < 4):
                             // Product Data With CSS
        endif;
    $i++;
     endforeach;
    endif;

?>
 Now you can show your index page product list randomly with 3 limited number products.

Comment it and share it.

Wednesday, May 9, 2012

Replace default email logo in welcome email Magento

You can create a new theme and place it there. This isn't as difficult as it sounds because of the way themes fall back onto defaults in Magento. If Magento can't find something in your theme, it will fall back onto the base theme by looking in the default folder.

For example, in a store that you maintain, you uploaded your own version of the e-mail logo image in
/skin/frontend/{package}/{my-theme-name}/images/logo_email.gif
and in the Administration panel, you went to System > Configuration > Design > Themes and set Default to {your-theme-name}.

Why does this work?
In the e-mail templates, Magento specifies the src of the logo image as {{skin url="images/logo_email.gif" _area='frontend'}}. This is Magento template gibberish for "find the images/logo_email.gif in the frontend area of the current theme." So Magento looks in for /frontend/{package}/{your-theme-name}/images/logo_email.gif, finds it, and uses that path when dishing out the HTML.

If you delete your image, it doesn't break! Instead, although Magento would still first search in your theme directory as described above, it would discover that it doesn't exist and fall back onto the one in /frontend/{package}/default/images/logo_email.gif.

Good luck, and hope this helps!

Tuesday, May 8, 2012

Magento Backend user edit in account information checkboxes values show and update code

You have to customize in couple of file for showing checked value and update those checkboxes in magento backend Account Information page.

for showing checked value
app/code/core/Mage/Adminhtml/controllers/CustomerController.php

and for update checkboxes value
app/code/core/Mage/Adminhtml/Block/Widget/form.php


          else if ($inputType == 'checkbox') {
                    $customer11 = Mage::registry('current_customer');
                    if($customer11->getData($attribute->getAttributeCode()) == '1' || $customer11->getData($attribute->getAttributeCode()) != '')
                        $element->setChecked('1');
                    else if($customer11->getData($attribute->getAttributeCode()) == '0' || $customer11->getData($attribute->getAttributeCode()) == '')
                        $element->setChecked('0');
                }

set this codition in function _setFieldset in form.php file for showing your checkbox is checked or not in backend Account infomation page in magento.


            $emailprefs = array(
                'ATTRIBUTECODE1','ATTRIBUTECODE2','ATTRIBUTECODE3',...,
            );
            // Prepare customer saving data
            if (isset($data['account'])) {
                foreach($emailprefs as $pref){
                    $data['account'][$pref] = isset($data['account'][$pref]) ? 1 : 0;
                }
               
                if (isset($data['account']['email'])) {
                    $data['account']['email'] = trim($data['account']['email']);
                }
                $customer->addData($data['account']);
            }

Put this code in function saveAction() in CustomerController.php page for updating your checkboxes values in backend Account infomation page in magento. Replace 'ATTRIBUTECODE' with your checkboxes attribute codes.

Magento update checkboxes in frontend edit registration page code


app\code\core\Mage\Customer\controllers\AccountController.php
 
             /**
             * we would like to preserver the existing group id
             */
            if ($this->_getSession()->getCustomerGroupId()) {
                $customer->setGroupId($this->_getSession()->getCustomerGroupId());
            }

            /**
             * Custom coding for Promoted Update & Rented Update by Leo
             */
            if ($this->getRequest()->getParam('ATTRIBUTE_CODE')) {
                $customer->setATTRIBUTE_CODE(1);
            } else {
                $customer->setATTRIBUTE_CODE(0);
            }
            /**
             * End
             */

From this customizing user can update checkboxes values from edit registration page frontside in Magento if user has checkbox fields in registration of his magento site. Replace 'ATTRIBUTE_CODE' with your checkbox attribute code.

Thursday, May 3, 2012

Find number of total checkboxes in form or page Javascript

var formobj = document.getElementById('FORM_ID');
var counter = 0;
for (var j = 0; j < formobj.elements.length; j++)
{
    if (formobj.elements[j].type == "checkbox")
    {
        if (formobj.elements[j].checked)
        {
            counter++;
        }
    } 
}

alert('Total Checked = ' + counter);
 
This javascript is using to find number of total checkboxes in form or page and also 
user can find from all checkboxes how many is checked. In this 'FORM_ID' is the id 
of <form>.

Saturday, February 25, 2012

How to check if GD Library is installed?

Try this:

php Code: 
<?php 
if (extension_loaded('gd') && function_exists('gd_info')) {
     echo "It looks like GD is installed";  
}
?>


You could also spit some info about your GD version by doing this:

php Code: 
<?php
  echo "<pre>"; var_dump(gd_info()); echo "</pre>";
 ?>
 
You will definitely get the ans of your GD Library is installed or not.

Inserting and Updating Records Using JDatabase in Joomla

When you are doing simple single table inserts and updates you can use the JDatabase methods to do so. The advantages of using the JDatabase methods is it saves your time from hand coding sql and will escape and correctly quote your inputs for you.

The following will insert a new record into a table:

<?php 
$db = JFactory::getDBO();
//Create data object
$row = new JObject();
$row->title = 'The Title';
$row->author = 'Bob Smith';
//Insert new record into #__book table.
$ret = $db->insertObject('#__book', $row);
//Get the new record id
$new_id = (int)$db->insertid();
?>
 
This will update an existing record:
<?php
$db = JFactory::getDBO();
//Create data object
$row = new JObject();
//Record to update
$row->rec_id = 200;
$row->title = 'The Title';
$row->author = 'Bob Smith';
//Update the record. Third parameter is table id field that will be used to update.
$ret = $db->updateObject('#__book', $row,'rec_id');
?>
 
You can also use JTable to insert and update records, but requires more initial setup since you have to create a new JTable class for each table you want to modify. Using JTable is preferred if table has many fields to update from a form submit. JTable will automatically bind the form fields to corresponding table fields using the bind() method.

Here is more info on using JTable.

Tuesday, January 10, 2012

Convert Joomla 1.5 AJAX into Joomla 1.7



Joomla 1.5 AJAX Syntax

var a = new Ajax( url, {
 method: 'get',onComplete: function(){
 alert("AJAX is Working in Joomla 1.5")},
 update: element
}).request();


Joomla 1.6/1.7 AJAX Syntax

var a = new Request.HTML({
 url: url,
 method: 'get',onComplete: function(){
 alert("AJAX is Working in Joomla 1.7")},
 update: element
}).send();


Joomla 1.5 above AJAX syntax is not working in Joomla 1.7 because in Joomla 1.7 AJAX is not defined in mootools. so this perticular Joomla 1.6/1.7 AJAX syntax is properly working in Joomla 1.7 and in Joomla 1.6 also.

Convert BBCode to HTML in PHP

function bb2html($message)
        {                               
            $preg = array(
                '/(?<!\\\\)\[COLOR(?::\w+)?=(.*?)\](.*?)\[\/COLOR(?::\w+)?\]/si'   => "<span style=\"color:\\1\">\\2</span>",
                '/(?<!\\\\)\[SIZE(?::\w+)?=(.*?)\](.*?)\[\/SIZE(?::\w+)?\]/si'     => "<span style=\"font-size:\\1\">\\2</span>",
                '/(?<!\\\\)\[FONT(?::\w+)?=(.*?)\](.*?)\[\/FONT(?::\w+)?\]/si'     => "<span style=\"font-family:\\1\">\\2</span>",
                '/(?<!\\\\)\[ALIGN(?::\w+)?=(.*?)\](.*?)\[\/ALIGN(?::\w+)?\]/si'   => "<div style=\"text-align:\\1\">\\2</div>",
                '/(?<!\\\\)\[B(?::\w+)?\](.*?)\[\/B(?::\w+)?\]/si'                 => "<span style=\"font-weight:bold\">\\1</span>",
                '/(?<!\\\\)\[I(?::\w+)?\](.*?)\[\/I(?::\w+)?\]/si'                 => "<span style=\"font-style:italic\">\\1</span>",
                '/(?<!\\\\)\[U(?::\w+)?\](.*?)\[\/U(?::\w+)?\]/si'                 => "<span style=\"text-decoration:underline\">\\1</span>",
                '/(?<!\\\\)\[CENTER(?::\w+)?\](.*?)\[\/CENTER(?::\w+)?\]/si'       => "<div style=\"text-align:center\">\\1</div>",
                               
                // [email]
                '/(?<!\\\\)\[EMAIL(?::\w+)?\](.*?)\[\/EMAIL(?::\w+)?\]/si'         => "<a href=\"mailto:\\1\" class=\"bb-email\">\\1</a>",
                '/(?<!\\\\)\[EMAIL(?::\w+)?=(.*?)\](.*?)\[\/EMAIL(?::\w+)?\]/si'   => "<a href=\"mailto:\\1\" class=\"bb-email\">\\2</a>",
                // [url]
                '/(?<!\\\\)\[URL(?::\w+)?\]www\.(.*?)\[\/URL(?::\w+)?\]/si'        => "<a href=\"http://www.\\1\" target=\"_blank\" class=\"bb-url\">\\1</a>",
                '/(?<!\\\\)\[URL(?::\w+)?\](.*?)\[\/URL(?::\w+)?\]/si'             => "<a href=\"\\1\" target=\"_blank\" class=\"bb-url\">\\1</a>",
                '/(?<!\\\\)\[URL(?::\w+)?=(.*?)?\](.*?)\[\/URL(?::\w+)?\]/si'      => "<a href=\"\\1\" target=\"_blank\" class=\"bb-url\">\\2</a>",
                // [img]
                '/(?<!\\\\)\[IMG(?::\w+)?\](.*?)\[\/IMG(?::\w+)?\]/si'             => "<img src=\"\\1\" alt=\"\\1\" class=\"bb-image\" />",
                '/(?<!\\\\)\[IMG(?::\w+)?=(.*?)x(.*?)\](.*?)\[\/IMG(?::\w+)?\]/si' => "<img width=\"\\1\" height=\"\\2\" src=\"\\3\" alt=\"\\3\" class=\"bb-image\" />",
                                       
                // [list]
                '/(?<!\\\\)(?:\s*<br\s*\/?>\s*)?\[\*(?::\w+)?\](.*?)(?=(?:\s*<br\s*\/?>\s*)?\[\*|(?:\s*<br\s*\/?>\s*)?\[\/?LIST)/si' => "\n<li class=\"bb-listitem\">\\1</li>",
                '/(?<!\\\\)(?:\s*<br\s*\/?>\s*)?\[\/LIST(:(?!u|o)\w+)?\](?:<br\s*\/?>)?/si'    => "\n</ul>",
                '/(?<!\\\\)(?:\s*<br\s*\/?>\s*)?\[\/LIST:u(:\w+)?\](?:<br\s*\/?>)?/si'         => "\n</ul>",
                '/(?<!\\\\)(?:\s*<br\s*\/?>\s*)?\[\/LIST:o(:\w+)?\](?:<br\s*\/?>)?/si'         => "\n</ol>",
                '/(?<!\\\\)(?:\s*<br\s*\/?>\s*)?\[LIST(:(?!u|o)\w+)?\]\s*(?:<br\s*\/?>)?/si'   => "\n<ul class=\"bb-list-unordered\">",
                '/(?<!\\\\)(?:\s*<br\s*\/?>\s*)?\[LIST:u(:\w+)?\]\s*(?:<br\s*\/?>)?/si'        => "\n<ul class=\"bb-list-unordered\">",
                '/(?<!\\\\)(?:\s*<br\s*\/?>\s*)?\[LIST:o(:\w+)?\]\s*(?:<br\s*\/?>)?/si'        => "\n<ol class=\"bb-list-ordered\">",
                '/(?<!\\\\)(?:\s*<br\s*\/?>\s*)?\[LIST(?::o)?(:\w+)?=1\]\s*(?:<br\s*\/?>)?/si' => "\n<ol class=\"bb-list-ordered,bb-list-ordered-d\">",
                '/(?<!\\\\)(?:\s*<br\s*\/?>\s*)?\[LIST(?::o)?(:\w+)?=i\]\s*(?:<br\s*\/?>)?/s'  => "\n<ol class=\"bb-list-ordered,bb-list-ordered-lr\">",
                '/(?<!\\\\)(?:\s*<br\s*\/?>\s*)?\[LIST(?::o)?(:\w+)?=I\]\s*(?:<br\s*\/?>)?/s'  => "\n<ol class=\"bb-list-ordered,bb-list-ordered-ur\">",
                '/(?<!\\\\)(?:\s*<br\s*\/?>\s*)?\[LIST(?::o)?(:\w+)?=a\]\s*(?:<br\s*\/?>)?/s'  => "\n<ol class=\"bb-list-ordered,bb-list-ordered-la\">",
                '/(?<!\\\\)(?:\s*<br\s*\/?>\s*)?\[LIST(?::o)?(:\w+)?=A\]\s*(?:<br\s*\/?>)?/s'  => "\n<ol class=\"bb-list-ordered,bb-list-ordered-ua\">",
                                       
                //line breaks
                '/\n/'                                                               => "<br>",
                // escaped tags like \[b], \[color], \[url], ...
                '/\\\\(\[\/?\w+(?::\w+)*\])/'                                      => "\\1"
                               
            );
                               
            $message = preg_replace(array_keys($preg), array_values($preg), $message);
            return $message;
        }


// Call Function bb2html and echo

$htmltext = bb2html($message);
echo $htmltext;

Friday, January 6, 2012

Multiple Left JOIN in One SQL Query

Two Tables
1. w6h8a_community_favloc
2. w6h8a_csearchm_rides

SELECT CONCAT( (
SELECT statecode
FROM w6h8a_states
WHERE w6h8a_states.state = f1.states
), '|', f1.city, '|', f1.zip, '|', r.event_type, '|', f1.address1, '|', f2.address1, '|', '', '|', (
SELECT statecode
FROM w6h8a_states
WHERE w6h8a_states.state = f2.states
), '|', f2.city, '|', f2.zip, '|', '', '|', f1.name, '|', f2.name, '|', r.ride_name ) AS value, r.ride_name AS text
FROM w6h8a_csearchm_rides AS r
LEFT JOIN w6h8a_community_favloc AS f1 ON f1.name = r.pickup_fav_loc_name
AND f1.userid = r.user_id
LEFT JOIN w6h8a_community_favloc AS f2 ON f2.name = r.dropoff_fav_loc_name
AND f2.userid = r.user_id
WHERE r.user_id =82
GROUP BY r.id

It will not getting right output to generating value string.

Solution : 

SELECT CONCAT( (
SELECT statecode
FROM w6h8a_states
WHERE w6h8a_states.state = f1.states
), '|', f1.city, '|', f1.zip, '|', r.event_type, '|', f1.address1, '|', f2.address1, '|', '', '|', (
SELECT statecode
FROM w6h8a_states
WHERE w6h8a_states.state = f2.states
), '|', f2.city, '|', f2.zip, '|', '', '|', f1.name, '|', f2.name, '|', r.ride_name ) AS value, r.ride_name AS text
FROM (
(
w6h8a_csearchm_rides AS r
LEFT JOIN w6h8a_community_favloc AS f1 ON f1.name = r.pickup_fav_loc_name
AND f1.userid = r.user_id
)
LEFT JOIN w6h8a_community_favloc AS f2 ON f2.name = r.dropoff_fav_loc_name
AND f2.userid = r.user_id
)
WHERE r.user_id =82
GROUP BY r.id

In this you have to put two braces after FROM and complete first braces after first join and second braces after second join like this it will working perfectly.