Friday, November 15, 2013

Magento – Customize Backend Order Grid to have SKU, E-mail Address, and Phone Number

Magento’s default back-end order grid doesn’t cut it.  I recently had a customer that wanted to be able to sort orders by sku, shipping address, shipping state, and customer e-mail address on their magento site.  Why did they want to do this?  To quickly generate reports I guess, who knows? By default you can’t sort by these items.  You have to add the fields to magento which can be some what tricky.
Anyway if you want to change the order grid from this:
Magento Order Grid on a Magento Web site with SKUs
To this on your magento web site:
Magento Order Grid with SKU
Just follow these few easy steps.
Step one create a new directory on your server at app/code/local/Mage/Adminhtml/Block/Sales/Order
Here we will be creating a file called Grid.php.
First navigate to app/code/core/Mage/Adminhtml/Block/Sales/Order and copy\paste Grid.php into the directory you just created.
Now open up app/code/local/Mage/Adminhtml/Block/Sales/Order/Grid.php
Look for the following:
1
2
3
4
protected function _getCollectionClass()
{
return 'sales/order_grid_collection';
}
Now change it to :
1
2
3
4
protected function _getCollectionClass()
{
return 'sales/order_grid_collection';
}
Next find:
1
2
3
4
5
6
protected function _prepareCollection()
{
$collection = Mage::getResourceModel($this->_getCollectionClass());
$this->setCollection($collection);
return parent::_prepareCollection();
}
and make it:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
protected function _prepareCollection()
{
$collection = Mage::getResourceModel($this->_getCollectionClass())
->join(
'sales/order_item',
'`sales/order_item`.order_id=`main_table`.entity_id',
array(
'skus' => new Zend_Db_Expr('group_concat(`sales/order_item`.sku SEPARATOR ",")'),
)
);

$collection->getSelect()->group('main_table.entity_id');

$collection->getSelect()->joinLeft(array('sfog' => 'sales_flat_order_grid'),
'main_table.entity_id = sfog.entity_id',array('sfog.shipping_name','sfog.billing_name'));

$collection->getSelect()->joinLeft(array('sfo'=>'sales_flat_order'),
'sfo.entity_id=main_table.entity_id',array('sfo.customer_email','sfo.weight',
'sfo.discount_description','sfo.increment_id','sfo.store_id','sfo.created_at','sfo.status',
'sfo.base_grand_total','sfo.grand_total'));

$collection->getSelect()->joinLeft(array('sfoa'=>'sales_flat_order_address'),
'main_table.entity_id = sfoa.parent_id AND sfoa.address_type="shipping"',array('sfoa.street',
'sfoa.city','sfoa.region','sfoa.postcode','sfoa.telephone'));

$this->setCollection($collection);

return parent::_prepareCollection();
}
Finally find:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
protected function _prepareColumns()
{

$this->addColumn('real_order_id', array(
'header'=> Mage::helper('sales')->__('Order #'),
'width' => '80px',
'type' => 'text',
'index' => 'sfo.increment_id',
));

if (!Mage::app()->isSingleStoreMode()) {
$this->addColumn('store_id', array(
'header' => Mage::helper('sales')->__('Purchased From (Store)'),
'index' => 'store_id',
'type' => 'store',
'store_view'=> true,
'display_deleted' => true,
));
}

$this->addColumn('created_at', array(
'header' => Mage::helper('sales')->__('Purchased On'),
'index' => 'created_at',
'type' => 'datetime',
'width' => '100px',
));

$this->addColumn('billing_name', array(
'header' => Mage::helper('sales')->__('Bill to Name'),
'index' => 'billing_name',
));

$this->addColumn('shipping_name', array(
'header' => Mage::helper('sales')->__('Ship to Name'),
'index' => 'shipping_name',
));

$this->addColumn('base_grand_total', array(
'header' => Mage::helper('sales')->__('G.T. (Base)'),
'index' => 'base_grand_total',
'type' => 'currency',
'currency' => 'base_currency_code',
));

$this->addColumn('grand_total', array(
'header' => Mage::helper('sales')->__('G.T. (Purchased)'),
'index' => 'grand_total',
'type' => 'currency',
'currency' => 'order_currency_code',
));

$this->addColumn('status', array(
'header' => Mage::helper('sales')->__('Status'),
'index' => 'status',
'type' => 'options',
'width' => '70px',
'options' => Mage::getSingleton('sales/order_config')->getStatuses(),
));
}
Change it to:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
protected function _prepareColumns()
{

$this->addColumn('real_order_id', array(
'header'=> Mage::helper('sales')->__('Order #'),
'width' => '80px',
'type' => 'text',
'index' => 'increment_id',
'filter_index' => 'sfo.increment_id',
));

if (!Mage::app()->isSingleStoreMode()) {
$this->addColumn('store_id', array(
'header' => Mage::helper('sales')->__('Purchased From (Store)'),
'index' => 'store_id',
'type' => 'store',
'store_view'=> true,
'display_deleted' => true,
));
}

$this->addColumn('created_at', array(
'header' => Mage::helper('sales')->__('Purchased On'),
'index' => 'created_at',
'filter_index' => 'sfo.created_at',
'type' => 'datetime',
'width' => '50px',
));

$this->addColumn('skus', array(
'header' => Mage::helper('Sales')->__('Skus'),
'width' => '350px',
'index' => 'skus',
'filter_index' => 'sku',
'type' => 'text',

));
$this->addColumn('shipping_street', array(
'header' => Mage::helper('sales')->__('Shipping Street'),
'index' => 'street',
'type' => 'text',
'filter_index' => 'sfoa.street',
'width' => '100px',
));
$this->addColumn('shipping_city', array(
'header' => Mage::helper('sales')->__('Shipping City'),
'index' => 'city',
'type' => 'text',
'filter_index' => 'sfoa.city',
'width' => '50px',
));
$this->addColumn('shipping_region', array(
'header' => Mage::helper('sales')->__('Shipping Region'),
'index' => 'region',
'type' => 'text',
'filter_index' => 'sfoa.region',
'width' => '50px',
));
$this->addColumn('customer_email', array(
'header' => Mage::helper('sales')->__('Customer Email'),
'index' => 'customer_email',
'type' => 'text',
'filter_index' => 'sfo.customer_email',
));

$this->addColumn('grand_total', array(
'header' => Mage::helper('sales')->__('Total'),
'index' => 'grand_total',
'filter_index' => 'sfo.grand_total',
'type' => 'currency',
'currency' => 'order_currency_code',
));

$this->addColumn('status', array(
'header' => Mage::helper('sales')->__('Status'),
'index' => 'status',
'filter_index' => 'sfo.status',
'type' => 'options',
'width' => '70px',
'options' => Mage::getSingleton('sales/order_config')->getStatuses(),
));
That is it, if you wanted to add lets say product weight you would use the following:
1
2
3
4
5
6
$this->addColumn('order_weight', array(
'header' => Mage::helper('sales')->__('Weight'),
'index' => 'order_weight',
'type' => 'text',
'filter_index' => 'sfo.weight',
));
}
Let’s say for some reason when you are doing searches in your brand new boxes and you get an error like
1
SQLSTATE[23000]: Integrity constraint violation: 1052 Column'status' in where clause is ambiguous
This means you did not add a filter type properly go back a line like this:
1
'filter_index' => 'sfo.itemname',
This should fix the error and fix your magento web site’s order grid!  Now you should be able to sort by sku, address, name, e-mail address. Shoot you can easily add the telephone number to this order grid if you want!
In case you are wondering I referenced these posted.  It took me a while to get the SKU’s to play nicely with all of the other information.

