Post by Dhaupin » Tue Sep 16, 2014 12:32 am

This isnt a blackhat tool, its meant to generate SEO urls for your products that are missing them so you dont have to go through 1 by 1 and do them manually.

It seems to work on 1.5.6 but there are some errors, and also it will re-write links it thinks is improper (like with & -> and) possibly resulting in massive amounts of redirects you would have to make :) use with caution for sure and be ready to 301 so no 404 brokens

https://creadev.org | support@creadev.org - Opencart Extensions, Integrations, & Development. Made in the USA.


User avatar
Active Member

Posts

Joined
Tue May 13, 2014 3:45 am
Location - PA

Post by Dhaupin » Thu Sep 18, 2014 4:52 am

Ok tried it out. After a bit of tweaking it worked great. If anyone wants a backwoods edit for this, here is what we used:

1) commented out the "& to And" maker as to not break existing urls
2) commented out the existing url re-write (it will only make urls for products that dont have them, wont update existing)
3) added isset to the $url[0] to silence errors
4) added a dash (-) to regex - if a dash is in title it makes triple dash like various SEO js mods. This will reduce 404 if you use triple dash JS writers

Since this is a very specific use case, pm me or email dhaupin[at]creadev.org if you want this modded version.

If you just wanna fix the undefined index error, change $url[0] to isset($url[0]) and it still seems to work. Of course, always backup before you run this.

https://creadev.org | support@creadev.org - Opencart Extensions, Integrations, & Development. Made in the USA.


User avatar
Active Member

Posts

Joined
Tue May 13, 2014 3:45 am
Location - PA

Post by haydent » Tue Dec 18, 2018 5:37 am

excellent guys ! this is why i love opencart. so i just added this little line to the start of seoURL function to replace & symbols with 'and'

Code: Select all

$str = str_replace('&','and',$str);

User avatar
Active Member

Posts

Joined
Wed Nov 09, 2011 9:50 am
Location - Sydney, Australia

Post by haydent » Tue Dec 18, 2018 6:05 am

