Tuesday, July 23, 2013

Using CURL to get XML

if you have an IP restricted XML service you can put this script on the server to reflect the xml :


<?php
header("Content-type: text/xml");
function get_data($url) {
    $ch = curl_init();
    $timeout = 5;
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
    $data = curl_exec($ch);
    curl_close($ch);
    return $data;
}
echo get_data("YOUR XML URL");
?>

Java and php integration

If you need Java integration in PHP 5 +, there is the Java bridge of Zend Server:

  http://www.zend.com/en/products/server-ce/
 


or use the following  "PHP/Java Bridge":

  http://php-java-bridge.sourceforge.net/pjb/

Solve sohosin problems with cpanel

Solve sohosin problems with cpanel:

# remove suhosin from easyapache php config
/usr/local/cpanel/scripts/phpextensionmgr uninstall PHPSuHosin
# download and install older suhosin
wget http://download.suhosin.org/suhosin-0.9.31.tgz
tar zxf suhosin-0.9.31.tgz
cd suhosin-0.9.31
phpize
./configure
make
make install
#open php.ini and add line loading suhosin
vi /usr/local/lib/php.ini
and paste following line into section where you add extensions
extension=”suhosin.so”

Friday, June 14, 2013

get Store currency code And symbol in magento

to do this you need to select your store number first , the default store is number 1 so we will say : $S_id = 1 ;

//store id
$S_id = 1 ;

// gets currency code:

$C_Code = Mage::app()->getStore($S_id)->getCurrentCurrencyCode(); 

//gets  Currency Symbol 
$C_Symbol = Mage::app()->getLocale()->currency($C_Code)->getSymbol(); 


Thursday, June 13, 2013

Add increment decrement button to Magento quantity field in Cart

well its kinda cool to have increment decrement buttons for your qty field in cart view Maybe by the chance somebody tempt to increase the Qty . lol :)

all you need to do is open the file  : app/design/frontend/default/YOUR_TEMPLATE_NAME/template/checkout/cart/item/default.phtml

search code for this line :


change it with :
     
        
  
you can chose yor favorte color by changing style="color:magenta to whatever you want
now we need to find these file : app/design/frontend/default/YOUR_TEMPLATE_NAME/template/checkout/cart.phtml
and add the following JS to end of the file :
 
 




there you go guys !!!!


PHP code to replace string in a file or multiple files in remote server

If you need to replace any string on series of files on your remote server and well you don't have time for it! , here is your solution , I hope it can help someone.

 ////
 //PHP 5.3 + Class find and replace string in files
 //
 //by Bruce Afruz 
 //
 //2013
 //
 //example usage for single file:
 //
 //$new = new fileReplacement('./');
 //$new->setExt("check.php");
 //$new->changeContents("hello", "goodbye");
 //
 //example usage for multiple files:
 //
 //$new = new fileReplacement('./test');
 //$new->setExt("*.html");
 //$new->changeContents("hello", "goodbye");
 //
 //to change directory:
 //
 //$new = new fileReplacement('./test');
 //$new->setDir("./test2");
 //$new->setExt("*.html");
 //$new->changeContents("hello", "goodbye");
 ////


 class fileReplacement 
 {
  private $ext , $dir ;
  public function getDir() {
   return $this->dir;
  }
  public function setDir($dir) {
   $this->dir = $dir;
  }
   public function getExt() {
   return $this->ext;
  }
  public function setExt($ext) {
   $this->ext = $ext;
  }
 function __construct($dir) {
   $this->dir = $dir;
  }

  public function rglob($pattern = '*', $flags = 0, $path = '') {

  chdir($this->getDir());
  $paths = glob($path . '*', GLOB_MARK | GLOB_ONLYDIR | GLOB_NOSORT);
  $files = glob($path . $pattern, $flags);
  foreach ($paths as $path) {
  $files = array_merge($files, $this->rglob($pattern, $flags, $path));
  }
  return $files;
 }

 public function changeContents($replace , $sentence , $flags = 0, $path = '') {
 $all = $this->rglob($this->getExt() , $flags, $path);
 foreach ($all as $file) {

  $filename = $file;
  $handle = fopen($filename, "r");
  $contents = fread($handle, filesize($filename));
  fclose($handle);
  $contents = str_replace($replace , $sentence, $contents);

  if (is_writable($filename)) {
   if (!$handle = fopen($filename, 'w+')) {
    echo "Cannot open file ($filename)
"; exit; } // Write $contents to our opened file. if (fwrite($handle, $contents) === FALSE) { echo "Cannot write to file ($filename)
"; exit; } echo "Success, wrote content to file ($filename)
"; fclose($handle); } else { echo "The file $filename is not writable
"; } } }}