Thursday, November 14, 2013

how to create custom user passwor rest page in joomla using ajax out side joomla root folder

 hey guy this code for joomla  reset passwor page in joomla using ajax out side joomla root like old password to your own password change. custom ajax page
setp->1
create your reset component paste in your rest view page

 <script type="text/javascript" language="javascript">
  $(document).ready(function() {
      $("#driver").click(function(event){
        var currentpass=$('#oldpassword').val();
        var newpass=$('#newpass').val();
       
        var conformpass=$('#conformpass').val();
        var userid=$('#userid').val(); 
        var username=$('#username').val();
       
        if(currentpass==''){
            $('#oldpassword').addClass('invalid');
            return false;
            }else if(newpass==''){
                $('#oldpassword').removeClass('invalid');
                $('#newpass').addClass('invalid');
            return false;
                }
            else if(conformpass==''){
                $('#conformpass').addClass('invalid');
            return false;
                }
            else{
            $('#oldpassword').removeClass('invalid');
            $('#newpass').removeClass('invalid');
            $('#conformpass').removeClass('invalid');
                }
       
         $('#loading').addClass('resetloader');
          $.post(
             "http://joomla/ajaxresetpassword.php",
             { oldpass: currentpass,newpass:newpass,confirmpass:conformpass,userid:userid,username:username,},
             function(data) {
           
           
             $('#loading').removeClass('resetloader');
             if(data=='passwrod has been changed'){
                $('#oldpassword').val('');
                $('#newpass').val('');
                $('#conformpass').val('');
           
             }
                 alert(data);
                $('#stage').html(data);
             }

          );
      });
   });
   </script>
      <div id="tab2" class="tab_content">
      <form action="" method="get" name="" >
  <table width="100%" border="0" cellpadding="0" cellspacing="0">
    <tr class="tr-spac">
      <td class="left-td gray-color">Username</td>
      <td class="right-td"><?php echo $user->username;?></td>
     <input type="hidden" value="<?php echo $this->user_state->virtuemart_user_id;?>" name="userid" id="userid" />
      <input type="hidden" value="<?php echo $user->username;?>" name="username" id="username" />
    </tr>
    <tr class="tr-spac">
      <td colspan="2" class="left-td gray-color"><a href="#">Current Password</a></td>
      <td class="right-td"><input type="password" name="oldpassword" id="oldpassword" class="inputbox"  /></td>
        </tr>
    <tr class="tr-spac">
     <td colspan="2" class="left-td gray-color"><a href="#">New Password</a></td>
     <td class="right-td"><input type="password" name="newpass" id="newpass" class="inputbox"  /></td>
    </tr>
    <tr class="tr-spac" style="border-bottom:none;">
       <td colspan="2" class="left-td gray-color" style="padding-bottom:16px;"><a href="#">Confirm Password</a></td>
       <td class="right-td"><input type="password" name="conformpass" id="conformpass" class="inputbox"  /><div id="loading">&nbsp;</div></td>
    </tr>
   
    <tr >
      <td colspan="2">
     <div class="editbg" style="float:right;">
    <a href="#" id="driver" >Save</a>     
  
    </td>
    </tr>
  </table>       
  </form>
  </div>


-------------------------------------------------------------------------------------------------------

create joomla/ajaxresetpassword.php
<?php

//access joomla db and other liabray class
################################################################################
#######
define('_JEXEC',1);
define('DS', DIRECTORY_SEPARATOR );
define('JPATH_BASE', $_SERVER[ 'DOCUMENT_ROOT' ].'/joomla' );

require_once( JPATH_BASE . DS . 'includes' . DS . 'defines.php' );
require_once( JPATH_BASE . DS . 'includes' . DS . 'framework.php' );
require_once( JPATH_BASE . DS . 'libraries' . DS . 'joomla' . DS . 'factory.php' );
$mainframe =& JFactory::getApplication('site');
$db =& JFactory::getDBO();
################################################################################
#########

//get user post request
########################################################
 $currentpass          =JRequest::getVar('oldpass');   #
                                                        #
 $newpassword          =JRequest::getVar('newpass');    #
 $confirmpassword      =JRequest::getVar('confirmpass');#
 $ExistUserid          =JRequest::getVar('userid');     #
 $ExistUsername        =JRequest::getVar('username');   #
##############################################
//store temp session user id and username for check exist
###############################################
 $check_user_username   = $ExistUsername;      #
 $check_user_id         = $ExistUserid;        #
                                               #
###############################################
 //retrive user current password from database for checking
