Friday, September 22, 2017

Magento 1: How to override Paypal Model in your custom module

Task: Need to overrite magento paypal model method in your custom module

Solution:
For example, need to override /app/code/core/Mage/Paypal/Model/Config.php  method getBuildNotationCode

Create model in your extantion

app/code/local/YourFirm/ExtName/Model/Paypal/Config.php

code:

class YourFirm_ExtName_Model_Paypal_Config extends Mage_Paypal_Model_Config
{
    public function getBuildNotationCode($countryCode = null)
    {
        ... your code here....
       // if you need, you could run base function, use: parent::getBuildNotationCode($countryCode);
    }
}


open confix.xml in your extantion
/app/code/local/YourFirm/ExtName/etc/config.xml

and add next code in global section:

and add next code in global section:
    <global>
        <models>
            <paypal>
             <rewrite>
              <config>YourFirm_ExtName_Model_Paypal_Config</config>
             </rewrite>
            </paypal>            
        </models>
    </global>

           
           
                  

how to make redirect in .htaccess for url with specific symbols


The problem was to redirect wrong CodeIgniter url with %C2%A0 symbols to another pahe in .htaccess

For example
http://mysite.com/some-page%C2%A0
to
http://mysite.com/other-page


Redirect   301    /some-page%C2%A0     /other-page   does not work

Here I had found some solution:

RewriteCond   %{THE_REQUEST}   ^[A-Z]+\ /[^%?\ ]*\%
RewriteRule    ^. http://www.example.com/     [R=301,L]

This rule redirects all matches with %.. symbols

So I had tried next:

RewriteCond   %{THE_REQUEST}   some-page[^%?\ ]*\%
RewriteRule   ^.    /other-page [R=301,L]

But after testing, it adds to now url an old url as parameters
As the results I had something like this:

http://mysite.com/index.php/other-page?/some-page/&... etc

So, after some googling I have found this

So I had changed

RewriteRule   ^.   /other-page [R=301,L]
to
RewriteRule   .?   /other-page$1? [R=301,L]


So, to make 301 redirect from broken url with % symbols need to do something like this:

RewriteCond   %{THE_REQUEST}   some-page[^%?\ ]*\%
RewriteRule   .?  /other-page$1? [R=301,L]

How to clean clean github repository

Step 1: remove all history

rm -rf .git

Step 2: reconstruct the Git repo with only the current content

git init
git add .
git commit -m "Initial commit"

Step 3: push to GitHub.

git remote add origin <github-uri>
git push -u --force origin master


https://stackoverflow.com/questions/9683279/make-the-current-commit-the-only-initial-commit-in-a-git-repository

Partial text Replace in MySQL UPDATE - example

How to make partial text Replace in MySQL UPDATE

example:

UPDATE `my_table` SET `field` = REPLACE(`field`, 'old_text', 'new_text') WHERE ... condition ...

How to catch global ajax response event (jquery or magento prototype)

//jQuery ajax
$(document).ajaxSuccess(function (event, request, settings) {
alert(22);
});

// magento prototype
Ajax.Responders.register({
   onComplete: function() {
alert('bbb');
   }
});

Magento 1: How to display customer custom attribute value for selected option in report grid

in Grid.php in method  _prepareColumns()

// get all available options for custom attribute

$options = array();

$attribute = Mage::getSingleton('eav/config')->getAttribute('customer', 'attribute_name');
if(!empty($attribute)){
$opts = $attribute->getFrontend()->getSelectOptions();

foreach($opts as $opt){
if(empty($opt['value'])) // skip empty option
continue;
$options[$opt['value']] = $opt['label'];
}
}

// now add column in grid
  
  $this->addColumn('attribute_name', array(
  'header'    => Mage::helper('customer')->__('Some Attribute Name'),
  'index'     => 'attribute_name',
  'type' => 'options',
  'options' => $options  // gere is array with all available options
  ));



P.S. to select attribute value from database, need to open collection.php model for your report and use
->addAttributeToSelect('attribute_name');

I can't provide excat example, because each report may use other classes and method. this was just an example of what function exists, you can find examples in magento to see how it works and where you can use it

How to set chmod for a folder and files separately in Linux

source:
http://stackoverflow.com/questions/3740152/how-to-set-chmod-for-a-folder-and-all-of-its-subfolders-and-files-in-linux-ubunt

I suspect what you really want to do is set the directories to 755 and either leave the files alone or set them to 644. For this, you can use the find command. For example:
To change all the directories to 755 (-rwxr-xr-x):
find /opt/lampp/htdocs -type d -exec chmod 755 {} \;
To change all the files to 644 (-rw-r--r--):

find /opt/lampp/htdocs -type f -exec chmod 644 {} \;

Restore xampp database from backup

steps: stop mysql xampp 1 - create some backup folder "data_1"  2 - from your current xampp/mysql/data folder move core folders an...