SitePoint Sponsor

User Tag List

Page 2 of 2 FirstFirst 12
Results 26 to 37 of 37
  1. #26
    SitePoint Wizard
    Join Date
    Mar 2001
    Posts
    3,537
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It's just finding a way of posting the sizes to the checkout that Im not succeeding in. I know you suggest creating an array which stores the variable $Size inside, but I honestly haven't a clue on how to do it.
    Then give every item it's own id, and use your current code.

  2. #27
    SitePoint Zealot
    Join Date
    Apr 2005
    Posts
    191
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Every item already has its own unique ID... Or do you mean something else?

  3. #28
    SitePoint Wizard
    Join Date
    Mar 2001
    Posts
    3,537
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Like this:


    id........item
    ---------------
    11..... shirt xl
    12......shirt medium
    13......shirt small

    ??

  4. #29
    SitePoint Zealot
    Join Date
    Apr 2005
    Posts
    191
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Nah not like that...

    I think it looks a bit amateurish having items like that e.g. 7 different items to browse but all different sizes, instead Id like to have 1 shirt and being able to select the sizes from there.

    I just need to figure out how, and hopefully with a little help somebody can get me off on the right foot.

  5. #30
    SitePoint Evangelist
    Join Date
    May 2004
    Location
    New Jersey, USA
    Posts
    567
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hilly,

    You've got items with sizes, and items without sizes, correct?

    That being the case, I think you need to consider the size part of the item identifier: a customer can buy 2 pairs size 7 blue shoes, 1 pair size 9 black shoes.

    When it comes down to putting things in your cart, every user-selectable field that is about the product basically is part of the identification.

    You need to compare them all, in order to decide whether to add a new record or merge two records:

    1 pr. size 7 blue shoes
    1 pr. size 9 black shoes
    1 pr. size 7 blue shoes <-- should be +1 to qty of first row.

    So in your search code, above, you want to first have some idea of everything the user has specified: size, color, shape, decoration, engraving, etc., so that you can compare all of them:
    PHP Code:
    if($add) {
      
    $attributes = array(
        
    'product' => 'Item_ID',
        
    'color' => 'color',
        
    'size' => 'size',
        
    'decoration' => 'decoration',
        
    'quantity' => 'quantity'
      
    );

      
    $add_item = array();

      foreach (
    $attributes as $post_var => $cart_var)
      {
        if (isset(
    $HTTP_POST_VARS[$post_var])) {
          
    $add_item[$cart_var] = $HTTP_POST_VARS[$post_var];
        }
      }

      
    // NOTE: You need better error-handling than this.
      
    if (!isset($add_item['Item_ID'])) {
        print 
    "You must specify an item.";
      }

      
    $cart = isset($HTTP_SESSION_VARS['cart'])
        ? 
    $HTTP_SESSION_VARS['cart']
        : array();

      foreach (
    $cart as $cart_item) {
        
    $found TRUE;
        foreach (
    $add_item as $attr => $value) {
          if (
    $cart_item[$attr] != $value) {
            
    $found FALSE;
            break;
          }
        }

        if (
    $found) {
          
    $cart_item['quantity'] += $add_item['quantity'];
          break;
        }
      }

      if (!
    $found) {
        
    $add_item['price'] = lookup_price($add_item);
        
    $cart[] = $add_item;
      }

      
    $HTTP_SESSION_VARS['items']  = count($cart);    
      
    $HTTP_SESSION_VARS['price'] += $add_item['price'] * $add_item['quantity'];

      
    $HTTP_SESSION_VARS['cart'] = $cart;

    Cheers,

    =Austin

  6. #31
    SitePoint Zealot
    Join Date
    Apr 2005
    Posts
    191
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for the advice mate, Im going to try it when I get back.

    So, this just puts items which are the same but with different sizes on different rows? Obviously Il have to edit it a bit it doesn't work with what Ive got. But Il give it a shot. If this works its then the problem of displaying...

    Cheers.

  7. #32
    SitePoint Zealot
    Join Date
    Apr 2005
    Posts
    191
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Just attempting to put that script into my lib file plays havoc, lol. Im guessing you've copied the code from somewhere else?

    Just that theres functions missing, e.g. lookup_price?

    Also in the array you create you state different things like:

    PHP Code:
        'product' => 'Item_ID'
        
    'color' => 'color'
        
    'size' => 'size'
        
    'decoration' => 'decoration'
        
    'quantity' => 'quantity' 
    My add an item to the cart form, looks like this...

    HTML Code:
    // Theres another variable here which is $Size
    
      <input type="hidden" name="add" value="1">
      <input type="hidden" name="product" value="<?php echo $product['Item_ID'];?>">
      <input type="hidden" name="price" value="<?php echo $product['UK_Price'];?>">
      <input type="hidden" name="name" value="<?php echo $product['Item_Name'];?>">
    So I have in total 5 variables being forwarded to the cart. $Size, $add, $product, $price and $name.

    So would I change the array you wrote to something like:

    PHP Code:
      $attributes = array( 
        
    'product' => '$product'
        
    'size' => '$Size'
        
    'quantity' => '1' 
      
    ); 

  8. #33
    SitePoint Evangelist
    Join Date
    May 2004
    Location
    New Jersey, USA
    Posts
    567
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hilly,

    Don't put that script in your application -- I made that stuff up!

    The mapping from 'product' => 'Item_ID' is there so you can convert field names from the names on your form (product, price, name) into the names you will use for the shopping cart/database. No variables!

    I used the mapping pairs as $post_var / $cart_var. So when I look up $_POST['product'] ($post_var) I know to store that into $cart['Item_ID'] ($cart_var).

    For the other stuff, you might have
    price => Item_Price,
    name => Item_Name

    It depends on the innards of your cart.

    I just put the map in one place so you could set up the mapping from HTML -> shopping cart one time and forget it.

    All that other stuff was in case you were selling fancy items that the user could configure via the page. If you don't have that, then delete them.

    The one obvious field is "add". That one is the quantity to buy on the HTML side, but I used 'quantity' throughout. You'll have to figure out what, if anything, the cart uses for that. (Item_Count, Item_Quantity, Quantity, Num_Items, How_Many, etc.)

    I put in lookup_price() because I really don't think you should be passing price via the form. (I know, I know, we had that argument. )

    You can put in
    PHP Code:
    function lookup_price() {
      return 
    $_POST['price'];

    and go on.


    Anyway, that wasn't meant to be a solution, so much as an example of how you could make a solution.

    Cheers,

    =Austin
    Austin Hastings - Principal Consultant - Longacre, Inc.

    Anything you can do, you can do better.

  9. #34
    SitePoint Zealot
    Join Date
    Apr 2005
    Posts
    191
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Austin_Hastings
    Hilly,

    Don't put that script in your application -- I made that stuff up!

    The mapping from 'product' => 'Item_ID' is there so you can convert field names from the names on your form (product, price, name) into the names you will use for the shopping cart/database. No variables!
    First off, thanks for the reply Austin.

    The thing is the way the database is set out is that there are a number of field names of various sizes (and the quantity of each item stored in those fields) e.g.

    Item_ID | Youth Small | Youth Medium | Youth Large | Small | Medium etc... etc...

    And the variable $Size posts the field name to the lib file, so it's necessary to have a variable in the $Size Array at least.

    And...

    'size' => '$Size',

    ...won't validate will it?

  10. #35
    SitePoint Zealot
    Join Date
    Apr 2005
    Posts
    191
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sorry mod / admin, but this thread isn't finished yet, Im still searching for help.

  11. #36
    does not play well with others frezno's Avatar
    Join Date
    Jan 2003
    Location
    Munich, Germany
    Posts
    1,391
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sorry to break into this thread but imho you should really considder using an id/sku for each item and style.
    Makes things much easier and is way more professional.

    To handle a cart then is pretty much a nobrainer - depending on your database structure
    We are the Borg. Resistance is futile. Prepare to be assimilated.
    I'm Pentium of Borg.Division is futile.Prepare to be approximated.

  12. #37
    SitePoint Zealot
    Join Date
    Apr 2005
    Posts
    191
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    So are you suggesting something like...

    tbl_ITEMS

    SizeCat_ID || Size ||

    1 No_Size
    2 Youth_Small
    3 Youth_Medium etc... etc...

    tbl_SubItems

    Item_ID || SizeCat_ID || Quantity

    1 1 15
    1 2 234
    1 3 0
    1 4 99

    What is a sku?


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •