X


Historia wymaga pasterzy, nie rzeźników.


Default Properties:
◆ none
Methods:
◆ Item. The class constructor. Takes two arguments: $parent and $atts. Calls the Base() method, assigning each element of the $atts array to Object properties.
◆ SaveItem. Takes no arguments, assumes a $this->item_id exists. Will both update existing styles and create new ones as needed.
CLASS CARTCATEGORY
This is the first of the new classes that directly extend the classes created for the catalog application.
Class Name: CartCategory
Extends Category
Default Properties:
◆ none
Methods:
◆ CartCategory. The class constructor. Calls the Base() method, assigning each element of the $atts array to Object properties.
◆ AddProduct. This method overwrites the AddProduct() method that is in the parent (Category) class. It creates an array, called $products, each member of which is an object formed by calling the CartProducts() class.
3537-4 ch14.f.qc 12/15/00 15:25 Page 385
Chapter 14: Shopping Cart 385 In creating the data structure in Chapter 10, you saw how the LoadCategory() method instantiated objects within an array. Instead of having the LoadCategory() class instantiate the object directly, we had LoadCategory() call another method, named AddProduct(), which instantiated the objects. By breaking out AddProduct() into its own separate method, we gained some flexibility, which becomes convenient in this application.
When you instantiate the CartCategory class, the AddProduct() method of this child class overwrites the AddProduct() method of the parent (Category) class. So if you write the following code:
$c = new CartCategory;
$c->LoadProduct($product_id);
you can be sure that the AddProduct() method from the CartCategory call will execute.
Here are the contents of AddProduct() method of the CartCategory class.
function AddProduct($parent,$atts)
{
$this->products[] = new CartProduct($parent,$atts);
}
CLASS CARTPRODUCT
This is similar to the CartCategory class and includes a method for printing Products that is better for the shopping cart.
Class Name: CartProduct
Extends Product
Default Properties:
◆ none
Methods:
◆ CartProduct. The class constructor. Takes two arguments: $parent and $atts.
Calls the Base() method, assigning each element of the $atts array to Object properties.
◆ AddStyle. This method overwrites the AddStyle() method that is in the parent (Product) class. It creates an array, called $styles, each member of which is an object formed by calling the CartStyles() class.
◆ PrintProdct. Takes no attributes. Overwrites the PrintProduct() method of the parent (Product) class.
3537-4 ch14.f.qc 12/15/00 15:25 Page 386
386
Part IV: Not So Simple Applications CLASS CARTSTYLE This is similar to the CartStyle class and includes a method for printing Styles that is better for the shopping cart.
Class Name: CartStyle
Extends Style
Default Properties:
◆ none
Methods:
◆ CartStyle. The class constructor. Takes two arguments: $parent and $atts.
Calls the Base() method, assigning each element of the $atts array to Object properties.
◆ AddSubStyle. This method overwrites the AddSubStyle() method that is in the parent (Style) class. It creates an array, called $substyles, each member of which is an object formed by calling the CartSubStyles() class.
◆ PrintStyleRow. Takes no attributes. Overwrites the PrintStyleRow() method of the parent (Style) class.
CLASS CARTSUBSTYLE
This is similar to the CartSubStyle class and includes a method for printing substyles that is better for the shopping cart.
Class Name: CartSubStyle
Extends SubStyle
Default Properties:
◆ none
Methods:
◆ CartSubStyle. The class constructor. Takes two arguments: $parent and $atts.
Calls the Base() method, assigning each element of the $atts array to Object properties.
◆ AddSubStyle. This method overwrites the AddSubStyle() method that is in the parent (Style) class. It creates an array, called $substyles, each member of which is an object formed by calling the CartSubStyles() class.
◆ PrintSubStyle. Takes three attributes, $style_price, $style_dsc, $product_dsc.
Overwrites the PrintSubStyle() method of the parent (Style) class.
3537-4 ch14.f.qc 12/15/00 15:25 Page 387
Chapter 14: Shopping Cart 387 Scripts
These are the pages called by URLs and the includes. Once again, you will probably notice that there isn’t a whole lot involved. Almost all of the work is done in the Classes.
DISPLAY.PHP
This will print out either a list of categories or a specific product.
include ‘header.php’;
if (empty($category_id))
{
header(“Location: index.php”);
exit;
}
$page_title = anchor_tag(“index.php”, “Bag’O’Stuff”);
$c = new CartCategory;
if (empty($product_id))
{
$c->LoadCategory($category_id);
$page_title .= “: $c->category”;
include “start_page.php”;
$c->PrintCategory();
}
else
{
$p = new CartProduct;
$p->LoadProduct($product_id);
$p->LoadStyles();
$c->FetchCategory($p->category_id);
$page_title .= “: “
.anchor_tag(“display.php?category_id=$c->category_id”
, $c->category
)
.”: $p->product”
;
3537-4 ch14.f.qc 12/15/00 15:25 Page 388
388
Part IV: Not So Simple Applications include “start_page.php”;
$p->PrintProduct();
}
include “end_page.php”;

Drogi użytkowniku!

W trosce o komfort korzystania z naszego serwisu chcemy dostarczać Ci coraz lepsze usługi. By móc to robić prosimy, abyś wyraził zgodę na dopasowanie treści marketingowych do Twoich zachowań w serwisie. Zgoda ta pozwoli nam częściowo finansować rozwój świadczonych usług.

Pamiętaj, że dbamy o Twoją prywatność. Nie zwiększamy zakresu naszych uprawnień bez Twojej zgody. Zadbamy również o bezpieczeństwo Twoich danych. Wyrażoną zgodę możesz cofnąć w każdej chwili.

 Tak, zgadzam siÄ™ na nadanie mi "cookie" i korzystanie z danych przez Administratora Serwisu i jego partnerów w celu dopasowania treÅ›ci do moich potrzeb. PrzeczytaÅ‚em(am) PolitykÄ™ prywatnoÅ›ci. Rozumiem jÄ… i akceptujÄ™.

 Tak, zgadzam siÄ™ na przetwarzanie moich danych osobowych przez Administratora Serwisu i jego partnerów w celu personalizowania wyÅ›wietlanych mi reklam i dostosowania do mnie prezentowanych treÅ›ci marketingowych. PrzeczytaÅ‚em(am) PolitykÄ™ prywatnoÅ›ci. Rozumiem jÄ… i akceptujÄ™.

Wyrażenie powyższych zgód jest dobrowolne i możesz je w dowolnym momencie wycofać poprzez opcję: "Twoje zgody", dostępnej w prawym, dolnym rogu strony lub poprzez usunięcie "cookies" w swojej przeglądarce dla powyżej strony, z tym, że wycofanie zgody nie będzie miało wpływu na zgodność z prawem przetwarzania na podstawie zgody, przed jej wycofaniem.