#########################################################################
##################################### 
   $TablePrefix=$db->getPrefix();
   $TableName=$TablePrefix.'users';
   $sqlquery="select password from $TableName where username='$check_user_username'  and id=$check_user_id";
 
   $db->setQuery($sqlquery);
   $result=$db->loadObject();
  

checkpassword($currentpass,$newpassword,$confirmpassword,$result->password,$check_user_id,
$TableName,$db);


//785f9b9a8385a739b05cc92105dda7ca:JtjrzbzPQNQAYWKVvORRawlV0TwaGWzm

function checkpassword(&$currentpass,&$newpass,&$confimpass,&$retrivepass,&$userid,&$TableName,&$db){
      $makepass_array = explode(':',$retrivepass);
      $joomla_pass = $makepass_array[0];
      $joomla_salt = $makepass_array[1];         
      $comparepass=md5($currentpass.$joomla_salt);
      if($joomla_pass == $comparepass)
        {
                if($newpass==$confimpass)
                {
       
                    $gnrtnewpas=md5($confimpass.$joomla_salt);           
                    $gnrtnewpas = $gnrtnewpas.':'.$joomla_salt;                   
                    $updtquery="UPDATE $TableName SET password ='$gnrtnewpas'  where id=$userid";
                    $db->setQuery($updtquery);
                    $db->query();
                    if ($db->getErrorNum())
                    { 
                        echo $db->getErrorMsg(); 
                        return false; 
                    }
          echo "passwrod has been changed";
          return true;
       
        }else{
            echo "Confirm password dose not match";
            return false;
        }
        }else
        { 
            echo "incorrect Current password ";
            return false;
        }


}

Tuesday, November 12, 2013

How to get user data in joomla root page [SOLVE]

How to get user data in joomla root page  external
 
define( '_JEXEC', 1 );
define( 'DS', DIRECTORY_SEPARATOR );
define( 'JPATH_BASE', $_SERVER[ 'DOCUMENT_ROOT' ] );
... then you need to include three files, like:
require_once( JPATH_BASE . DS . 'includes' . DS . 'defines.php' );
require_once( JPATH_BASE . DS . 'includes' . DS . 'framework.php' );
require_once( JPATH_BASE . DS . 'libraries' . DS . 'joomla' . DS . 'factory.php' );
$mainframe =& JFactory::getApplication('site');
EDIT.. ... or you can include only two files like:
require_once( JPATH_BASE . 'libraries' . DS . 'import.php' ); // framework
require_once( JPATH_BASE . 'configuration.php' ); // config file
... and finally use joomla class, like:
$db = JFactory::getDBO();

how to remove mootools jquery in joomla home page ?

please go through below. copy and paste the above joomlaheader tag.

<?php
if ($menu->getActive() == $menu->getDefault()) {
         $headData = $doc->getHeadData();
         $scripts = $headData['scripts'];
   

         //remove your script, i.e. mootools

         unset($scripts['/canvasink/media/system/js/mootools-more.js']);
         unset($scripts['/canvasink/media/system/js/mootools-core.js']);
         $headData['scripts'] = $scripts;
         $doc->setHeadData($headData);
}
         ?>

Monday, November 11, 2013

how to add new field of product in virtuemart add to cart for virtuemart_order_items and insert the new filed

Hello guys i did the custom process please follow these step

Steps 1-> create your new field on virtuemart_order_items from phpmyadmin
Steps-2>D:\xampp\htdocs\canvasink\administrator\components\com_virtuemart\tables\order_items.php

add your new field property like

var $product_customimage = NULL;


Steps-3>D:\xampp\htdocs\canvasink\administrator\components\com_virtuemart\models\orders.php
line no 1077

put your field like:
$_orderItems->product_customimage='your value';


