ini_set('display_errors', 1);
require_once('../app/Mage.php');
Mage::app()->setCurrentStore(Mage::getModel('core/store')->load(Mage_Core_Model_App::ADMIN_STORE_ID));
/* Clear Cache */
try {
$allTypes = Mage::app()->useCache();
foreach($allTypes as $type => $cache) {
Mage::app()->getCacheInstance()->cleanType($type);
}
/**
* Flush cache storage
*/
Mage::dispatchEvent('adminhtml_cache_flush_all');
Mage::app()->getCacheInstance()->flush();
/**
* Flush all magento cache
*/
Mage::app()->cleanCache();
Mage::dispatchEvent('adminhtml_cache_flush_system');
} catch (Exception $e) {
Mage::logException($e->getMessage());
}
try {
/* cleanImages */
Mage::getModel('catalog/product_image')->clearCache();
Mage::dispatchEvent('clean_catalog_images_cache_after');
/* cleanSwatches */
Mage::helper('configurableswatches/productimg')->clearSwatchesCache();
Mage::dispatchEvent('clean_configurable_swatches_cache_after');
clearCstoreCacheDir('../var/cache');
echo 'Success';
} catch (Mage_Core_Exception $e) {
echo $e->getMessage();
} catch (Exception $e) {
echo Mage::helper('adminhtml')->__('An error occurred while clearing the configurable swatches image cache.');
}
function clearCstoreCacheDir($dirPath) {
if (!is_dir($dirPath)) {
throw new InvalidArgumentException("$dirPath must be a directory");
}
if (substr($dirPath, strlen($dirPath) - 1, 1) != '/') {
$dirPath .= '/';
}
$files = glob($dirPath . '*', GLOB_MARK);
foreach ($files as $file) {
if (is_dir($file)) {
self::deleteDir($file);
} else {
unlink($file);
}
}
rmdir($dirPath);
}
Shopify, Shopify Apps, Magento, WordPress, Codeigniter, Joomla, Big Commerce | PHP
Tuesday, 9 January 2018
Clear configurable Swatches, Images, Flush Magento ALL Cache and cache files
Tuesday, 2 January 2018
How to install extensions in php 7 cent os
Install extensions in php 7 cent os follow these steps
1. curl 'https://setup.ius.io/' -o setup-ius.sh
2. sudo bash setup-ius.sh
3. sudo yum install -y mod_php70w php70w-cli php70w-mysqlnd php70w-json php70w-gd php70w-dom php70w-simplexml php70w-mcrypt php70w-intl httpd mysql-server git
Labels:
Cent,
Cent OS,
cli,
dom,
Extensions,
Git,
httpd,
install,
Intl,
JSON,
Magento 2,
Mcrypt,
mysql-server,
mysqlnd,
PHP,
PHP 7,
simplexml
Saturday, 30 December 2017
How to download and Extract Uncompress zip / gz file from URL in PHP
ini_set('display_errors', 1);
$dbname = 'db_'.date('Ymdhis').".gz";
$url = 'http://www.domainname.com/backups/bkp30122017.gz';
file_put_contents($dbname, fopen($url, 'r'));
Extract / Uncompress GZ / ZIP file
try{
//This input should be from somewhere else, hard-coded in this example
$file_name = $dbname;
// Raising this value may increase performance
$buffer_size = 4096; // read 4kb at a time
$out_file_name = str_replace('.gz', '.sql', $file_name);
// Open our files (in binary mode)
$file = gzopen($file_name, 'rb');
$out_file = fopen($out_file_name, 'wb');
// Keep repeating until the end of the input file
while (!gzeof($file)) {
// Read buffer-size bytes
// Both fwrite and gzread and binary-safe
fwrite($out_file, gzread($file, $buffer_size));
}
// Files are done, close files
fclose($out_file);
gzclose($file);
} catch (Exception $ex) {
echo $ex->getMessage();
}
Wednesday, 27 December 2017
How to upload image / file in magento
<input type="file" name="image">
Select path of media directory
$path = Mage::getBaseDir() . DS . 'media' . DS . 'customerimages' . DS;
$imagename = $this->uploadImageFile($_FILES, $path);
Create functions
function uploadImageFile($filedata, $path){
if(isset($filedata['image']) && $filedata['image']['error'] == 0){
try{
$uploader = new Varien_File_Uploader('image');
$uploader->setAllowedExtensions(array('jpg', 'jpeg', 'gif', 'png'));
$uploader->setAllowRenameFiles(true);
if(!is_dir($path)){
mkdir($path, 0755, true);
}
$ext = pathinfo($filedata['image']['name'], PATHINFO_EXTENSION);
$uploader->save($path, date('Ymd') . "_" . date('his') . '.' . $ext);
$uploadFile = $uploader->getUploadedFileName();
if($uploadFile){
return $uploadFile;
} else {
return 'File not uploaded!';
}
} catch (Exception $e) {
return $e->getMessage();
}
} else {
return 'Please select image file!';
}
}
Tuesday, 26 December 2017
How to get product Tire / Final / Group price custom in Magento
How to get product Tire / Final / Group price custom order in Magento
$productid = 4108;
$qty = 3;
$customergroup = 1;
$_productB = Mage::getModel('catalog/product')->load($productid);
$_productB->setCustomerGroupId($customergroup);
echo $_productB->getPriceModel()->getFinalPrice($qty, $_productB);exit;
Monday, 25 December 2017
Export Big sql/mysql database using php file
Export Big sql/mysql database using php file
error_reporting(E_ALL ^ E_NOTICE);
ini_set('display_errors', 1);
ini_set('memory_limit', '512M');
$dbinfo = array(
"host" => 'localhost',
"user" => 'root',
"pass" => 'root',
"dbname" => 'dbname'
);
// Database Config
$sqlhost = $dbinfo["host"];
$dbuser = $dbinfo["user"];
$dbpassword = $dbinfo["pass"];
$dbname = $dbinfo["dbname"];
// filename
$file = date('Ymdhis');
echo shell_exec("mysqldump --add-drop-table -u $dbuser -p$dbpassword`cat /etc/psa/.psa.shadow` $dbname > $file.sql");
//shell_exec("mysql -u $dbuser --password='$dbpassword' --host='$sqlhost' $dbname < $file");
echo 'Finished!<br/>';
File Directly Open in NetBeans in Ubuntu / Linux using terminal
1. Open terminal and login with sudo su
2. Edit file using nano in terminal (Use following command)
sudo nano /usr/share/applications/netbeans-8.1.desktop
3. Change
Exec=/bin/sh "/usr/local/netbeans-8.1/bin/netbeans"
to
Exec=/bin/sh "/usr/local/netbeans-8.1/bin/netbeans" %U
Terminal=04. Press CTRL+X , than Y and Enter
to
Terminal=false
5. That't IT, Now you can see NetBeans in open with application
Ref by. Nirav Patel
Subscribe to:
Posts (Atom)