Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> Koszyk w php ale jak skorzystać?, Mam gotowy skrypt ale nie umiem...
kofaniutki_misio
post
Post #1





Grupa: Zarejestrowani
Postów: 14
Pomógł: 0
Dołączył: 9.11.2005

Ostrzeżenie: (0%)
-----


Mam gotowy skrypt ale nie umiem go wykorzystać. Nie znam się na php dobrze, jestem bardzo początkujący.

Chce zrobic koszyk sklepu internetowego, znalazłem darmowy skrypt ale nie umiem go "ożywić".

Czy ktoś może napisać jak się go używa ? przykladowo jak dodac coś do koszyka, jak go wyświetlić itd.

  1. <?php
  2. /*
  3. Basket class for e-commerce purpose
  4.  
  5. Version : 0.5
  6. Type:Class
  7. Category:Shopping Carts
  8. License: GNU General Public License
  9.  
  10. Description: This class provides methods for add, remove, update and remove all 
    items
  11. from a basket. The basket works with a session cookie, saving the product ID
  12. and quantity in an array for simple accesing it.
  13. There's an example in this category... called "Basket example using basket class"
  14. */
  15.  
  16. class basket {
  17. var $items;
  18. var $empty;
  19.  
  20. function basket()
  21. {
  22.   global $cart;
  23.   if(isset($cart))
  24.   {
  25.    $this->items=unserialize(stripslashes($cart));
  26.    if ( gettype($this->items) == "array" )
  27.    {
  28.     $this->empty=false;
  29.    }
  30.    else
  31.     $this->empty=true;
  32.   }
  33.   else
  34.    $this->empty=true;
  35. }
  36.  
  37.  
  38. function additem($id, $name, $count, $prix)
  39. {
  40.  
  41. if ($this->items[$id][1] > 0 )
  42. {
  43.   $this->items[$id][1]+=$count;
  44. }
  45. else
  46. {
  47.   $this->items[$id][0]=$name;
  48.   $this->items[$id][1]=$count;
  49.   $this->items[$id][2]=$prix;
  50.   $this->items[$id][3]=stripslashes($name);
  51. }
  52. setcookie("cart",serialize($this->items),0,"/");
  53. $this->empty=false;
  54. }
  55.  
  56. function removeitem($id) {
  57. $tmp=""; // Don't forget to initialize !
  58. if(!$this->empty)  {
  59.   while(list($x,$y)=each($this->items)){
  60.    if($x!=$id) $tmp[$x]=$y;
  61.   };
  62. };
  63. $this->items=$tmp; // Or this will have no effect !
  64. setcookie("cart",serialize($this->items),0,"/");
  65. if(count($this->items)==0) $this->empty=true;
  66. }
  67.  
  68. function resetArray($basket)
  69. {
  70. reset($basket->items);
  71. }
  72.  
  73. function countItems($basket)
  74. {
  75. if(!$basket->empty)
  76. {
  77.   while ( list($x,$y,) = each($basket->items) )
  78.   {
  79.    $ant++;
  80.   }
  81. }
  82. return $ant;
  83. }
  84. function sumItems($basket)
  85. {
  86. if(!$basket->empty)
  87. {
  88.   while ( list($x,$y,) = each($basket->items) )
  89.   {
  90.    $ant = $ant + $y[1];
  91.   }
  92. }
  93. return $ant;
  94. }
  95. function printItems($b)
  96. {
  97. if(!$b->empty)
  98. {
  99.   while ( list($x,$y,) = each($b->items) )
  100.   {
  101.    echo "$x     ".$y[0]."   ".$y[1]."  <a href="$PHP_SELF?action=R&id=$x">Remove</a><br>";
  102.   }
  103. }
  104. }
  105. function updateitem($id,$count){
  106. $this->items[$id][1]=$count;
  107. setcookie("cart",serialize($this->items),0,"/");
  108. }
  109.  
  110. function removeall(){
  111. setcookie("cart",NULL,0,"/");
  112. $this->empty=true;
  113. }
  114.  
  115.  
  116. }
  117.  
  118.  
  119. ?>
  120.  
  121. </body>
  122. </html>


z góry dziękuje. Jeśli ktoś wie gdzie można sciągnać bardziej opisowy koszyk, wraż z plikami prosze o linka.

Ten post edytował jebus_maksimus 9.11.2005, 12:30:31
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 19.08.2025 - 18:23