Steps 4->D:\xampp\htdocs\canvasink\administrator\components\com_virtuemart\models\orders.php
line 200 put you filed name to select statement for retrive
like ::
$q = 'SELECT virtuemart_order_item_id, product_quantity, order_item_name,product_customimage,
    order_item_sku, i.virtuemart_product_id, product_item_price,
    product_final_price, product_basePriceWithTax, product_discountedPriceWithoutTax, product_priceWithoutTax, product_subtotal_with_tax, product_subtotal_discount, product_tax, product_attribute, order_status, p.product_available_date, p.product_availability,
    intnotes, virtuemart_category_id
   FROM (#__virtuemart_order_items i
   LEFT JOIN #__virtuemart_products p
   ON p.virtuemart_product_id = i.virtuemart_product_id)
                        LEFT JOIN #__virtuemart_product_categories c
                        ON p.virtuemart_product_id = c.virtuemart_product_id
   WHERE `virtuemart_order_id`="'.$virtuemart_order_id.'" group by `virtuemart_order_item_id`';

Friday, November 8, 2013

Why use Colliding Collations in MySQL


Colliding Collations in MySQL


Every once in a while I write a MySQL query that fails because of differing collations.  Here’s how to resolve those issues.
First, a little background.
In MySQL, each server, database, table and column can have its own character set and collation. The MySQL 5.0 manual does a terrific job of explaining character sets and collations, so we’ll let them handle that part: http://dev.mysql.com/doc/refman/5.0/en/charset-general.html.
You can see what character sets and collations your server has like so:
mysql> show character set;
+----------+-----------------------------+---------------------+--------+
| Charset  | Description                 | Default collation   | Maxlen |
+----------+-----------------------------+---------------------+--------+
| big5     | Big5 Traditional Chinese    | big5_chinese_ci     |      2 |
| dec8     | DEC West European           | dec8_swedish_ci     |      1 |
| cp850    | DOS West European           | cp850_general_ci    |      1 |
| hp8      | HP West European            | hp8_english_ci      |      1 |
| koi8r    | KOI8-R Relcom Russian       | koi8r_general_ci    |      1 |
| latin1   | cp1252 West European        | latin1_swedish_ci   |      1 |
| latin2   | ISO 8859-2 Central European | latin2_general_ci   |      1 |
| swe7     | 7bit Swedish                | swe7_swedish_ci     |      1 |
| ascii    | US ASCII                    | ascii_general_ci    |      1 |
| ujis     | EUC-JP Japanese             | ujis_japanese_ci    |      3 |
| sjis     | Shift-JIS Japanese          | sjis_japanese_ci    |      2 |
| hebrew   | ISO 8859-8 Hebrew           | hebrew_general_ci   |      1 |
| tis620   | TIS620 Thai                 | tis620_thai_ci      |      1 |
| euckr    | EUC-KR Korean               | euckr_korean_ci     |      2 |
| koi8u    | KOI8-U Ukrainian            | koi8u_general_ci    |      1 |
| gb2312   | GB2312 Simplified Chinese   | gb2312_chinese_ci   |      2 |
| greek    | ISO 8859-7 Greek            | greek_general_ci    |      1 |
| cp1250   | Windows Central European    | cp1250_general_ci   |      1 |
| gbk      | GBK Simplified Chinese      | gbk_chinese_ci      |      2 |
| latin5   | ISO 8859-9 Turkish          | latin5_turkish_ci   |      1 |
| armscii8 | ARMSCII-8 Armenian          | armscii8_general_ci |      1 |
| utf8     | UTF-8 Unicode               | utf8_general_ci     |      3 |
| ucs2     | UCS-2 Unicode               | ucs2_general_ci     |      2 |
| cp866    | DOS Russian                 | cp866_general_ci    |      1 |
| keybcs2  | DOS Kamenicky Czech-Slovak  | keybcs2_general_ci  |      1 |
| macce    | Mac Central European        | macce_general_ci    |      1 |
| macroman | Mac West European           | macroman_general_ci |      1 |
| cp852    | DOS Central European        | cp852_general_ci    |      1 |
| latin7   | ISO 8859-13 Baltic          | latin7_general_ci   |      1 |
| cp1251   | Windows Cyrillic            | cp1251_general_ci   |      1 |
| cp1256   | Windows Arabic              | cp1256_general_ci   |      1 |
| cp1257   | Windows Baltic              | cp1257_general_ci   |      1 |
| binary   | Binary pseudo charset       | binary              |      1 |
| geostd8  | GEOSTD8 Georgian            | geostd8_general_ci  |      1 |
| cp932    | SJIS for Windows Japanese   | cp932_japanese_ci   |      2 |
| eucjpms  | UJIS for Windows Japanese   | eucjpms_japanese_ci |      3 |
+----------+-----------------------------+---------------------+--------+