I modded this code to do the manufacturers: (also i noted if you wanted it to run faster reduce or remove the sleep commands, they are really not needed.

Code: Select all

 elseif(isset($_GET['manufacturer'])) {
        $manufacturerp    = $db->query("SELECT * FROM " . DB_PREFIX . "manufacturer");
        $manufacturerp    = $manufacturerp->rows;

        foreach($manufacturerp as $manufacturer) {

            $url = $db->query("SELECT * FROM " . DB_PREFIX . "url_alias WHERE query = 'manufacturer_id=" . (int)$manufacturer['manufacturer_id'] . "'");
            $url = $url->rows;

            if(!empty($url)) {
                echo 'Match found for ' . $manufacturer['manufacturer_id'] . '. No action taken.<br>---------------<br>';
            } else {
                echo 'URL needed for ' . $manufacturer['manufacturer_id'] . '...<br>';

                    echo 'Name: ' . $manufacturer['name'] . ' | Converting to: ' . seoURL($manufacturer['name']);
                    $manufacturer['name'] = seoURL($manufacturer['name']);
                    sleep(1);
                    $db->query("INSERT INTO " . DB_PREFIX . "url_alias SET query = 'manufacturer_id=" . (int)$manufacturer['manufacturer_id'] . "', keyword = '" . $db->escape($manufacturer['name']) . "'");
                    echo '<br>Inserted!<br>---------------<br>';

            }
        }
        echo '<br><br>All done! <a href="seo-links.php">Back</a>';

    }

Code: Select all

 echo '<p><a href="?manufacturer">Manufacturer</a> - Create information-URLs</p>';

User avatar
Active Member

Posts

Joined
Wed Nov 09, 2011 9:50 am
Location - Sydney, Australia

Post by gunberi » Fri Feb 01, 2019 12:42 am

I've updated the code for Opencart 3 and added Turkish characters

Code: Select all

<?php

require_once('config.php');
require_once(DIR_SYSTEM . 'startup.php');

// Registry
$registry = new Registry();

// Loader
$loader = new Loader($registry);
$registry->set('load', $loader);

// Database
$db = new DB(DB_DRIVER, DB_HOSTNAME, DB_USERNAME, DB_PASSWORD, DB_DATABASE);
$registry->set('db', $db);

function seoURL($str) {
    $serch = array('Ç', 'Ş', 'Ğ', 'Ü', 'İ', 'Ö', 'ç', 'ş', 'ğ', 'ü', 'ö', 'ı');
    $change = array('c', 's', 'g', 'u', 'i', 'o', 'c', 's', 'g', 'u', 'o', 'i');
    $str = strtolower(str_replace($serch, $change, $str));
    $str = preg_replace('/[^a-zA-Z0-9]+/', '-', $str);
    $str = trim($str, '-');
    $str = strtolower($str);
            
    return $str;
}

?>
<html>
    <head>
        <title>Create SEO-links</title>
    </head>
    <style type="text/css">
        body {
            font-family: "Arial";
            font-size: 12px;
        }
    </style>
    <body>
        <center>
        <h2>Script by Kartoffelz</h2>
<?php

if(isset($_GET['products'])) {
$products   = $db->query("SELECT * FROM " . DB_PREFIX . "product");
$products   = $products->rows;

foreach($products as $product) {
    
    $url = $db->query("SELECT * FROM " . DB_PREFIX . "seo_url WHERE query = 'product_id=" . (int)$product['product_id'] . "'");
    $url = $url->rows;
    
    if(!empty($url)) {
        echo 'Match found for ' . $product['product_id'] . '). No action taken.<br>---------------<br>';
    } else {
        echo 'URL needed for ' . $product['product_id'] . '. Fetching information...<br>';
        $info = $db->query("SELECT * FROM " . DB_PREFIX . "product_description WHERE product_id = '" . $product['product_id'] . "' LIMIT 1");
        $info = $info->rows;
        
        foreach($info as $data) {        
            echo 'Name: ' . $data['name'] . ' | Converting to: ' . seoURL($data['name']);
            $data['name'] = seoURL($data['name']);
            sleep(1);
            $db->query("INSERT INTO " . DB_PREFIX . "seo_url SET store_id = 0, language_id = '" .  (int)$data['language_id'] . "', query = 'product_id=" . (int)$product['product_id'] . "', keyword = '" . $db->escape($data['name']) . "'");
            echo '<br>Inserted!<br>---------------<br>';
        }
    }
}

echo '<br><br>All done! <a href="seo-links.php">Back</a>';
}
elseif(isset($_GET['categories'])) {
$categories   = $db->query("SELECT * FROM " . DB_PREFIX . "category");
$categories   = $categories->rows;

foreach($categories as $category) {
    
    $url = $db->query("SELECT * FROM " . DB_PREFIX . "seo_url WHERE query = 'category_id=" . (int)$category['category_id'] . "'");
    $url = $url->rows;
    
    if(!empty($url)) {
        echo 'Match found for ' . $category['category_id'] . '). No action taken.<br>---------------<br>';
    } else {
        echo 'URL needed for ' . $category['category_id'] . '. Fetching information...<br>';
        $info = $db->query("SELECT * FROM " . DB_PREFIX . "category_description WHERE category_id = '" . $category['category_id'] . "' LIMIT 1");
        $info = $info->rows;
        
        foreach($info as $data) {        
            echo 'Name: ' . $data['name'] . ' | Converting to: ' . seoURL($data['name']);
            $data['name'] = seoURL($data['name']);
            sleep(1);
            $db->query("INSERT INTO " . DB_PREFIX . "seo_url SET store_id = 0, language_id = '" .  (int)$data['language_id'] . "', query = 'category_id=" . (int)$category['category_id'] . "', keyword = '" . $db->escape($data['name']) . "'");
            echo '<br>Inserted!<br>---------------<br>';
        }
    }
}

echo '<br><br>All done! <a href="seo-links.php">Back</a>';
} elseif(isset($_GET['information'])) {
$informationp    = $db->query("SELECT * FROM " . DB_PREFIX . "information");
$informationp    = $informationp->rows;

foreach($informationp as $information) {
    
    $url = $db->query("SELECT * FROM " . DB_PREFIX . "seo_url WHERE query = 'information_id=" . (int)$information['information_id'] . "'");
    $url = $url->rows;
    
    if(!empty($url)) {
        echo 'Match found for ' . $information['information_id'] . '. No action taken.<br>---------------<br>';
    } else {
        echo 'URL needed for ' . $information['information_id'] . '. Fetching information...<br>';
        $info = $db->query("SELECT * FROM " . DB_PREFIX . "information_description WHERE information_id = '" . $information['information_id'] . "' LIMIT 1");
        $info = $info->rows;
        
        foreach($info as $data) {        
            echo 'Name: ' . $data['title'] . ' | Converting to: ' . seoURL($data['title']);
            $data['title'] = seoURL($data['title']);
            sleep(1);
            $db->query("INSERT INTO " . DB_PREFIX . "seo_url SET store_id = 0, language_id = '" .  (int)$data['language_id'] . "', query = 'information_id=" . (int)$information['information_id'] . "', keyword = '" . $db->escape($data['title']) . "'");
            echo '<br>Inserted!<br>---------------<br>';
        }
    }
}
echo '<br><br>All done! <a href="seo-links.php">Back</a>';
    
}
else {
    echo '<p><a href="?products">Products</a> - Create product-URLs</p>';
    echo '<p><a href="?categories">Categories</a> - Create category-URLs</p>';
    echo '<p><a href="?information">Information</a> - Create information-URLs</p>';
}

?>
</center>
</body>
</html>

Newbie

Posts

Joined
Thu Jul 03, 2014 11:14 pm
Who is online

Users browsing this forum: No registered users and 36 guests