#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2000
    Posts
    0
    Rep Power
    0
    Hi,

    I am wondering how to split a var like $cart which after the form is process holds the entire information of the shopping cart including prices, item descriptions, ect ect,.

    I need to split this apart so I can put things in their own fields and am not sure how to go about it. I would like to have it so I can use the data in a nice form in stead of two strings of text.

    for example:

    PRODUCT:
    $product_info
    Price:
    $product_price

    Thanks I hope this is clear I am not sure quite how to explain it any better than this!

    See ya,

    THANKS AGAIN!!
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2000
    Posts
    71
    Rep Power
    15
    How did you get one string with all that information at first place?
    Could you show example how that string looks like?
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2000
    Posts
    0
    Rep Power
    0
    You can use the split() function to seperate the contents of cart if u have a delimiter e.g. $cart='Vibrator|12|XL';
    ($product,$price,$size)=split(/|/,$cart);

    however if u aint got no deliminters and you wanna split the string then your just making life extremly hard for yourself. You mention forms? is the $cart information gained from a CGI form? if so use &ReadParse from cgi-lib.pl to create a nice hash for you. However this is a bit passe i think now and you should be using CGI.pm
  6. #4
  7. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2000
    Posts
    0
    Rep Power
    0
    Well first off the cart is a service that I signed up with (mals-e.com). Mals service allows to do a call fununction so I can attact a scrip on my own server to do special things. Right now that special thing is just to send a html e-mail to me and the client. I have included the script that I have worked on below....

    #!/usr/local/bin/perl


    $| = 1;

    # Path to send mail instead by uncommenting this line
    $SEND_MAIL="/usr/sbin/sendmail -t";

    # The email's subject line
    $subject1= "Order receipt from";
    $subject2= "New Online Order Posted";

    # Your email address
    # The backslash before the @ in the address is IMPORTANT!
    $sender = "accounts@globalsoft.net";


    # This part takes the incomming query string and
    # parses it into seperate fields with the names
    # $Data{'field_name'}

    @pairs = split(/&/, $ENV{'QUERY_STRING'});
    # For each name-value pair:
    foreach $pair (@pairs) {

    # Split the pair up into individual variables.
    local($name, $value) = split(/=/, $pair);

    # Decode the form encoding on the name and value variables.
    $name =~ tr/+/ /;
    $name =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;

    $value =~ tr/+/ /;
    $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;

    if ($value) {
    $Data{$name} = $value;
    }
    }

    # Output a header. We must do this!
    print "Content-type: text/htmlnn";

    # If there is no recipient for the message
    # then stop here
    if ( ! $Data{'email'} ) {
    print "No sender email address";
    exit;
    }

    # The cart is delimited by ~ between lines so
    # replace these with a n new line
    $cart = "";
    @lines = split(/~/, $Data{'cart'});
    foreach $item (@lines) {
    $cart .= $item . "n";
    }

    # The next three blocks remove the undocumented {br}
    # and the {b} and {/b} (line break and bold tags) present
    # in the cart input strings so they don't show up in the email.

    $new = "";
    @lines1 = split(/{br}/, $cart);
    foreach $item (@lines1) {
    $new .= $item . "n";
    }

    $cart = $new;
    $new = "";
    @lines2 = split(/{b}/, $cart);
    foreach $item (@lines2) {
    $new .= $item. "";
    }

    $cart = $new;
    $new = "";
    @lines3 = split(/{/b}/, $cart);
    foreach $item (@lines3) {
    $new .= $item . "";
    }

    $cart = $new;


    # This routine parses the shipping_zone value into the $zone
    # string which will print out the actual shipping method selected.


    if ( $Data{'shipping_zone'} eq 1 ) { $zone = "UPS Ground"; }
    elsif ( $Data{'shipping_zone'} eq 2 ) { $zone = "UPS 3-Day Select";
    }
    elsif ( $Data{'shipping_zone'} eq 3 ) { $zone = "UPS 2nd Day Air"; }
    elsif ( $Data{'shipping_zone'} eq 4 ) { $zone = "UPS Next Day Air";
    }
    else { $zone = "International Priority Mail"; }

    # We build up the body of the messagefor the e-mail to the customer
    $message1 = "nThank you for your order $Data{'inv_name'}. Bellow is a summary of your purchase, as well as your order information.

    Customer Id : $Data{'id'}
    Date : $Data{'date'}
    For payment by $Data{'method'}

    Product , Quantity , Price
    ==========================
    $cart

    Discount : -$Data{'discount'}
    Subtotal : $Data{'subtotal'}
    Shipping : $Data{'shipping'}
    Tax : $Data{'tax'}
    -------------
    TOTAL : $Data{'total'}

    Invoice To:
    $Data{'inv_name'}
    $Data{'inv_addr1'}
    $Data{'inv_addr2'}
    $Data{'inv_state'}
    $Data{'inv_zip'}
    $Data{'inv_country'}
    $Data{'tel'}
    $Data{'fax'}
    $Data{'email'}


    If you have any questions about your order please do not hesitate
    to contact us. You can reply to this email, or call us directly at your number.
    ";

    # There are two extra fields that are not included in this sample
    # they are Data{'message'} and Data{'ip'}.

    # And this actually sends the email
    if ($SEND_MAIL ne "")
    {
    open (MAIL,"| $SEND_MAIL");

    print MAIL "To: $Data{'email'}n";
    print MAIL "From: $sendern";
    print MAIL "Reply-to: $sendern";
    print MAIL "X-Mailer: Perl Powered Socket Mailern";
    print MAIL "Subject: $subject1nn";
    print MAIL "$message1";
    print MAIL "n.n";

    close(MAIL);
    }

    {
    open (MAIL,"| $SEND_MAIL");
    print MAIL "To: $Data{'email'}n";
    print MAIL "From: $sendern";
    print MAIL "Reply-to: $sendern";
    print MAIL "X-Mailer: Perl Powered Socket Mailern";
    print MAIL "Subject: $subject2n";
    print MAIL "Content-Type: text/html; charset="us ascii"n";

    open (HTML,"email.html") | | die $!;

    while(<HTML> ){
    print MAIL eval("qq($_)");
    }
    }
    close(HTML);
    close(MAIL);


    # Confirmation - Dont' cut this off, it lets my server
    # know that the transfer is finished
    print "Success<br>Sent to $Data{'email'}n";

    # End of script!

    Their is of course 1 text e-mail and 1 html being sent. This is what happens currently with just '$cart' in the text e-mail and the same thing happens in the html e-mail.

    Product , Quantity , Price
    ==========================
    some item : 1 : 10
    some item: 1 : 20
    some item : 1 : 30
    some item : 1 : 40

    I want to be something like this
    Product Quantity, Price
    $cart_itemincart $cart_quanity $cart_price
    $cart_itemincart $cart_quanity $cart_price
    $cart_itemincart $cart_quanity $cart_price
    $cart_itemincart $cart_quanity $cart_price

    of couse it would be diffrent number of items for each person that buys something but if I can't do it that way how to do I change the output so it looks at least readable!!!

    The other thing is with the message field box from the cart .. I setup a form outside of the cart for people to fill first with certain types of information. When they are finished it pushes the information into the message box in the shopping cart. this is information will look like something like this ....
    agree | asdfasdf | sdfasdf | asdf | 46456 | INSERT YOUR OWN COMMENTS HERE!


    This information is assinged to $message and I want to beable to split this up also into little vars so I can pick out certain data and use it other places in the e-mail confirmation return.


    I have probably opend up a new can of worms and have made everyone really confused! LOL sorry about that! What I want may not be possible but I thought I would try. I asked the owner of the cart but he doesn't know perl or have the time to worry about everyones problems (this is a free service of course) The only solution he mentioned was to try to split up the var.


    thanks
  8. #5
  9. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2000
    Posts
    0
    Rep Power
    0
    I got it working!! Thanks everyone!

IMN logo majestic logo threadwatch logo seochat tools logo