Web Analytics Made Easy -
StatCounter Class of classes - CodingForum

Announcement

Collapse
No announcement yet.

Class of classes

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Class of classes

    I am producing a shopping cart system for a friends gallery web site. I have produced a class for products so when the user adds a product it will create a new class from the data about that product. That class then needs to be set as session data. How do I allow multiple classes to added to an order?
    Do I need a order class? Is there such thing as a class of classes (oder class of product classes)? Or do I need an array of product classes.

    So here is the class so far:

    PHP Code:
    <?PHP

    Class item_class{
    // a class to add the items to session
        
    var $cat;  //category of picture
        
    var $subcat;  // sub category of picture
        
    var $product;  //product identifier
        
    var $title;  //title of artwork
        
    var $pic_cat;  //legend for category and sub cat
        
    var $frame;  // the frame style 
        
    var $dims;  //dimesions of product
        
    var $price;  //price fo product
        
    var $img_link;  //link to the gallery image
        
    var $txt_link;  //link to the gallery description text file


        
    function add_to_order(){
        
    //add whole product to the order

        
    }

        function 
    add_frame(){
        
    // add the picture frame part to a customisable commision order

        
    }

        function 
    add_picture(){
        
    // add the picture part to a customisable commision order

        
    }
    }
    ?>
    Any advice would be greatly apprecited here.

    Thanks
    You can not say you know how to do something, until you can teach it to someone else.

  • #2
    i could set up an online shop for your friend, pm me an offer!

    Comment


    • #3
      I'm not sure what the exact needs are, but you maybe under-utilizing object-oriented programming.

      If all of your products will have the same properties, like size, weight, color, etc, then you create a class that has all of those properties. When someone adds a new product, you create an instance of the product class. This is an object. You then assign to the object all the properties of the new product.

      There's no need for extra classes unless you plan on creating new products with completely new properties that don't fit into a mold. Even then, if they are few and far between, you could provide an associative array that stores all the extra properties and their values, and still only need on product class.

      I hope this helps you somewhat, like I said, I have no idea what your OO experience is like. If you have more questions, just ask.

      Comment


      • #4
        I think i get it

        Thanks, So something like this

        PHP Code:

        <?PHP

        Class item_class{
        // a class to add the items to session
            
        var $cat;
            var 
        $subcat;
            var 
        $product;
            var 
        $title;
            var 
        $pic_cat;
            var 
        $frame;
            var 
        $dims;
            var 
        $price;
            var 
        $img_link;
            var 
        $txt_link;
            var 
        $add;


            function 
        add_to_order(){
            
        //add whole product to the order
                
        $this->add="whole";
                
        $_SESSION[$this->product]=$this->item_class;
            }

            function 
        add_frame(){
            
        // add the picture frame part to a customisable commision order
                
        $this->add="frame";
                
        $_SESSION[$this->product]=$this->item_class;
            }

            function 
        add_picture(){
            
        // add the picture part to a customisable commision order
                
        $this->add="picture";
                
        $_SESSION[$this->product]=$this->item_class;
            }
        }
        ?>
        The idea here is to add the whole class object to the session data where the identifier to that session object is the classes product. Is this what you mean. Or do I have to make a seperate associative array and assing that to a $_SESSION["cart"] or soemthing?
        You can not say you know how to do something, until you can teach it to someone else.

        Comment


        • #5
          It would be more like:

          Code:
          #....your class definition here...
          $newProduct = new Product();
          $newProduct->title = 'New Title';
          $_SESSION['myNewProduct'] = $newProduct;
          Now, if you want to carry multiple products in the session, then you'll have to store with different keys or you'll have to store an array with your objects in it.

          Does that answer your question?

          Comment


          • #6
            So I need to get rid of my class functions and add the new class to the session outside of the class. So something like this?

            PHP Code:
            <?PHP

            Class item_class{
            // item class declaration
                
            var $cat;
                var 
            $subcat;
                var 
            $product;
                var 
            $title;
                var 
            $pic_cat;
                var 
            $frame;
                var 
            $dims;
                var 
            $price;
                var 
            $img_link;
                var 
            $txt_link;
                var 
            $add;
            }

            //create new class
            $item=new item_class();

            // GET the form data and store in new class
            $item->cat=$_GET['cat'];
            $item->subcat=$_GET['subcat'];
            $item->product=$_GET['product'];
            $item->title=$_POST['title'];
            $item->pic_cat=$_POST['cat'];
            $item->frame=$_POST['frame'];
            $item->dims=$_POST['dims'];
            $item->price=$_POST['price'];
            $item->img_link=$_POST['img_link'];
            $item->txt_link=$_POST['txt_link'];
            $item->add=$_GET['add'];

            //store class in session variable
            $_SESSSION[$item->product] = $item;
            I think this is working it seems to be storing something, problem is I have no idea how to retirve it again when they are ready to checkout. Any ideas?
            Thanks again....
            Last edited by timgolding; Sep 29, 2006, 06:19 AM. Reason: speeling and grammer
            You can not say you know how to do something, until you can teach it to someone else.

            Comment


            • #7
              Hi again here is the output of the SESSION data when i just added a few instances to the SESSION and echoed $_SESSION.


              Array ( [pinman_1.txt] => __PHP_Incomplete_Class Object ( [__PHP_Incomplete_Class_Name] => item_class [cat] => pinmen [subcat] => sports [product] => pinman_1.txt [title] => Runner [pic_cat] => PMPS [frame] => Paper Maché News Paper [dims] => W 30cm x H 40cm [price] => £40 [img_link] => ./Gallerys/listed/pinmen/sports/pinman_1.jpg [txt_link] => ./Gallerys/listed/pinmen/sports/pinman_1.txt [add] => frame ) [pinman_11.txt] => __PHP_Incomplete_Class Object ( [__PHP_Incomplete_Class_Name] => item_class [cat] => pinmen [subcat] => sports [product] => pinman_11.txt [title] => Runner [pic_cat] => PMPS [frame] => Paper Maché News Paper [dims] => W 30cm x H 40cm [price] => £40 [img_link] => ./Gallerys/listed/pinmen/sports/pinman_11.jpg [txt_link] => ./Gallerys/listed/pinmen/sports/pinman_11.txt [add] => whole ) )

              What does " __PHP_Incomplete_Class Object ( [__PHP_Incomplete_Class_Name]" mean. Im scared
              You can not say you know how to do something, until you can teach it to someone else.

              Comment


              • #8
                dude, just get your friend to pay me to do it, will be much quicker

                Comment


                • #9
                  Originally posted by rafiki View Post
                  dude, just get your friend to pay me to do it, will be much quicker
                  NO..............
                  You can not say you know how to do something, until you can teach it to someone else.

                  Comment


                  • #10
                    ok ifne, then may i recommend zencart

                    Comment


                    • #11
                      The incomplete class name is due to you not having included the class definition before the session gets initialised- PHP sees the object and it's properties, but it doesn't know what it should do with it.
                      to fix the problem, include the file that contains the code for the class before you call session_start();
                      My thoughts on some things: http://codemeetsmusic.com
                      And my scrapbook of cool things: http://gjones.tumblr.com

                      Comment


                      • #12
                        Thank you Beagle and GJay you have both been extremely useful. This was my fisrt attempt at OO programming in PHP and it was a great learing experience. I'm pretty sure I have everything I need to finish my scripts now Thanks again
                        You can not say you know how to do something, until you can teach it to someone else.

                        Comment

                        Working...
                        X