Magento 2, Magento Development, Customization, Extension Development and Integration, Optimization, SEO and Responsive Design

Magento 2, Magento Development, Customization, Extension Development and Integration, Optimization, SEO and Responsive Design

Related product disappear after adding to Cart [Fixed]

I have noticed that after adding a product to cart, it disappears in list of related products. It's a default Magento feature that after adding an item to cart, it disappears under the related products of a specific product. If you want to still show that specific product even if already added it to cart You need to rewrite the block Mage_Catalog_Block_Product_List_Related and from the method _prepareData comment following line


It is a good practice to not change any core file. Better to over write this file in your local folder. Create directory like

/app/code/local/Mage/Catalog/Block/Product/List and copy Related.php file in this directory.

Get the Hash ( # ) value from url using jQuery or Javascript

Get the value after a hash in the URL of the current page.

var hash = window.location.hash.substr(1);

Generating Random Names With PHP

This is a short tutorial on how to generate random names with PHP. With PHP you can automatically generate random name using this script.

In this example, we have two PHP arrays. One contains a list of common names. The other contains a list of common surnames. Using the function mt_rand.



$names = array(
//PHP array containing surnames.
$surnames = array(
//Generate a random name.
$random_name = $names[mt_rand(0, sizeof($names) - 1)];
//Generate a random surname.
$random_surname = $surnames[mt_rand(0, sizeof($surnames) - 1)];
//Combine them together and print out the result.
echo $random_name . ' ' . $random_surname;

PHP Get Different Number On Page Refresh

This simple php script allow you to get different number on every page refresh. If you want to change value of your php variable on page refresh, this script will help you. Let say i have a default value 1 and want to change it for 2 on page refresh and again 2 to 1 on next page refresh.

    $_SESSION['changenumber'] = 1;
if($_SESSION['changenumber'] == 1){
    $_SESSION['changenumber'] = 2;
    $_SESSION['changenumber'] = 1;
echo $_SESSION['changenumber'];

PHP Find URLs in Text And Make Hyper Link

The basic function of this is to find any URLs in the block of text and turn them into hyperlinks.
It will only find URLs if they are properly formatted, meaning they have a www, http, https, ftp or ftps.


function textTohyperlink($text) {
    // The Regular Expression filter
    $reg_exUrl = "/((((http|https|ftp|ftps)\:\/\/)|www\.)[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,4}(\/\S*)?)/";

    // Check if there is a url in the text
    if(preg_match_all($reg_exUrl, $text, $url)) {
           // make the urls hyper links
           $matches = array_unique($url[0]);
           foreach($matches as $match) {
                $replacement = "<a href=".$match." target='_blank' rel='nofollow'>{$match}</a>";
                $text = str_replace($match,$replacement,$text);
           return nl2br($text);
    } else {
           // if no urls in the text just return the text
           return nl2br($text);

$text = "The text you want to filter goes here.";
echo textTohyperlink($text);


Copyright @ 2016 HKblog.