Re: [PHPLIB] cart questions From: Wolf Giesen (wgi <email protected>)
Date: 12/09/99

>Unfortunately, nobody could answer my question of how to extend the cart
>to hold additional attributes. I need to modify cart.inc, because I have
>an additional field called "stock". When the user buys 5 pieces of product
>1 from stock1 and 2 pieces from stock2, the orders are not allowed to be
>summed up! There have to be two seperate entries in the cart.

Perhaps I don't understand the problem. Go ahead and put your articles in a
database table. Then define a cart that accesses that table. Like the
following example (sorry, texts are in german, but it is from a working
production system):

Maybe it's just a problem of understanding: cart itself does nothing more
than keep a list of articles and their amaounts in the cart. Use the
article number as key for your database query. There you have all the
descriptive data for the articles. This makes the base class "cart"
independent of the actual structure of your articles.

Regards,

Wolf Giesen

class xyz_cart extends Cart
   {
    var $classname = "xyz_cart";

    var $database_class = "db_xyz";
    var $database_table = "daten";
    var $db;

    var $sum = 0;

    var $mwstsatz = 116.0;

    function netto_of($wert)
      {
       return ($wert*100.0) / $this->mwstsatz;
      }

    function mwst_of($wert)
      {
       return $this->netto_of($wert)*0.16;
      }

    function show_cart_open()
      {
       print "<TABLE BORDER=1>\n";
       printf("<TR><TH>Anzahl</TH><TH>Art.-Nr.</TH><TH>Bezeichnung</TH><TH>E
printf("<TR><TH>Anzahl</TH><TH>Art.-Nr.</TH><TH>Bezeichnung</TH><TH>Einzelpr
eis</TH><TH>Summe</TH></TR><TR>");
       $this->sum = 0;
      }

    function show_cart_close()
      {
       printf("<TR><TD COLSPAN=4>Darin enthalten: 16%% MwSt</TD><TD
ALIGN=RIGHT>DM&nbsp;%1.2f</TD></TR>\n",$this->mwst_of($this->sum));
       printf("<TR><TD COLSPAN=4>Nettobetrag:</TD><TD
ALIGN=RIGHT>DM&nbsp;%1.2f</TD></TR>\n",$this->netto_of($this->sum));
       printf("<TR><TD COLSPAN=4><STRONG>Gesamt:</STRONG></TD><TD
ALIGN=RIGHT><STRONG>DM&nbsp;%1.2f</STRONG></TD></TR></TABLE>\n",$this->sum);
      }

   function show_item($art,$num)
    {
     global $sess;

     if (!is_object($this->db))
       {
        $class = $this->database_class;
        $this->db = new $class;
       }

     $query = sprintf("select * from %s where Artikelnummer = '%s' ORDER BY
Artikelnummer", $this->database_table, $art);
     $this->db->query($query);

     while ($this->db->next_record())
       {
        printf('<TD VALIGN=TOP><FORM ACTION="%s" METHOD=POST>',
$sess->url("kdwkorb.php3?cmd=order"));
        printf('<INPUT TYPE=HIDDEN NAME="artikel" VALUE="%d">', $art);
        printf('<INPUT TYPE=TEXT NAME="quant" VALUE="%d" SIZE=3
MAXLENGTH=5>', $num);
        printf('<INPUT TYPE=SUBMIT VALUE="&auml;ndern"></FORM></TD>');

        printf('<TD VALIGN=TOP><FORM ACTION="%s" METHOD=POST>',
$sess->url("kdprod.php3"));
        printf('<INPUT TYPE=HIDDEN NAME="pg" VALUE="%d">',
$this->db->Record["artgruppe"]);
        printf('<INPUT TYPE=HIDDEN NAME="an" VALUE="%d">', $art);
        printf('<INPUT TYPE=SUBMIT VALUE="%d"></FORM></TD>',$art);

        printf("<TD VALIGN=TOP>%s</TD>",$this->db->Record["Prbe"]);
        printf("<TD VALIGN=TOP
ALIGN=RIGHT>DM&nbsp;%s</TD>",$this->db->Record["PPreis"]);
        $rowsum = $num * $this->db->Record["PPreis"];
        $this->sum += $rowsum;
        printf("<TD VALIGN=TOP ALIGN=RIGHT>DM&nbsp;%1.2f</TD></TR>\n",$rowsum);
       }
    }
}

--
Cyrano Kommunikation GmbH       Tel.: (0251) 32 11 89 1
Eulerstraße 15                  Fax:  (0251) 32 11 89 4
48155 Münster                   cyrano-kommunikation.de

- PHP3 Base Library Mailing List. Send messages to <phplib <email protected>>. To unsubscribe, send "unsubscribe" to <phplib-request <email protected>> in the body, not the subject, of your message.