Search:
 
PHP Site Solutions  ::  Board index  ::  PHP Site Solutions  ::  Commercial Software  ::  XCSEO Advanced & Pro
Forum Navigation Forum Navigation



All times are UTC - 5 hours [ DST ]





Post new topic Reply to topic  [ 1 post ] 
  Print view

Extending XCSEO: automatically support custom X-Cart addons
Author Message
PostPosted: Fri Sep 05, 2008 8:03 am 
Offline
Site Admin
User avatar

Joined: Thu Apr 24, 2008 5:29 am
Posts: 34
Often I find X-Cart store owners which have had a custom module developed for X-Cart.
One such store owner, had a module developed for managing Questions & Categories.

The Questions part of the module, was stored in the database & managed in X-Cart administration, similar to normal X-Cart Products.
Similarly, the Question Categories were similar to X-Cart Categories.

URLs for each section originally look like so:
Question: question.php?qid=123
Question Category: home.php?qcat=123

While such URLs can easily be manually rewritten, using XCSEO Pro's Manual URL feature, that process is of course, very manual.
This particular store owner wanted to have the process of rewriting his URLs to be more automated (to have each url auto-generated by default), similar to how XCSEO Advanced and Pro handle Products, Categories, etc.

The solution, is to extend XCSEO's class. This process is very simple.
There are 2 files provided with each download of XCSEO Advanced or Pro, the files are called modules/PHPSS_XCSEO/local.config.php and modules/PHPSS_XCSEO/extend.xcseo.php.

When extending XCSEO for the above described scenario, your files would look like the examples provided below.
Once XCSEO has been extended properly, new sections should appear in the XCSEO Administration for each new method you've added.

modules/PHPSS_XCSEO/local.config.php:
Code:
<?php

/*    Normally the table references below are defined by X-Cart when it loads
    But XCSEO loads BEFORE X-Cart, which means it needs to know any referenced tables before-hand
*/

if( !defined('XCART_START') ){
    $sql_tbl['qcategories'] = 'xcart_qcategories';
    $sql_tbl['questions'] = 'xcart_questions';
}

?>


modules/PHPSS_XCSEO/extend.xcseo.php:
Code:
<?php

/* Define any $sql_tbl values in local.config.php, for use when XCART_START hasn't been yet defined */

/*
The following SQL queries should be executed ONCE, to add the Language defines that are used in the XCSEO Administration page
*/
/*
INSERT INTO xcart_languages (code,name,value,topic) VALUES ('US','lbl_phpss_xcseo_type_qc','Question Category','Labels');
INSERT INTO xcart_languages (code,name,value,topic) VALUES ('US','lbl_phpss_xcseo_type_q','Question','Labels');
*/

class xcseo_filter_ext extends xcseo_filter{

    function xcseo_filter_ext() {
        global $sql_tbl;

        parent::xcseo_filter();

        /* Note the value 'qc', this is a unique array key */
        /* The following keys are already in use: c, p, m, s, r */
        $this->_types['qc'] = array(
                    'callback' => 'qcategory',
                    'file' => 'home.php',
                    'admin_file' => 'qcategory_modify.php',
                    'param' => 'qcat',
                    'table' => $sql_tbl['qcategories'],
                    'title' => 'category',
                    'content' => 'description',
                    /* Normally "param" is used for querying the db table, such as for products 
                    (Ex: productid is the unique id field in the db, and also the _GET parameter). 
                    Categories, though, have 1 value for the _GET, and a different unique id value for the db table */
                    'uniqueid'    => 'catid',
                );
        $this->_types['q'] = array(
                    /* A callback method of _WHATEVER_callback() is expected. The WHATEVER part goes here */
                    'callback' => 'question',
                    /* The file in /XCART_ROOT/, which is used for displaying Question entries */
                    'file' => 'question.php',
                    /* The file in /XCART_ROOT/admin/, which is used for adding/editing Question entries */
                    'admin_file' => 'question.php',
                    /* This is the parameter found in the URL, which is the page id. 
                    Ex: productid=1234, productid would be the param, 1234 is the product id */
                    'param' => 'qid',
                    /* The Questions db table */
                    'table' => $sql_tbl['questions'],
                    /* This db field populates XCSEO's Page Title and Link Title values, and is used for generating the default URL */
                    'title' => 'question',
                    /* This is the db field that should be used to populate XCSEO's meta description value */
                    'content' => 'answer',
                );
    }

    /* Each of the methods below, are essentially just shortcuts, but are all expected/required */

    function _qcategory_filename($params) {
        return $this->_generic_filename('qc', $params);
    }

    function _question_filename($params) {
        return $this->_generic_filename('q', $params);
    }

    function _qcategory_callback($found, $uri_only = false, $title = false) {
        return $this->_generic_callback($found, 'qcat', 'qcategory', $uri_only, $title);
    }

    function _question_callback($found, $uri_only = false, $title = false) {
        return $this->_generic_callback($found, 'qid', 'question', $uri_only, $title);
    }
}

?>



Additionally, the following modification needs to be made to the Admin template file that is used for adding/modifying the new method you've added (for example, skin1/main/product_details.tpl which is used when a Product is added/modified). This modification will include the fields that XCSEO displays for modifying your URL-related entry, when you add/modify your Question, Product, whatever.

Code:
{* PHP Site Solutions - XCSEO *}
{
if $active_modules.PHPSS_XCSEO}
{
include file="modules/PHPSS_XCSEO/xcseo_admin_include.tpl"}
{/if}
{*
 END PHP Site Solutions - XCSEO *}
 



And that's it!

Using this method, you can extend XCSEO to support most X-Cart 3rd party addons automatically.
This method is geared specifically around how X-Cart normally manages Products, Categories, Manufacturers, Static Pages, etc, so anything that you want to extend XCSEO for, needs to be properly integrated with X-Cart, functioning as X-Cart normally would.
In other words, a 3rd party module that exists *separately* from X-Cart, would not function properly with XCSEO.

If you are trying to extend XCSEO, feel free to contact me with questions, I'll help you however I can!

Cheers


Top
 Profile  
 

Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


Who is online

Users browsing this forum: No registered users and 0 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Authentication Authentication


Copyright © 2006-2008 PHP Site Solutions