Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> Wysyłanie zawartości koszyka, w zamówieniu
Ogniu
post 1.12.2014, 10:59:00
Post #1





Grupa: Zarejestrowani
Postów: 3
Pomógł: 0
Dołączył: 1.12.2014

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


Hej, zakładam nowy temat ponieważ ciężko mi było znaleźć taki który by rozwiązał mój problem.

Pomagam koledze przy pewnej stronce i chcielibyśmy żeby zawartość koszyka(1 plik) i zawartość karty zamówienia(2 plik) było wysyłane razem w zamówieniu.

Tak wygląda mój koszyk:
  1. <h1>Koszyk</h1>
  2. <?php
  3.  
  4. if($_GET['cart_add'] && $_GET['cart_szt']){
  5. $add_id = $_GET['cart_add'];
  6.  
  7. $db->query("SELECT id, name, price FROM offer WHERE id=$add_id");
  8. $db->setFetchMode(2);
  9. $product = $db->get();
  10. $product = $product[0];
  11. $product['szt'] = $_GET['cart_szt'];
  12.  
  13. $_SESSION['cart'][$add_id] = $product;
  14. }
  15.  
  16. if($_GET['delete']){
  17. $delete_id = $_GET['delete'];
  18. unset($_SESSION['cart'][$delete_id]);
  19. }
  20.  
  21. if($_GET['modify']){
  22. $mod_id = $_GET['modify'];
  23. $pcs = $_GET['cart_szt'];
  24. $_SESSION['cart']["$mod_id"]['szt'] = $pcs;
  25. }
  26. ?>
  27.  
  28. <script type="text/javascript">
  29. $(document).ready(function(){
  30. $('.removefromcart').click(function(){
  31. var id = $(this).data('id');
  32. window.location = "shop.php?module=cart&delete="+id;
  33. });
  34.  
  35. $('.countpcs').click(function(){
  36. var id = $(this).data('id');
  37. var pcs = $(this).prev().val();
  38. window.location = "shop.php?module=cart&modify="+id+"&cart_szt="+pcs;
  39. });
  40. });
  41. </script>
  42.  
  43.  
  44. <table id="cart">
  45. <thead>
  46. <tr>
  47. <th>Towar</th>
  48. <th style="width:100px">cena</th>
  49. <th style="width:200px">sztuk</th>
  50. </tr>
  51. </thead>
  52. <tbody>
  53. <?php foreach ($_SESSION['cart'] as $cart):?>
  54. <tr>
  55. <td><?=$cart['name']?></td>
  56. <td align="center"><?=$cart['price']?> zł</td>
  57. <td>
  58. <div style="display:inline;">
  59. <input type="text" style="width:35px;" value="<?=$cart['szt']?>" name="szt">
  60. <input type="button" class="countpcs" data-id="<?=$cart['id']?>" value="Przelicz">
  61. </div>
  62. <div style="display:inline;">
  63. <input type="button" class="removefromcart" data-id="<?=$cart['id']?>" value="Usuń">
  64. </div>
  65. </td>
  66. </tr>
  67. <?php $suma+=$cart['price']*$cart['szt'] ?>
  68. <?php endforeach; ?>
  69. <tr>
  70. <td align="center">Koszt cakowity:</td>
  71. <td><?=number_format($suma, 2, '.', '');?></td>
  72. <td></td>
  73. </tr>
  74. </tbody>
  75. </table>
  76.  
  77. <h1 style="margin-top:25px">Złóż zamówienie</h1>
  78. <?php include_once "modules/orderform.php"; ?>


