Store names with identical name

General Discussion about the commercial Enuuk Auction Platform
Post Reply
bamse
Posts: 220
Joined: Mon Feb 06, 2012 12:05 pm
Contact:

Store names with identical name

Post by bamse » Fri Jun 14, 2013 6:19 am

I am planning to modify code to allow store names with the same name, in the same way that different offers can have identical names.

Am I right that the only places to fix this is in class/Store::discoverId and adding store->id to all those hrefs in the templates?

...and in Action/Store.php and any other actions that use stores.

RWAP
Site Admin
Posts: 748
Joined: Fri Jan 08, 2010 2:23 am
Location: Stoke-on-Trent
Contact:

Re: Store names with identical name

Post by RWAP » Fri Jun 14, 2013 8:41 am

Yes, that is all that you would need do - it is quite a bit of work but something I wish Enuuk had done originally !!

bamse
Posts: 220
Joined: Mon Feb 06, 2012 12:05 pm
Contact:

Re: Store names with identical name

Post by bamse » Mon Jun 24, 2013 10:47 pm

The change was actually easier than expected. Below my modified class/Store->discoverId

This checks for URLs of the following types (in this order):
  • domain/store/42
    domain/store/MyStore-42
    domain/store/MyStore
I did not remove the last type of URL in order to prevent link rot. Somebody just starting a website, would not need it and could get rid of everything that follows the first "else" in below code.

Code: Select all

static public function discoverId(MyPDO $DB, $s)
    {
        if($s == 'defaultAction'){
            //No category selected
            return null;
        }elseif(intval($s) == $s && $s != 0){
            //Number (store id)
            return intval($s);
        }elseif(strlen($s)){
            $s = urldecode($s);
            $tmp = explode('-',$s);
            $id = $tmp[count($tmp)-1];
            $tmpStore = self::getInstanceFromDB($DB,$id);
            if($tmpStore instanceof self){
                unset($tmpOffer);
                return intval($id);
            }else{
                $sql = 'select id from '.self::DB_TABLE.' where name like :name limit 1';
                $query = $DB->prepare($sql);
                if( $query->execute(array(':name' => $s."%")) ){
                        $res = $query->fetch(PDO::FETCH_ASSOC);
                        unset($query);
                        return $res['id'];
                }else{
                        throw new Exception(_('Please select a valid store'),Error::BY_USER);
                }
            }
        }
        return null;
    }
Other than this I added '-'.$store->id or something like it depending on context to all the store related URL in templates in themes/default

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest