Şimdi Ara

Sepet Yapımında

Daha Fazla
Bu Konudaki Kullanıcılar: Daha Az
1 Misafir - 1 Masaüstü
5 sn
5
Cevap
0
Favori
855
Tıklama
Daha Fazla
İstatistik
  • Konu İstatistikleri Yükleniyor
0 oy
Öne Çıkar
Sayfa: 1
Giriş
Mesaj
  • " : ""; ?>
    <td class="quantity center"><input type="text" name="quantity[<?php echo $order_code; ?>]" size="3" value="<?php echo $quantity; ?>" tabindex="<?php echo $i; ?>" /></td>
    <td class="item_name"><?php echo $Cart->getItemName($order_code); ?></td>
    <td class="order_code"><?php echo $order_code; ?></td>
    <td class="unit_price">$<?php echo $Cart->getItemPrice($order_code); ?></td>
    <td class="extended_price">$<?php echo ($Cart->getItemPrice($order_code)*$quantity); ?></td>
    <td class="remove center"><input type="checkbox" name="remove[]" value="<?php echo $order_code; ?>" /></td>
    </tr>
    <?php endforeach; ?>
    <tr><td colspan="4"></td><td id="total_price">$<?php echo $total_price; ?></td></tr>
    </table>
    <input type="submit" name="update" value="Update cart" />
    </form>
    <?php else: ?>
    <p class="center">You have no items in your cart.</p>
    <?php endif; ?>
    <p><a data-test="test" rel="nofollow" style="word-wrap: break-word; text-decoration: underline;" target="_blank" onclick="return dhExternalLinkRedirect(this)" href="/ExternalLinkRedirect?module=pgdcode&messageId=71059304&url=load.php" data-href="load.php">Load Sample Cart</a></p>
    </div>
    </body>
    </html>



    shopping_cart.class.php

     
    <?php

    class Shopping_Cart {
    var $cart_name; // The name of the cart/session variable
    var $items = array(); // The array for storing items in the cart

    /**
    * __construct() - Constructor. This assigns the name of the cart
    * to an instance variable and loads the cart from
    * session.
    *
    * @param string $name The name of the cart.
    */
    function __construct($name) {
    $this->cart_name = $name;
    $this->items = $_SESSION[$this->cart_name];
    }

    /**
    * setItemQuantity() - Set the quantity of an item.
    *
    * @param string $order_code The order code of the item.
    * @param int $quantity The quantity.
    */
    function setItemQuantity($order_code, $quantity) {
    $this->items[$order_code] = $quantity;
    }

    /**
    * getItemPrice() - Get the price of an item.
    *
    * @param string $order_code The order code of the item.
    * @return int The price.
    */
    function getItemPrice($order_code) {
    // This is where the code taht retrieves prices
    // goes. We'll just say everything costs $9.99 for this tutorial.
    return 9.99;
    }

    /**
    * getItemName() - Get the name of an item.
    *
    * @param string $order_code The order code of the item.
    */
    function getItemName($order_code) {
    // This is where the code that retrieves product names
    // goes. We'll just return something generic for this tutorial.
    return 'My Product (' . $order_code . ')';
    }

    /**
    * getItems() - Get all items.
    *
    * @return array The items.
    */
    function getItems() {
    return $this->items;
    }

    /**
    * hasItems() - Checks to see if there are items in the cart.
    *
    * @return bool True if there are items.
    */
    function hasItems() {
    return (bool) $this->items;
    }

    /**
    * getItemQuantity() - Get the quantity of an item in the cart.
    *
    * @param string $order_code The order code.
    * @return int The quantity.
    */
    function getItemQuantity($order_code) {
    return (int) $this->items[$order_code];
    }

    /**
    * clean() - Cleanup the cart contents. If any items have a
    * quantity less than one, remove them.
    */
    function clean() {
    foreach ( $this->items as $order_code=>$quantity ) {
    if ( $quantity < 1 )
    unset($this->items[$order_code]);
    }
    }

    /**
    * save() - Saves the cart to a session variable.
    */
    function save() {
    $this->clean();
    $_SESSION[$this->cart_name] = $this->items;
    }
    }

    ?>

    [code][/code]
    Merhabalar;

    Arkadaşlar web sayfam için bi sepet yapmaya çalışıyorum, hazır bir script buldum ancak üzerinde çok fazla değişiklik yapamadım. kodlar aşağıda. İstediğim şey ürünün "Bedeni"de form aracılığı ile gönderip sepette göstermek.

    yardımcı olursanız sevinirim.
    Not; taslağı hiç değiştirmeden ekliyorum.

    index.html
     
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <title>Shopping Cart</title>
    <script src="js/jquery-1.2.6.pack.js" type="text/javascript"></script>
    <script src="js/jquery.color.js" type="text/javascript"></script>
    <script src="js/thickbox.js" type="text/javascript"></script>
    <script src="js/cart.js" type="text/javascript"></script>
    <link href="css/style.css" rel="stylesheet" type="text/css" media="screen" />
    <link href="css/thickbox.css" rel="stylesheet" type="text/css" media="screen" />

    <script type="text/javascript">
    $(function() {
    $("form.cart_form").submit(function() {
    var title = "Your Shopping Cart";
    var orderCode = $("input[name=order_code]", this).val();
    var quantity = $("input[name=quantity]", this).val();
    var url = "cart_action.php?order_code=" + orderCode + "&quantity=" + quantity + "&TB_iframe=true&height=400&width=780";
    tb_show(title, url, false);

    return false;
    });
    });
    </script>
    </head>
    <body>
    <div id="container">
    <h1>Shopping Cart Demo</h1>
    <a data-test="test" rel="nofollow" style="word-wrap: break-word; text-decoration: underline;" target="_blank" onclick="return dhExternalLinkRedirect(this)" href="/ExternalLinkRedirect?module=pgdcode&messageId=71059304&url=cart.php?KeepThis=true&TB_iframe=true&height=400&width=780" title="Your Shopping Cart" class="thickbox" data-href="cart.php?KeepThis=true&TB_iframe=true&height=400&width=780" title="Your Shopping Cart" class="thickbox">Open Cart</a>
    <hr />
    <a data-test="test" rel="nofollow" style="word-wrap: break-word; text-decoration: underline;" target="_blank" onclick="return dhExternalLinkRedirect(this)" href="/ExternalLinkRedirect?module=pgdcode&messageId=71059304&url=cart_action.php?order_code=KWL-JFE&quantity=3&TB_iframe=true&height=400&width=780" title="Your Shopping Cart" class="thickbox" data-href="cart_action.php?order_code=KWL-JFE&quantity=3&TB_iframe=true&height=400&width=780" title="Your Shopping Cart" class="thickbox">Add three KWL-JFE to cart</a>
    <hr />
    <form class="cart_form" action="cart_action.php" method="get">
    <input type="hidden" name="order_code" value="KWL-JFE" />
    <label>KWL-JFE: <input class="center" type="text" name="quantity" value="1" size="3" ?></label>
    <input type="submit" name="submit" value="Add to cart" />
    </form>
    </div>
    </body>
    </html>



    cart_action.php

     
    <?php

    include('shopping_cart.class.php');
    session_start();
    $Cart = new Shopping_Cart('shopping_cart');

    if ( !empty($_GET['order_code']) && !empty($_GET['quantity']) ) {
    $quantity = $Cart->getItemQuantity($_GET['order_code'])+$_GET['quantity'];
    $Cart->setItemQuantity($_GET['order_code'], $quantity);
    }

    if ( !empty($_GET['quantity']) ) {
    foreach ( $_GET['quantity'] as $order_code=>$quantity ) {
    $Cart->setItemQuantity($order_code, $quantity);
    }
    }

    if ( !empty($_GET['remove']) ) {
    foreach ( $_GET['remove'] as $order_code ) {
    $Cart->setItemQuantity($order_code, 0);
    }
    }

    $Cart->save();

    header('Location: cart.php');

    ?>


    cart.php
     
    <?php
    include('shopping_cart.class.php');
    session_start();
    $Cart = new Shopping_Cart('shopping_cart');
    ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <title>Shopping Cart</title>
    <script src="js/jquery-1.2.6.pack.js" type="text/javascript"></script>
    <script src="js/jquery.color.js" type="text/javascript"></script>
    <script src="js/cart.js" type="text/javascript"></script>
    <link href="css/cart.css" rel="stylesheet" type="text/css" media="screen" />
    </head>
    <body>
    <div id="container">
    <h1>Shopping Cart</h1>
    <?php if ( $Cart->hasItems() ) : ?>
    <form action="cart_action.php" method="get">
    <table id="cart">
    <tr>
    <th>Quantity</th>
    <th>Item</th>
    <th>Order Code</th>
    <th>Unit Price</th>
    <th>Total</th>
    <th>Remove</th>
    </tr>
    <?php
    $total_price = $i = 0;
    foreach ( $Cart->getItems() as $order_code=>$quantity ) :
    $total_price += $quantity*$Cart->getItemPrice($order_code);
    ?>
    echo $i++%2==0 ? "







  • bedeni normal olarak formun icine ekle

    diger sayfada geti belirle iste formda ona id ver sonra javacriptteki urlde get icin bedeni ekle

    en son olaarak

    $Cart = new Shopping_Cart('shopping_cart');


    Shopping_Cart diye bir class var onu duzenle

    < Bu ileti mobil sürüm kullanılarak atıldı >
  • Zaten sorunda orada, form içerisine beden için
    <input type="hidden" name="beden" value="S" >


    olarak ekledim. ancak "cart_action.php" sayfasına ne ekleyeceğimi anlayamadım. önceden class ve dizilerle pek çalışmadım.

    Yardımcı olursanız sevinirim.
  • simdi sen formu gonderiyorsun . formu alan sayfada geti alacaksin . geti aldiktan sonra getin degerini classin icine gondereceksin zaten session save yapiyor class oturum icin carti save ediyor sadece o . classlarin basit bi introsunu oku yaparsin .

    < Bu ileti mobil sürüm kullanılarak atıldı >
  • function getItemSize($order_code) {
    // This is where the code taht retrieves prices
    // goes. We'll just say everything costs $9.99 for this tutorial.
    return Small;
    }



    ama bunu boyle koyarsan sadece small dondurur. onun yerine forma select koy size icin degerler ver o degerler classtan medium small large falan diye doner daha adam akilli olur

    < Bu ileti mobil sürüm kullanılarak atıldı >
  • 
Sayfa: 1
- x
Bildirim
mesajınız kopyalandı (ctrl+v) yapıştırmak istediğiniz yere yapıştırabilirsiniz.