a tak wygląda karta zamównienia

  1. <?php
  2. if($_POST)
  3. {
  4. require 'libs/phpmailer/class.phpmailer.php';
  5.  
  6. $imie=$_POST['name'];
  7. $miejscowosc=$_POST['city'];
  8. $email=$_POST['email'];
  9. $telefon=$_POST['phone'];
  10. $tresc=$_POST['content'];
  11.  
  12. $message.="<p><strong>Koszyk</strong></p>";
  13. $message.="<p><strong>Dane Zamówienia</strong></p>";
  14. $message.="<strong>Imie i nazwisko / nazwa firmy: </strong> $imie <br /> \n";
  15. $message.="<strong>Adres: </strong> $adres <br /> \n";
  16. $message.="<strong>Miejscowość: </strong> $miejscowosc <br /> \n";
  17. $message.="<strong>Telefon: </strong>$telefon <br /> \n";
  18. $message.="<strong>Email: </strong>$email <br /> \n";
  19. $message.="<strong>Uwagi: </strong> <br/>".$tresc."<br /> \n";
  20.  
  21. $mail = new PHPMailer(true); //defaults to using php "mail()"; the true param means it will throw exceptions on errors, which we need to catch
  22.  
  23. try {
  24. $mail->CharSet = 'UTF-8';
  25. $mail->AddReplyTo($email, $imie);
  26. $mail->AddAddress('ogniu88@gmail.com', 'Blue Orchid');
  27. $mail->SetFrom($email, $imie);
  28. $mail->Subject = 'Nowe zamówienie ze strony';
  29. //$mail->AltBody = 'To view the message, please use an HTML compatible email viewer!'; // optional - MsgHTML will create an alternate automatically
  30. $mail->MsgHTML($message);
  31. $mail->Send();
  32. $sended = true;
  33. //echo "<p class='error'>Twój formularz został pomyślnie wysłany</p>\n";
  34. //echo "<script type='text/javascript'>alert('Twój formularz został pomyślnie wysłany');</script>\n";
  35. } catch (phpmailerException $e) {
  36. echo $e->errorMessage(); //Pretty error messages from PHPMailer
  37. } catch (Exception $e) {
  38. echo $e->getMessage(); //Boring error messages from anything else!
  39. }
  40. }
  41. ?>
  42. <form method="post" action="" id="contactForm">
  43. <div class="form">
  44. <?php if($sended):?>
  45. <div style="text-align:center;color:green;font-weight:bold;">Zamówienie zostało wysłane!</div>
  46. <?php endif; ?>
  47. <div>
  48. <label for="contact_name"><span class="star">*</span> Imię i nazwisko</label>
  49. <input placeholder="np. Jan Kowalski" value="" name="name" class="text required" id="contact_name">
  50. </div>
  51. <div>
  52. <label for="contact_adress"><span class="star">*</span> Adres</label>
  53. <input placeholder="np. ul. Jerozolimska" name="adress" value="" class="text required" id="contact_adress">
  54. </div>
  55. <div>
  56. <label for="contact_city"><span class="star">*</span> Miejscowość</label>
  57. <input placeholder="np. Bytom" name="city" value="" class="text required" id="contact_city">
  58. </div>
  59. <div>
  60. <label for="contact_phone"><span class="star">*</span> Numer telefonu</label>
  61. <input placeholder="np. 48 123 456 789" name="phone" value="" class="text required" id="contact_phone">
  62. </div>
  63. <div>
  64. <label for="contact_email"><span class="star">*</span> Adres e-mail</label>
  65. <input placeholder="np. twoj@adres.pl" name="email" value="" class="text required email" id="contact_email">
  66. </div>
  67. <div>
  68. <label for="contact_content">Uwagi</label>
  69. </div>
  70. <div>
  71. <textarea cols="50" rows="10" name="content" class="textarea" placeholder="Twoje pytanie" id="contact_content"></textarea>
  72. </div>
  73. <div><p style="margin:5px 0;"><span class="star">*</span> Pola obowiązkowe</p></div>
  74. <div align="right"><input type="submit" value="Wyślij zamówienie"/></div>
  75. </div>
  76. </form>
  77.  
  78. <script type="text/javascript">
  79. $("#contactForm").validate();
  80. </script>


