
At this lesson we will construct the logic for the "Shopping Cart".
If you are a web developer you know that one of the big problems of the web is the fact that it works stateless. This means that: one page doesn't "talk" to the other of the same site. The protocol HTTP makes a connection to the web server, loads one page and its complements, and closes the connection. If you go to another page it repeats the operation. Softwares like ASP .NET try to bypass this problem.
Using Squeak, a site is an object having other objects (pages etc.) inside and they can talk to each other.
PROS & CONS: The "other side" of this fact is: if you have a very big site you will load a big .PR file, having many pages that you will not use. We like to call this kind of applications: "fat clients". This was the reason of the disaster of the Java applets in 1995. Now, 10 years later, having broadband and fast machines, this is not a great problem anymore.
Another "con": using this architecture we can't have "hiperlink to page".By example: if there are a Shakespeare's book to sell, we can create a link to a page about this author. What we can have is "links in space level". We can, by example, to have a portal, at the Book&Videos.com space, to a space about Shakespeare:
To facilitate, our bookstore will have only 2 books to sell- no videos. To the pageAAAA we will drag two objects Rectangle from the "green window". We will change their names to: Book1Price and Book2Price.
Inside each one we will put an object Text having the price. You know how to change the size, font etc. of a Text. We will put also the titles of the books and could have a description of the book etc. All will be Text objects. You don't need to change the names of these objects because they will not be used in code.
After this, go to the pageCCCC. Put an object ScrollingText (from Basic1 of the "green window") - new name: FinalList - and a "Text (border)" - name: Total.
DON'T FORGET: The "embed into" thing...
If you "wheelclicks" many times, you will see the Halo of an object TextMorphForEditView inside the ScrollingText. Change its name to: TextInFL. Change its size and style but let it empty.
Back to the pageAAAA, define 2 texts to show a message to the buyer when he clicks the rectangle of the price. Their names will be: Book1Conf and Book2Conf. Open the Viewer of each one, clicking in the "yellow exclamation" to hide them (look the figure):
An script is always glued to the object "owner of the event" that starts this script.
Here we will have 2 "starters", the rectangles to be clicked : Book1Price and Book2Price.
Open the Viewer of Book1Price and drag a new Script Editor.
The script will do 3 things:
So: we need first to put in the Script Editor - dragging a line of the Viewer of each - instances of the objects:
Opening the the Script Editor we will have the lines of the figure:
WARNING: The versions of your objects can be different!
The code will be:
Book1Conf3 show. TextInFL setCharacters: TextInFL getCharacters,'\The Gourmet CookBook by Rachel Reichl 20.74' withCRs. Total6 setNumericValue: Total6 getNumericValue + 20.74.
VERY VERY IMPORTANT: Before to do the "accept" of the program verify all the names+versions of the objects involved! They change!
CODE COMMENTS
To define the event that will start the program click in "Normal" and select: mouseDown
NOW, DO THE ACCEPT!
Go to the pageAAAA and click the price of the first book:
Go to the pageCCCC and you will see (miracle!) the new line and total:
We will erase the Page Controls, but we can add pages in the future using the Menu of the Book.
If you have the Squeakland plugin, look and play with the atual version of our project (good for 1400x1050 resolution):
You can test this project!
Its address is: http://www.dmu.com/Tealand/theBookstore111.014.pr
And re-read the lesson about how to create a 3D window for a project. Use for "extent": 1050 x 1050.
Look the figure of the site in the space:
WARNING. If you don't have a powerfull computer and a fast communication line it's possible that you will not have a very responsible application. We are doing our tests at a:
Notebook DELL Latitude D600 - Intel Pentium M755 2.0 GHZ - Memory: 512 MB - VideoCard ATI Radeon 9000 32MB DDR 4xAGP - Resolution 1400x1050 - Communication: ADSL 256 kbps (Download: 45 kBps, Upload: 14 kBps) - Windows XP Professional SP1
PREVIOUS LESSON NEXT LESSON T. CONTENTS HOMEPAGE
