I know there are shopping carts out there such as oscommerce and a few others that I saw on the code snippet section. But those may not work the way I need something to work (which is really quite simplistic...i think), so if you have a moment, I will explain what I am trying to do.

We have a b2b website where customers order products in large quantites with quantity breaks (100, 250, 500, 1000 pieces, etc) and I need a cart where this is easy to do. Also, in my business, orders are so custom, the final price (of course approved by the customer) is often not even what the customer sees on the website. Perhaps the customer wants various prints on the product, additional colors, etc, and as such, the total of the cart they send us is not that important. Further, it is NOT important to us that they send payment with the cart.

If i didn't care about the website being cheesy, I could simply have a "Place Order" button on each product page which then goes to a form, which will mostly be pre-filled out based on what product they chose (all from the database), and then the customer would simply enter their information, desired quantity, etc. And I could do this for every product...just by using forms. But this is very cheesy and unprofessional, because if a customer wanted to order three products, they would have to fill this form three times, etc.

Basically, I simply want to have the functionality to have customers click some "add to cart" icon, and then they would choose the quantity, get the appropriate price break discount, and the product would go to the cart. And when they are ready to "check out", they just fill in their name, contact info, etc, and it will state that they will be contacted regarding their order. And I really don't even care or want customers to register first, as this is not necessary for us.

Is this something that is somewhat :o easy to implement in php/mysql? Perhaps using sessions (something else i have no idea about)?

Please advise.

