This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* @ http://stackoverflow.com/a/12628971 */ | |
function isValidUrl($url){ | |
// first do some quick sanity checks: | |
if(!$url || !is_string($url)){ | |
return false; | |
} | |
// quick check url is roughly a valid http request: ( http://blah/... ) | |
if( ! preg_match('/^http(s)?:\/\/[a-z0-9-]+(.[a-z0-9-]+)*(:[0-9]+)?(\/.*)?$/i', $url) ){ | |
return false; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* @ http://stackoverflow.com/a/12628971 */ | |
function getHttpResponseCode_using_getheaders($url, $followredirects = true){ | |
// returns string responsecode, or false if no responsecode found in headers (or url does not exist) | |
// NOTE: could potentially take up to 0-30 seconds , blocking further code execution (more or less depending on connection, target site, and local timeout settings)) | |
// if $followredirects == false: return the FIRST known httpcode (ignore redirects) | |
// if $followredirects == true : return the LAST known httpcode (when redirected) | |
if(! $url || ! is_string($url)){ | |
return false; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$oldname = "index.html"; | |
$newname = "index.php"; | |
// checking if file exist or not. | |
if ( file_exists($oldname) && ( (!file_exists($newname))|| is_writable($newname) ) ) { | |
$renameResult = rename($oldname, $newname); | |
die($oldname . " renamed to " . $newname); | |
} else { | |
die('nothing to rename.'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
1) Create a CSV File with Before and After SKUs. | |
- In the first column, list your current SKUs and in the second column list the new SKUs. | |
- Do not include headings in your CSV file. | |
- Be sure this file is saved as a CSV file in the UTF-8 or ANSI encoding. You might run into problems with this if you create the file using Excel. | |
2) Upload the CSV file to the var/export directory on your Magento server so that it’s path is /var/export/sku2sku.csv. | |
3) Run the Script | |
+ If you run into the following error, don’t worry too much. Just re-run the script and see if more SKUs get updated. | |
- Cannot retrieve products from Magento: SQLSTATE[40001]: Serialization failure: 1213 Deadlock found when trying to get lock; try restarting transaction |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/*PHP code to: | |
1) Read / Scan any directory | |
2) Read any file | |
3) Write to any file | |
1) Read or Scan directory | |
Get all files and folders inside the directory. | |
Three ways are shown below. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Tax rate: <input id='taxrate' /> <input type='button' id='selecttable' value='Select content' /> | |
<div id='result'> | |
</div> | |
<script> | |
var fields = [ | |
'Code', 'Country', 'State', 'Zip/Post Code', | |
'Rate', 'Zip/Post is Range', 'Range From', |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Programmatically Creating a Tax Rate | |
(for the state of North Carolina(NC). You can modify it as needed to create a rate: | |
/* Helper Function for Getting a Region ID from a state code(NC) */ | |
function get_region_id_from_state($state){ | |
$region_data = Mage::getModel('directory/region')->loadByCode($state, 'NC'); | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function moveArrayKeyBefore($arr, $find, $move) { | |
if (!isset($arr[$find], $arr[$move])) { | |
return $arr; | |
} | |
$elem = [$move=>$arr[$move]]; // cache the element to be moved | |
$start = array_splice($arr, 0, array_search($find, array_keys($arr))); | |
unset($start[$move]); // only important if $move is in $start | |
return $start + $elem + $arr; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$sql = "SELECT sku FROM catalog_product_entity"; | |
$data = Mage::getSingleton(‘core/resource’) ->getConnection(‘core_read’)->fetchAll($sql); | |
if(!$data){ | |
echo 'empty'; | |
}else{ | |
foreach ($data as $data){ | |
echo $data['sku'].'Some description'; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
* create new session variable foo_data | |
* You have two options, for the session name, "frontend" for frontend session or "adminhtml" for admin session | |
*/ | |
Mage::getSingleton("core/session", array("name" => "frontend")); | |
// This will get the session of the current logged in user. | |
$session = Mage::getSingleton('customer/session'); |