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
"; } } }}