Thanks.
Jonathan

    Very easy. You can use SESSIONS, or store the data in a database or a combo. I would definetely store the orders (even when they are partial) in the DB, as your business is B2B it is unlikely you will have many non-returning customers

      So I wouldn't need to use some pre-written script of some sort? I could hopefully try to weave my way through this and figure it out myself?

      What specifically, if you do not mind explaining, would I save with the sessions? And sorry for my ignorance, but as of 15 minutes ago, i had no idea of php sessions. Trying to read up on it now. (but i'm a quick learner).

      Thanks.

        Been reading for a bit on sessions, and still not quite sure how I would use those to setup a shopping cart.

        However, I am still thoroughly motivated by your comment of "Very easy." Hoping this is the case.

        Could you possibly give an example of a specific way to do this or perhaps recommend some online resource which explains this in simple terms.

        Thanks again.
        Jonathan

          Hi Jonathan,

          When I learned about sessions, it took me 1 or 2 days to be able to use them for the site I was building at the moment, that's why I said "very easy" (BTW, I like to think of myself as a quick learner, just like you).

          You need the session to keep information about the current user within this session (that sounded a bit strange 😉... Basically I would assume you want your users to log in using a username and password to identify them. Once they log in, you store their details in a session, so you know who they are and when they place an order you know which user is doing so.

          In terms of recommended literature for sessions, I must admit I bought a great book at the time: "PHP & MySQL Bible" from Wiley publishers... so that is what I use normally for reference. You could buy the book (or another one) or just try to find something on the internet.

          In a nutshell, for sessions you would need:

          A "session_start();" PHP call at the beginning of your web pages (first line)

          Then you need to assign SESSION variables: "$_SESSION['user'] = $ulogin;". This should be done after you have validated the user's password in the database (make sure you store passwords encrypted and use the crypt function, really easy to use too).

          And finally, use the SESSION variables: "if(isset($HTTP_SESSION_VARS['user'])) { echo "Hello, ".$HTTP_SESSION_VARS['user']."!"; }

          Hope this helped. Good luck

            Thanks again for your help. I will be out of commission for the next five or so days, so please don't think I have given up on this project. Just have other things on the table.

            But I did want to ask you a more specific question on sessions/shopping carts, now that I've read more on sessions. (Although very simplistic, hudzilla's page on sessions was quite helpful: http://www.hudzilla.org/phpbook/read.php/10_0_0)

            You said that I could store the shopping cart data in the session variables. So let's see if i even remotely understand this correctly.

            Let's say the customer is viewing product #7 and wants to order a certain quantity of it. So when they click the "Order this Product" button, in actuality, I will have in the background a "form" and that "Order this Product" button is really acting like a SUBMIT button on a form. And then I will send this form, via POST, to a page called, for example, order.php. And because of the way our business works and with large quantity orders and customization, I guess that I would really only need to send the productID along with this form (because I would not want them to fill out quantity, and other details until the next page). So then from the order page, the product would again show, but this time in a "order form" type of style, and I will give the customer a form to fill specifying the quantity, imprint colors, in-hand date, etc (any thing i need for the order), and then they will hit an "Add to Cart" button. This button will again simply be a submit button for a form, which will then submit the form, via POST, to a page called, for example, cart.php. So on this cart.php page, I would then basically re-iterate to the customer what they just added to the cart, given an "Edit" button, and a continue shopping button, etc. And at this point, all the details from the last form, including the product ID, are now saved in the superglobal $_POST array, and I can access those variables accordingly. So now i need to get this data into the Session array, right? And I guess this can be done for each variable of the POST array as follows:

            $SESSION['prodID'] = $POST['prodID'];
            $SESSION['quantity'] = $POST['quantity'];
            $SESSION['otherpostedstuff'] = $POST['otherpostedstuff'];

            Is this correct? So now the posted "stuff" is saved into specific session variables.

            If that is basically a correct way up till now, then here is my main question...

            So for example, the field used for prodID and quantity, what happens when the user goes to another product, and decides to order that item also. We follow the same chain of events. They click the "Order this Product" button, come to the order.php page and fill out the form appropriately and submit it by clicking "Add to Cart". At this point they come to the cart.php page where I take the data from the POST array and save each to the SESSION array. But how do I do this without overwriting the data that was already there? This is probably a stupid question and I am either missing something or majorly overthinking it. Do I need to keep some global count variable, and somehow add stuff using it? (that last question probably made no sense) Hopefully someone can see where I am going wrong in the logic and point me in the right direction.

            Please advise.

            Thanks.
            Jonathan

              And just to clarify, each time that the user fills the larger order form and clicks add to cart, I could simply add that "stuff" to a cart table in my database. But I want to see if it is possible to stay away from adding to the databases for this.

              And also, although we are a b2b website, the return business we get almost ALWAYS calls their respective salesperson as opposed to going to the website. So the site is mainly used for getting new customers who order products. Thus, it is not even a big deal for me to save usernames and their respective info in a database. So when they checkout, i intend to simply have them fill out a form with their company info, shipping/billing details, etc. and have it all sent to an email somewhere, or maybe, at this point, once it is a confirmed order, maybe at this point i can save it in an "orders" table in the database. We'll see. But either way, I just want to see if i can do the whole thing with only using sessions.

              Hope this makes sense.

              Thanks.

                Hi,

                Your logic seems fine and your question, hopefully, easy to understand. What you need is a SESSION array, so you can add as many elements to your shopping cart as you want without overwriting the previous ones. I found this link on another forum that might be useful:

                http://www.experts-exchange.com/Web/Web_Languages/PHP/PHP_Databases/Q_20926089.html

                About not using a database: I guess it is not a big issue, but my personal view on this is to use a database, mainly for the following 2 reasons:

                1) If for whatever reason a customer has ordered many things (ie: cart quite full and them having spent considerable amount filling it) and something goes pear-shaped (ie: their connection goes down, their system crashes, your web server goes down, ...) and the session is lost, they have to start all over: they won't be happy. If you have saved stuff on a database this can be recovered.

                2) If your SMTP server is not responding or the email can't be sent for whatever reason you are in big trouble. My preferred approach would always be to store the order(s) in a database table and then have an automated job from the database sending the emails (you can check success and retry as many times as you want).

                To this you should add the fact that storing orders in a DB would allow you to do some analysis on order data per customer or accross the board...

                  Well great! Then I wasn't too far off from a 2D array, which was my guess...just didn't want to sound stupid by suggesting it. Didn't know Session could be used like that.

                  Once I get it setup, as mentioned, I will probably add a tuple to an order table, in the database, once the customer actually hits the submit button.

                  I'll look at the link you gave later on and try to make some sense of it.

                  Thanks.
                  Jonathan

                    Write a Reply...