Teraz na mejla wysyła się tylko zawartość karty zamówienia, czyli imię i nazwisko itp. a brakuje informacji z koszyka. Chciałbym prosić Was o pomoc smile.gif
Go to the top of the page
+Quote Post
SaMi
post 1.12.2014, 15:41:07
Post #2





Grupa: Zarejestrowani
Postów: 173
Pomógł: 14
Dołączył: 27.03.2004
Skąd: Białystok

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


Bo tu nie ma żadnego info z koszyka.
  1. $message.="<p><strong>Koszyk</strong></p>";
  2. $message.="<p><strong>Dane Zamówienia</strong></p>";
  3. $message.="<strong>Imie i nazwisko / nazwa firmy: </strong> $imie <br /> \n";
  4. $message.="<strong>Adres: </strong> $adres <br /> \n";
  5. $message.="<strong>Miejscowość: </strong> $miejscowosc <br /> \n";
  6. $message.="<strong>Telefon: </strong>$telefon <br /> \n";
  7. $message.="<strong>Email: </strong>$email <br /> \n";
  8. $message.="<strong>Uwagi: </strong> <br/>".$tresc."<br /> \n";
  9. .
  10. .
  11. .
  12. $mail->MsgHTML($message);


W pliku zamówienia musisz pobrać zawartość $_SESSION['cart'] i jej zawartość wstawić w treści wiadomości.

Ten post edytował SaMi 1.12.2014, 15:48:09


--------------------
Zapraszam na spływy kajakowe rzekami podlasia www.splywy-kajakiem.pl
Go to the top of the page
+Quote Post
Ogniu
post 1.12.2014, 16:36:36
Post #3





Grupa: Zarejestrowani
Postów: 3
Pomógł: 0
Dołączył: 1.12.2014

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


Powiem szczerze, że jestem samoukiem i wcześniej nie miałem takiego problemu i ciężko mi samemu go rozwiązać, czy mógłbyś @SaMi przedstawić, jak to miałoby wyglądać? Z góry dziękuję wink.gif

Ten post edytował Ogniu 1.12.2014, 20:15:11
Go to the top of the page
+Quote Post
SaMi
post 2.12.2014, 11:52:58
Post #4





Grupa: Zarejestrowani
Postów: 173
Pomógł: 14
Dołączył: 27.03.2004
Skąd: Białystok

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


Najprościej

  1. //tu masz zdefinijowaną treść maila
  2. $message = "<p><strong>Koszyk</strong></p>";
  3.  
  4. // przykład
  5. $message.= "dane z koszyka: $_SESSION['cart'][$jakis_id]";
  6. //albo całą tablicę
  7. foreach ($_SESSION['cart'] as $cart){
  8. $message.= "produkt:". $cart['name']." cena:".$cart['price'];
  9. }
  10.  
  11. $message.="<p><strong>Dane Zamówienia</strong></p>";
  12. $message.="<strong>Imie i nazwisko / nazwa firmy: </strong> $imie <br /> \n";
  13. $message.="<strong>Adres: </strong> $adres <br /> \n";
  14. $message.="<strong>Miejscowość: </strong> $miejscowosc <br /> \n";
  15. $message.="<strong>Telefon: </strong>$telefon <br /> \n";
  16. $message.="<strong>Email: </strong>$email <br /> \n";
  17. $message.="<strong>Uwagi: </strong> <br/>".$tresc."<br /> \n";


Tylko podstaw sobie własne nazwy kluczy jakie masz w $_SESSION


--------------------
Zapraszam na spływy kajakowe rzekami podlasia www.splywy-kajakiem.pl
Go to the top of the page
+Quote Post
Ogniu
post 2.12.2014, 13:50:38
Post #5





Grupa: Zarejestrowani
Postów: 3
Pomógł: 0
Dołączył: 1.12.2014

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


Śmiga jak szalone, dziękuję bardzo, do zamknięcia wink.gif
Go to the top of the page
+Quote Post

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 Wersja Lo-Fi Aktualny czas: 10.06.2024 - 18:56