SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    From downunder but sure 2 rise Hazardous's Avatar
    Join Date
    Aug 2003
    Location
    New Zealand
    Posts
    361
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Automatic cross sell feature

    I was wondering if anyone knew how to select 5 similar products automatically without adding any more fields to the database

    would it be a good idea to do a search like product name?

    i would like to end up with something similar to:

    http://www.learningexpress.com/child...V5530/proj.htm

    i am using PHP and MySQL

    one thing i don't want to have to do is make it so that every product is physically linked to 5 similar products using fK's in the database

    but i also want the 5 most similar products
    Hazardous
    My Blog

  2. #2
    SitePoint Evangelist ghurtado's Avatar
    Join Date
    Sep 2003
    Location
    Wixom, Michigan
    Posts
    591
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Since you dont want to hardcode the relationships, I would start by thinking what is it that makes 2 products related to one another. Same category? Similar text in the description? Price range? Whomever bought-this bought-that? If you can come up with the answer to this question, you are probably half way to the solution.

  3. #3
    eschew sesquipedalians silver trophy sweatje's Avatar
    Join Date
    Jun 2003
    Location
    Iowa, USA
    Posts
    3,749
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    $ghurtado->idea++;

    I was going to suggest modeling some kind of a product family attribute and randomly selecting from others in the same family, but ghurtado's suggestion covers the more general case.
    Jason Sweat ZCE - jsweat_php@yahoo.com
    Book: PHP Patterns
    Good Stuff: SimpleTest PHPUnit FireFox ADOdb YUI
    Detestable (adjective): software that isn't testable.

  4. #4
    ********* Victim lastcraft's Avatar
    Join Date
    Apr 2003
    Location
    London
    Posts
    2,423
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Hi...

    Quote Originally Posted by Hazardous
    one thing i don't want to have to do is make it so that every product is physically linked to 5 similar products using fK's in the database
    You are right to reject this option. It is a coding problem, not a core data one.

    Are the five products found by an approximate match of the data, configured by the client or detected by usage? As I don't know the answer and the algorithm will probably change anyway, I'll have a separate strategy...
    PHP Code:
    class ProductFinder extends Finder {
        ...
        function 
    findNearest($product) {
            
    $this->_findModified(
                    
    $this->findAllQuery(),
                    new 
    TableCrossSeller($product));
        }
        function &
    _findModified(&$query, &$modifier) {
            
    $modifier->addClauses($query);
            return 
    $this->findByQuery($query);
        }

    It doesn't matter whether you prefer ActiveRecord or some kind of TableGateway for your Finder/DAO as it's pretty much the same code. These days I often prefer to pass the query object around directly for data driven sites. If you are the same, then you would have something like...
    PHP Code:
    $search = &Product::findAll();
    $search->modify(new TableCrossSeller($product));
    $broker = &new Broker();
    $result = &$broker->find($search);
    ...

    class 
    Search {
        ...
        function 
    modify($modifier) {
            
    $modifer->addClauses($this->_query);
        }

    This code probably already exists for your Pager classes or whatever.

    Doing it with strategies leaves you free to experiment more. Here are some examples...
    PHP Code:
    class SimilarNameCrossSeller {
        var 
    $_name;

        function 
    SimilarNameCrossSeller($product) {
            
    $this->_name $product->getValue('name');
        }
        function 
    addClauses(&$query) {
            
    $query->like('name'substr($this->_name2) . '%');
        }
    }

    class 
    ScoreTableCrossSeller {
        var 
    $_id;

        function 
    ScoreTableCrossSeller($product) {
            
    $this->_id $product->getId();
        }
        function 
    addClauses(&$query) {
            
    $query->addJoin('near''near.id1''id');
            
    $query->mustEqual('near.id2'$this->_id);
            
    $query->orderBy('near.score');
        }

    The second assumes you have a "near" table with the ids of each related product and the score (basically a count). This table can be filled either by the promotional people or by tracking the practices of the customers.

    Is this too much or too little detail?

    yours, Marcus

    Edit: Whilst I was writing this, others have replied. Sorry about the repetition.
    Marcus Baker
    Testing: SimpleTest, Cgreen, Fakemail
    Other: Phemto dependency injector
    Books: PHP in Action, 97 things

  5. #5
    eschew sesquipedalians silver trophy sweatje's Avatar
    Join Date
    Jun 2003
    Location
    Iowa, USA
    Posts
    3,749
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by lastcraft
    Edit: Whilst I was writing this, others have replied. Sorry about the repetition.
    I would never consider it repetition when someone espouses a high-level design suggestion and you then post some workable code that people and play with

  6. #6
    From downunder but sure 2 rise Hazardous's Avatar
    Join Date
    Aug 2003
    Location
    New Zealand
    Posts
    361
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks you guy this has been a great help
    Hazardous
    My Blog


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •