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
 
Start new topic
Odpowiedzi
jurobg
post
Post #2





Grupa: Zarejestrowani
Postów: 10
Pomógł: 0
Dołączył: 17.01.2005

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


Mniejsza z informacją - skoro to forum liczylem ze otrzymam odpowiedz dlaczego tak sie dzieje a nie gdzie szukac tego. Przyzwyczailem sie juz raczej do tego ze zwykle ci co juz wiedza kaza szukac a jak nie wiedzieli to prosili o pomoc jak to zrobic bo znalezc nie moga. Niewazne - poradzilem sobie.

Ponawiam pytanie.
Jezeli ktos uzywal tego skryptu to czy udalo mu sie go sprawnie zastosowac ?

Mam cos takiego:

  1. $basket = new basket;
  2. switch($action){
  3. case "A":
  4. $basket->additem($id, $name, $q, $cena); //function additem($id, $name, $count, $prix)
  5. break;
  6. case "R":
  7. $basket->removeitem($id);
  8. break;
  9. case "D":
  10. $basket->removeall();
  11. break;
  12. }
  13.  
  14. ?>
  15. <body text="#000080" link="#0000FF" vlink="#800080" alink="#FF0000" bgcolor="#FFFFFF">
  16. <pre>
  17. ID Towar Cena
  18. 23 Notebook  3500 <a href="<? echo $PHP_SELF; ?>?action=A&id=23&q=1&name=Notebook&cena=3500">Dodaj</a>
  19. 10 Pad 10 <a href="<? echo $PHP_SELF; ?>?action=A&id=10&q=1&name=Pad&cena=10">Dodaj</a>
  20. <a href="<? echo $PHP_SELF; ?>?action=D">Usun wszystko</a>
  21. </pre>
  22. <pre>
  23. <?
  24.  
  25. if(!$basket->empty) {
  26. echo "Zawartosc koszyka: <br>ID ITEM Q<br>";
  27. $basket->printItems($basket);
  28. }
  29. ?></pre>


Tu czytalem ze rozwiazanie sie kreowalo ale niewiele z tego rozumiem:

http://www.prog.hu/tudastar/37693/PHP5%20basket.html
Go to the top of the page
+Quote Post

Posty w temacie


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

 



RSS Aktualny czas: 10.10.2025 - 12:29