mysql> show collation like 'latin1%';
+-------------------+---------+----+---------+----------+---------+
| Collation         | Charset | Id | Default | Compiled | Sortlen |
+-------------------+---------+----+---------+----------+---------+
| latin1_german1_ci | latin1  |  5 |         | Yes      |       1 |
| latin1_swedish_ci | latin1  |  8 | Yes     | Yes      |       1 |
| latin1_danish_ci  | latin1  | 15 |         | Yes      |       1 |
| latin1_german2_ci | latin1  | 31 |         | Yes      |       2 |
| latin1_bin        | latin1  | 47 |         | Yes      |       1 |
| latin1_general_ci | latin1  | 48 |         | Yes      |       1 |
| latin1_general_cs | latin1  | 49 |         | Yes      |       1 |
| latin1_spanish_ci | latin1  | 94 |         | Yes      |       1 |
+-------------------+---------+----+---------+----------+---------+
FYI, the _ci, _cs and _bin endings indicate “case insensitive”, “case sensitive” and “binary”, respectively.  Binary is, perforce, case sensitive.
To see the default settings for your server, check out the variables:
mysql> show variables like 'char%';
+--------------------------+------------------------------------------------------+
| Variable_name            | Value                                                |
+--------------------------+------------------------------------------------------+
| character_set_client     | latin1                                               |
| character_set_connection | latin1                                               |
| character_set_database   | latin1                                               |
| character_set_filesystem | binary                                               |
| character_set_results    | latin1                                               |
| character_set_server     | latin1                                               |
| character_set_system     | utf8                                                 |
| character_sets_dir       | /Applications/xampp/xamppfiles/share/mysql/charsets/ |
+--------------------------+------------------------------------------------------+
8 rows in set (0.01 sec)

mysql> show variables like 'coll%';
+----------------------+-------------------+
| Variable_name        | Value             |
+----------------------+-------------------+
| collation_connection | latin1_swedish_ci |
| collation_database   | latin1_swedish_ci |
| collation_server     | latin1_swedish_ci |
+----------------------+-------------------+
3 rows in set (0.00 sec)
So, you can specify the character set and collation right down to the column.  A collation is specific to a given character set, so you can’t compare two fields from different character sets, or from different collations.  In fact, that’s where we started: MySQL rapped my knuckles for trying to compare fields with different collations.
Let’s set up a collation collision for demonstration purposes.
drop table if exists a;
create table a (
 flda1 varchar(255)
) engine=myisam collate=latin1_swedish_ci;

drop table if exists b;
create table b (
 fldb1 varchar(50) not null
) engine=myisam collate=latin1_general_ci;

insert into a values ('aaa');
insert into b values ('bbb');
So if we did a select comparing the two fields, we’d get:
mysql> select * from a, b where a.flda1 = b.fldb1;
ERROR 1267 (HY000): Illegal mix of collations (latin1_swedish_ci,IMPLICIT) and (latin1_general_ci,IMPLICIT) for operation '='
mysql>
Great. Now, to fix it, we want to set the collation of table b to latin1_swedish_ci.  You’ll note that getting a “show create table b”, produces the following DDL script:
CREATE TABLE `b` (
  `fldb1` varchar(50) collate latin1_general_ci NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci
Clearly we’ll need to change both the table and the field’s collations:
alter table b
character set latin1 collate latin1_swedish_ci,
modify column fldb1 varchar(50) character set latin1 collate latin1_swedish_ci NOT NULL
You can see the syntax for alter at http://dev.mysql.com/doc/refman/5.0/en/alter-table.html.  After which we get a create script of:
CREATE TABLE `b` (
  `fldb1` varchar(50) NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1
And now, when we execute the select script:
mysql> select * from a, b where a.flda1 = b.fldb1;
Empty set (0.20 sec)