Product Upload SEO URL Enhancement

zerdnem

New member
XNullUser
Joined
Jan 30, 2022
Messages
15
Reaction score
0
Points
1
NullCash
12
SEO is the most important thing to have on a website and opencart doesn't have good SEO defaults. This will add validation to product upload.

Features
1. SEO URL is required
2. SEO URL should have no special characters and space
chrome_6Itmh0bo9B.png
XML:
<?xml version="1.0" encoding="utf-8"?>
<modification>
    <name>Product Upload SEO URL Enhancements</name>
    <version>1.0</version>
    <author>Jay Mendrez</author>
    <link>https://github.com/zerdnem</link>
    <code>seo_url_validation</code>
    <description>Product upload SEO URL validation</description>
    <file path="admin/view/template/catalog/product_form.twig">
        <operation>
            <search><![CDATA[
            {% if error_keyword[store.store_id][language.language_id] %}
            ]]></search>
            <add position="before">
                <![CDATA[
                {% if error_seo_url_empty[store.store_id][language.language_id] %}
                    <div class="text-danger">{{ error_seo_url_empty[store.store_id][language.language_id] }}</div>
                {% endif %}
                {% if error_special_chars[store.store_id][language.language_id] %}
                    <div class="text-danger">{{ error_special_chars[store.store_id][language.language_id] }}</div>
                {% endif %}
                ]]>
                </add>
        </operation>
    </file>
    <file path="admin/controller/catalog/product.php">
        <operation>
            <search><![CDATA[
            protected function validateDelete() {
            ]]></search>
            <add position="before">
                <![CDATA[
            protected function checkSpecialChars($txt) {

                return strpbrk($txt, "_ #$%^&*()+=[]';,./{}|:<>?~");

            }

                ]]>
                </add>
        </operation>
        <operation>
            <search><![CDATA[
            if (isset($this->error['keyword'])) {
            ]]></search>
            <add position="before">
                <![CDATA[
                if (isset($this->error['seo_url_empty'])) {

                    $data['error_seo_url_empty'] = $this->error['seo_url_empty'];

                } else {

                    $data['error_seo_url_empty'] = array();

                }

                if (isset($this->error['seo_special_chars'])) {

                    $data['error_special_chars'] = $this->error['seo_special_chars'];

                } else {

                    $data['error_special_chars'] = '';

                }

                ]]>
            </add>
        </operation>
        <operation>
            <search><![CDATA[
            foreach ($language as $language_id => $keyword) {
            ]]></search>
            <add position="after">
                <![CDATA[
                if (empty($keyword)) {
                    $this->error['seo_url_empty'][$store_id][$language_id] = $this->language->get('error_seo_url_empty');
                }
                ]]>
            </add>
        </operation>
        <operation>
            <search><![CDATA[
            if (count(array_keys($language, $keyword)) > 1) {
            ]]></search>
            <add position="before">
                <![CDATA[
                if ($this->checkSpecialChars($keyword)) {

                    $this->error['seo_special_chars'][$store_id][$language_id] = $this->language->get('error_special_chars');

                }

                ]]>
            </add>
        </operation>
    </file>
    <file path="admin/language/en-gb/catalog/product.php">
        <operation>
            <search><![CDATA[
            $_['error_warning']          = 'Warning: Please check the form carefully for errors!';
            ]]></search>
            <add position="before">
                <![CDATA[
                $_['error_seo_url_empty']        = 'Please add SEO URL!';
                $_['error_special_chars']    = 'SEO URL must not use spaces and special characters!';
                ]]>
            </add>
        </operation>
    </file>

</modification>
 

BuzGibi

Active member
XNullUser
Joined
Feb 18, 2021
Messages
253
Reaction score
29
Points
28
NullCash
346
Thank you for sharing! Interesting extension with great functions.
 

sozinhox1

Member
XNullUser
Joined
Jun 22, 2022
Messages
509
Reaction score
1
Points
18
NullCash
12
Thank you for sharing! Interesting extension with great functions.
 

boukafa.ayoub

Member
XNullUser
Joined
Aug 16, 2022
Messages
118
Reaction score
0
Points
16
NullCash
6
thanks for sharing this module. awesome
 
Top