Register for your free account! | Forgot your password?

Go Back   elitepvpers > Coders Den > Web Development
You last visited: Today at 16:56

  • Please register to post and access all features, it's quick, easy and FREE!

Advertisement



[Warenkorb] Zutat hinzufügen

Discussion on [Warenkorb] Zutat hinzufügen within the Web Development forum part of the Coders Den category.

Reply
 
Old   #1
 
Undaground's Avatar
 
elite*gold: 5
Join Date: Dec 2009
Posts: 1,474
Received Thanks: 1,421
[Warenkorb] Zutat hinzufügen

Hallo Com,

ich habe ein Warenkorb und ein kleines Problemchen.

Meine Demo:

Ich möchte weitere Optionsfelder bzw. Checkboxen in die Speisekarte mit reinbringen für die Zutaten.

Beispiel:

Pizza Salami:
ZUTATEN:
• Salami
• Sonstwas
• Dasauchnoch
|KLEIN|MITTEL|GROß|

Wie könnte ich diese optionen in das Script einbinden das es am Ende im Warenkorb mitangezeigt wird? Dazu müsste ich neue Variablen erstellen und dazugehörige Funktionen oder geht das einfacher?

Speisekarte ist ein einfaches Formular:

PHP Code:

<form method="post" class="jcart" action="">
                      <
fieldset>
                        <
input type="hidden" name="jcartToken" value="" /> 
                        <
input type="hidden" name="my-item-id" value="2" />
                        <
input type="hidden" name="my-item-qty" value="1" />
                        <
input type="hidden" name="my-item-name" value="Margherita mtl." />
                        <
input type="hidden" name="my-item-price" value="5.00" />
                      </
fieldset>
                        <
input type="submit" name="my-add-button" value="5,00 €" class="button" />
                    </
form
Da müsse ich Checkboxen für die jeweiligen Zutaten einbinden, soweit kann ich das ja aber in php habe ich sogut wie keine Erfahrung.

Warenkorb:

PHP Code:

<?php

// jCart v1.3
// http://conceptlogic.com/jcart/

//error_reporting(E_ALL);

// Cart logic based on Webforce Cart: http://www.webforcecart.com/
class Jcart {

    public 
$config     = array();
    private 
$items     = array();
    private 
$names     = array();
    private 
$prices    = array();
    private 
$qtys      = array();
    private 
$urls      = array();
    private 
$subtotal  0;
    private 
$itemCount 0;

    function 
__construct() {

        
// Get $config array
        
include_once('config-loader.php');
        
$this->config $config;
    }

    
/**
    * Get cart contents
    *
    * @return array
    */
    
public function get_contents() {
        
$items = array();
        foreach(
$this->items as $tmpItem) {
            
$item null;
            
$item['id']       = $tmpItem;
            
$item['name']     = $this->names[$tmpItem];
            
$item['price']    = $this->prices[$tmpItem];
            
$item['qty']      = $this->qtys[$tmpItem];
            
$item['url']      = $this->urls[$tmpItem];
            
$item['subtotal'] = $item['price'] * $item['qty'];
            
$items[]          = $item;
        }
        return 
$items;
    }

    
/**
    * Add an item to the cart
    *
    * @param string $id
    * @param string $name
    * @param float $price
    * @param mixed $qty
    * @param string $url
    *
    * @return mixed
    */
    
private function add_item($id$name$price$qty 1$url) {

        
$validPrice false;
        
$validQty false;

        
// Verify the price is numeric
        
if (is_numeric($price)) {
            
$validPrice true;
        }

        
// If decimal quantities are enabled, verify the quantity is a positive float
        
if ($this->config['decimalQtys'] === true && filter_var($qtyFILTER_VALIDATE_FLOAT) && $qty 0) {
            
$validQty true;
        }
        
// By default, verify the quantity is a positive integer
        
elseif (filter_var($qtyFILTER_VALIDATE_INT) && $qty 0) {
            
$validQty true;
        }

        
// Add the item
        
if ($validPrice !== false && $validQty !== false) {

            
// If the item is already in the cart, increase its quantity
            
if($this->qtys[$id] > 0) {
                
$this->qtys[$id] += $qty;
                
$this->update_subtotal();
            }
            
// This is a new item
            
else {
                
$this->items[]     = $id;
                
$this->names[$id]  = $name;
                
$this->prices[$id] = $price;
                
$this->qtys[$id]   = $qty;
                
$this->urls[$id]   = $url;
            }
            
$this->update_subtotal();
            return 
true;
        }
        elseif (
$validPrice !== true) {
            
$errorType 'price';
            return 
$errorType;
        }
        elseif (
$validQty !== true) {
            
$errorType 'qty';
            return 
$errorType;
        }
    }

    
/**
    * Update an item in the cart
    *
    * @param string $id
    * @param mixed $qty
    *
    * @return boolean
    */
    
private function update_item($id$qty) {

        
// If the quantity is zero, no futher validation is required
        
if ((int) $qty === 0) {
            
$validQty true;
        }
        
// If decimal quantities are enabled, verify it's a float
        
elseif ($this->config['decimalQtys'] === true && filter_var($qtyFILTER_VALIDATE_FLOAT)) {
            
$validQty true;
        }
        
// By default, verify the quantity is an integer
        
elseif (filter_var($qtyFILTER_VALIDATE_INT))    {
            
$validQty true;
        }

        
// If it's a valid quantity, remove or update as necessary
        
if ($validQty === true) {
            if(
$qty 1) {
                
$this->remove_item($id);
            }
            else {
                
$this->qtys[$id] = $qty;
            }
            
$this->update_subtotal();
            return 
true;
        }
    }


    
/* Using post vars to remove items doesn't work because we have to pass the
    id of the item to be removed as the value of the button. If using an input
    with type submit, all browsers display the item id, instead of allowing for
    user-friendly text. If using an input with type image, IE does not submit
    the    value, only x and y coordinates where button was clicked. Can't use a
    hidden input either since the cart form has to encompass all items to
    recalculate    subtotal when a quantity is changed, which means there are
    multiple remove    buttons and no way to associate them with the correct
    hidden input. */

    /**
    * Reamove an item from the cart
    *
    * @param string $id    *
    */
    
private function remove_item($id) {
        
$tmpItems = array();

        unset(
$this->names[$id]);
        unset(
$this->prices[$id]);
        unset(
$this->qtys[$id]);
        unset(
$this->urls[$id]);

        
// Rebuild the items array, excluding the id we just removed
        
foreach($this->items as $item) {
            if(
$item != $id) {
                
$tmpItems[] = $item;
            }
        }
        
$this->items $tmpItems;
        
$this->update_subtotal();
    }

    
/**
    * Empty the cart
    */
    
public function empty_cart() {
        
$this->items     = array();
        
$this->names     = array();
        
$this->prices    = array();
        
$this->qtys      = array();
        
$this->urls      = array();
        
$this->subtotal  0;
        
$this->itemCount 0;
    }

    
/**
    * Update the entire cart
    */
    
public function update_cart() {

        
// Post value is an array of all item quantities in the cart
        // Treat array as a string for validation
        
if (is_array($_POST['jcartItemQty'])) {
            
$qtys implode($_POST['jcartItemQty']);
        }

        
// If no item ids, the cart is empty
        
if ($_POST['jcartItemId']) {

            
$validQtys false;

            
// If decimal quantities are enabled, verify the combined string only contain digits and decimal points
            
if ($this->config['decimalQtys'] === true && preg_match("/^[0-9.]+$/i"$qtys)) {
                
$validQtys true;
            }
            
// By default, verify the string only contains integers
            
elseif (filter_var($qtysFILTER_VALIDATE_INT) || $qtys == '') {
                
$validQtys true;
            }

            if (
$validQtys === true) {

                
// The item index
                
$count 0;

                
// For each item in the cart, remove or update as necessary
                
foreach ($_POST['jcartItemId'] as $id) {

                    
$qty $_POST['jcartItemQty'][$count];

                    if(
$qty 1) {
                        
$this->remove_item($id);
                    }
                    else {
                        
$this->update_item($id$qty);
                    }

                    
// Increment index for the next item
                    
$count++;
                }
                return 
true;
            }
        }
        
// If no items in the cart, return true to prevent unnecssary error message
        
elseif (!$_POST['jcartItemId']) {
            return 
true;
        }
    }

    
/**
    * Recalculate subtotal
    */
    
private function update_subtotal() {
        
$this->itemCount 0;
        
$this->subtotal  0;

        if(
sizeof($this->items 0)) {
            foreach(
$this->items as $item) {
                
$this->subtotal += ($this->qtys[$item] * $this->prices[$item]);

                
// Total number of items
                
$this->itemCount += $this->qtys[$item];
            }
        }
    }

    
/**
    * Process and display cart
    */
    
public function display_cart() {

        
$config $this->config
        
$errorMessage null;

        
// Simplify some config variables
        
$checkout $config['checkoutPath'];
        
$priceFormat $config['priceFormat'];

        
$id    $config['item']['id'];
        
$name  $config['item']['name'];
        
$price $config['item']['price'];
        
$qty   $config['item']['qty'];
        
$url   $config['item']['url'];
        
$add   $config['item']['add'];

        
// Use config values as literal indices for incoming POST values
        // Values are the HTML name attributes set in config.json
        
$id    $_POST[$id];
        
$name  $_POST[$name];
        
$price $_POST[$price];
        
$qty   $_POST[$qty];
        
$url   $_POST[$url];

        
// Optional CSRF protection, see: http://conceptlogic.com/jcart/security.php
        
$jcartToken $_POST['jcartToken'];

        
// Only generate unique token once per session
        
if(!$_SESSION['jcartToken']){
            
$_SESSION['jcartToken'] = md5(session_id() . time() . $_SERVER['HTTP_USER_AGENT']);
        }
        
// If enabled, check submitted token against session token for POST requests
        
if ($config['csrfToken'] === 'true' && $_POST && $jcartToken != $_SESSION['jcartToken']) {
            
$errorMessage 'Invalid token!' $jcartToken ' / ' $_SESSION['jcartToken'];
        }

        
// Sanitize values for output in the browser
        
$id    filter_var($idFILTER_SANITIZE_SPECIAL_CHARSFILTER_FLAG_STRIP_LOW);
        
$name  filter_var($nameFILTER_SANITIZE_SPECIAL_CHARSFILTER_FLAG_STRIP_LOW);
        
$url   filter_var($urlFILTER_SANITIZE_URL);

        
// Round the quantity if necessary
        
if($config['decimalPlaces'] === true) {
            
$qty round($qty$config['decimalPlaces']);
        }

        
// Add an item
        
if ($_POST[$add]) {
            
$itemAdded $this->add_item($id$name$price$qty$url);
            
// If not true the add item function returns the error type
            
if ($itemAdded !== true) {
                
$errorType $itemAdded;
                switch(
$errorType) {
                    case 
'qty':
                        
$errorMessage $config['text']['quantityError'];
                        break;
                    case 
'price':
                        
$errorMessage $config['text']['priceError'];
                        break;
                }
            }
        }

        
// Update a single item
        
if ($_POST['jcartUpdate']) {
            
$itemUpdated $this->update_item($_POST['itemId'], $_POST['itemQty']);
            if (
$itemUpdated !== true)    {
                
$errorMessage $config['text']['quantityError'];
            }
        }

        
// Update all items in the cart
        
if($_POST['jcartUpdateCart'] || $_POST['jcartCheckout'])    {
            
$cartUpdated $this->update_cart();
            if (
$cartUpdated !== true)    {
                
$errorMessage $config['text']['quantityError'];
            }
        }

        
// Remove an item
        /* After an item is removed, its id stays set in the query string,
        preventing the same item from being added back to the cart in
        subsequent POST requests.  As result, it's not enough to check for
        GET before deleting the item, must also check that this isn't a POST
        request. */
        
if($_GET['jcartRemove'] && !$_POST) {
            
$this->remove_item($_GET['jcartRemove']);
        }

        
// Empty the cart
        
if($_POST['jcartEmpty']) {
            
$this->empty_cart();
        }

        
// Determine which text to use for the number of items in the cart
        
$itemsText $config['text']['multipleItems'];
        if (
$this->itemCount == 1) {
            
$itemsText $config['text']['singleItem'];
        }

        
// Determine if this is the checkout page
        /* First we check the request uri against the config checkout (set when
        the visitor first clicks checkout), then check for the hidden input
        sent with Ajax request (set when visitor has javascript enabled and
        updates an item quantity). */
        
$isCheckout strpos(request_uri(), $checkout);
        if (
$isCheckout !== false || $_REQUEST['jcartIsCheckout'] == 'true') {
            
$isCheckout true;
        }
        else {
            
$isCheckout false;
        }

        
// Overwrite the form action to post to gateway.php instead of posting back to checkout page
        
if ($isCheckout === true) {

            
// Sanititze config path
            
$path filter_var($config['jcartPath'], FILTER_SANITIZE_URL);

            
// Trim trailing slash if necessary
            
$path rtrim($path'/');

            
$checkout $path '/gateway.php';
        }

        
// Default input type
        // Overridden if using button images in config.php
        
$inputType 'submit';

        
// If this error is true the visitor updated the cart from the checkout page using an invalid price format
        // Passed as a session var since the checkout page uses a header redirect
        // If passed via GET the query string stays set even after subsequent POST requests
        
if ($_SESSION['quantityError'] === true) {
            
$errorMessage $config['text']['quantityError'];
            unset(
$_SESSION['quantityError']);
        }

        
// Set currency symbol based on config currency code
        
$currencyCode trim(strtoupper($config['currencyCode']));
        switch(
$currencyCode) {
            case 
'EUR':
                
$currencySymbol '€';
                break;
            case 
'GBP':
                
$currencySymbol '£';
                break;
            case 
'JPY':
                
$currencySymbol '¥';
                break;
            case 
'CHF':
                
$currencySymbol 'CHF&nbsp;';
                break;
            case 
'SEK':
            case 
'DKK':
            case 
'NOK':
                
$currencySymbol 'Kr&nbsp;';
                break;
            case 
'PLN':
                
$currencySymbol 'zł&nbsp;';
                break;
            case 
'HUF':
                
$currencySymbol 'Ft&nbsp;';
                break;
            case 
'CZK':
                
$currencySymbol 'Kč&nbsp;';
                break;
            case 
'ILS':
                
$currencySymbol '₪&nbsp;';
                break;
            case 
'TWD':
                
$currencySymbol 'NT$';
                break;
            case 
'THB':
                
$currencySymbol '฿';
                break;
            case 
'MYR':
                
$currencySymbol 'RM';
                break;
            case 
'PHP':
                
$currencySymbol 'Php';
                break;
            case 
'BRL':
                
$currencySymbol 'R$';
                break;
            case 
'USD':
            default:
                
$currencySymbol '€';
                break;
        }

        
////////////////////////////////////////////////////////////////////////
        // Output the cart

        // Return specified number of tabs to improve readability of HTML output
        
function tab($n) {
            
$tabs null;
            while (
$n 0) {
                
$tabs .= "\t";
                --
$n;
            }
            return 
$tabs;
        }

        
// If there's an error message wrap it in some HTML
        
if ($errorMessage)    {
            
$errorMessage "<p id='jcart-error'>$errorMessage</p>";
        }

        
// Display the cart header
        
echo tab(1) . "$errorMessage\n";
        echo 
tab(1) . "<form method='post' action='$checkout'>\n";
        echo 
tab(2) . "<fieldset>\n";
        echo 
tab(3) . "<input type='hidden' name='jcartToken' value='{$_SESSION['jcartToken']}' />\n";
        echo 
tab(3) . "<table border='1'>\n";
        echo 
tab(4) . "<thead>\n";
        echo 
tab(5) . "<tr>\n";
        echo 
tab(6) . "<th colspan='3'>\n";
        echo 
tab(7) . "<strong id='jcart-title'>{$config['text']['cartTitle']}</strong> ($this->itemCount $itemsText)\n";
        echo 
tab(6) . "</th>\n";
        echo 
tab(5) . "</tr>""\n";
        echo 
tab(4) . "</thead>\n";
        
        
// Display the cart footer
        
echo tab(4) . "<tfoot>\n";
        echo 
tab(5) . "<tr>\n";
        echo 
tab(6) . "<th colspan='3'>\n";

        
// If this is the checkout hide the cart checkout button
        
if ($isCheckout !== true) {
            if (
$config['button']['checkout']) {
                
$inputType "image";
                
$src " src='{$config['button']['checkout']}' alt='{$config['text']['checkout']}' title='' ";
            }
            echo 
tab(7) . "<input type='$inputType$src id='jcart-checkout' name='jcartCheckout' class='jcart-button' value='{$config['text']['checkout']}' />\n";
        }

        echo 
tab(7) . "<span id='jcart-subtotal'>{$config['text']['subtotal']}: <strong>$currencySymbolnumber_format($this->subtotal$priceFormat['decimals'], $priceFormat['dec_point'], $priceFormat['thousands_sep']) . "</strong></span>\n";
        echo 
tab(6) . "</th>\n";
        echo 
tab(5) . "</tr>\n";
        echo 
tab(4) . "</tfoot>\n";            
        
        echo 
tab(4) . "<tbody>\n";

        
// If any items in the cart
        
if($this->itemCount 0) {

            
// Display line items
            
foreach($this->get_contents() as $item)    {
                echo 
tab(5) . "<tr>\n";
                echo 
tab(6) . "<td class='jcart-item-qty'>\n";
                echo 
tab(7) . "<input name='jcartItemId[]' type='hidden' value='{$item['id']}' />\n";
                echo 
tab(7) . "<input id='jcartItemQty-{$item['id']}' name='jcartItemQty[]' size='2' type='text' value='{$item['qty']}' />\n";
                echo 
tab(6) . "</td>\n";
                echo 
tab(6) . "<td class='jcart-item-name'>\n";

                if (
$item['url']) {
                    echo 
tab(7) . "<a href='{$item['url']}'>{$item['name']}</a>\n";
                }
                else {
                    echo 
tab(7) . $item['name'] . "\n";
                }
                echo 
tab(7) . "<input name='jcartItemName[]' type='hidden' value='{$item['name']}' />\n";
                echo 
tab(6) . "</td>\n";
                echo 
tab(6) . "<td class='jcart-item-price'>\n";
                echo 
tab(7) . "<span>$currencySymbolnumber_format($item['subtotal'], $priceFormat['decimals'], $priceFormat['dec_point'], $priceFormat['thousands_sep']) . "</span><input name='jcartItemPrice[]' type='hidden' value='{$item['price']}' />\n";
                echo 
tab(7) . "<a class='jcart-remove' href='?jcartRemove={$item['id']}'>{$config['text']['removeLink']}</a>\n";
                echo 
tab(6) . "</td>\n";
                echo 
tab(5) . "</tr>\n";
            }
        }

        
// The cart is empty
        
else {
            echo 
tab(5) . "<tr><td id='jcart-empty' colspan='3'>{$config['text']['emptyMessage']}</td></tr>\n";
        }
        echo 
tab(4) . "</tbody>\n";
        echo 
tab(3) . "</table>\n\n";

        echo 
tab(3) . "<div id='jcart-buttons'>\n";

        if (
$config['button']['update']) {
            
$inputType "image";
            
$src " src='{$config['button']['update']}' alt='{$config['text']['update']}' title='' ";
        }

        echo 
tab(4) . "<input type='$inputType$src name='jcartUpdateCart' value='{$config['text']['update']}' class='jcart-button' />\n";

        if (
$config['button']['empty']) {
            
$inputType "image";
            
$src " src='{$config['button']['empty']}' alt='{$config['text']['emptyButton']}' title='' ";
        }

        echo 
tab(4) . "<input type='$inputType$src name='jcartEmpty' value='{$config['text']['emptyButton']}' class='jcart-button' />\n";
        echo 
tab(3) . "</div>\n";

        
// If this is the checkout display the PayPal checkout button
        
if ($isCheckout === true) {
            
// Hidden input allows us to determine if we're on the checkout page
            // We normally check against request uri but ajax update sets value to relay.php
            
echo tab(3) . "<input type='hidden' id='jcart-is-checkout' name='jcartIsCheckout' value='true' />\n";

            
// PayPal checkout button
            
if ($config['button']['checkout'])    {
                
$inputType "image";
                
$src " src='{$config['button']['checkout']}' alt='{$config['text']['checkoutPaypal']}' title='' ";
            }

            if(
$this->itemCount <= 0) {
                
$disablePaypalCheckout " disabled='disabled'";
            }

            echo 
tab(3) . "<input type='$inputType$src id='jcart-paypal-checkout' name='jcartPaypalCheckout' value='{$config['text']['checkoutPaypal']}$disablePaypalCheckout />\n";
        }

        echo 
tab(2) . "</fieldset>\n";
        echo 
tab(1) . "</form>\n\n";
        
        echo 
tab(1) . "<div id='jcart-tooltip'></div>\n";
    }
}

// Start a new session in case it hasn't already been started on the including page
@session_start();

// Initialize jcart after session start
$jcart $_SESSION['jcart'];
if(!
is_object($jcart)) {
    
$jcart $_SESSION['jcart'] = new Jcart();
}

// Enable request_uri for non-Apache environments
// See: http://api.drupal.org/api/function/request_uri/7
if (!function_exists('request_uri')) {
    function 
request_uri() {
        if (isset(
$_SERVER['REQUEST_URI'])) {
            
$uri $_SERVER['REQUEST_URI'];
        }
        else {
            if (isset(
$_SERVER['argv'])) {
                
$uri $_SERVER['SCRIPT_NAME'] . '?' $_SERVER['argv'][0];
            }
            elseif (isset(
$_SERVER['QUERY_STRING'])) {
                
$uri $_SERVER['SCRIPT_NAME'] . '?' $_SERVER['QUERY_STRING'];
            }
            else {
                
$uri $_SERVER['SCRIPT_NAME'];
            }
        }
        
$uri '/' ltrim($uri'/');
        return 
$uri;
    }
}
?>
config:

PHP Code:

<?php

// jCart v1.3
// http://conceptlogic.com/jcart/

// Do NOT store any sensitive info in this file!!!
// It's loaded into the browser as plain text via Ajax


////////////////////////////////////////////////////////////////////////////////
// REQUIRED SETTINGS

// Path to your jcart files
$config['jcartPath']              = 'jcart/';

// Path to your checkout page
$config['checkoutPath']           = 'checkout.php';

// The HTML name attributes used in your item forms
$config['item']['id']             = 'my-item-id';    // Item id
$config['item']['name']           = 'my-item-name';    // Item name
$config['item']['price']          = 'my-item-price';    // Item price
$config['item']['qty']            = 'my-item-qty';    // Item quantity
$config['item']['url']            = 'my-item-url';    // Item URL (optional)
$config['item']['add']            = 'my-add-button';    // Add to cart button
// Your PayPal secure merchant ID
// Found here: https://www.paypal.com/webapps/customerprofile/summary.view
$config['paypal']['id']           = '';

////////////////////////////////////////////////////////////////////////////////
// OPTIONAL SETTINGS

// Three-letter currency code, defaults to USD if empty
// See available options here: http://j.mp/agNsTx
$config['currencyCode']           = '';

// Add a unique token to form posts to prevent CSRF exploits
// Learn more: http://conceptlogic.com/jcart/security.php
$config['csrfToken']              = false;

// Override default cart text
$config['text']['cartTitle']      = 'Bestellung';    // Shopping Cart
$config['text']['singleItem']     = '';    // Item
$config['text']['multipleItems']  = '';    // Items
$config['text']['subtotal']       = 'Preis';    // Subtotal
$config['text']['update']         = '';    // update
$config['text']['checkout']       = 'Bestellung aufnehmen';    // checkout
$config['text']['checkoutPaypal'] = '';    // Checkout with PayPal
$config['text']['removeLink']     = 'Entfernen';    // remove
$config['text']['emptyButton']    = '';    // empty
$config['text']['emptyMessage']   = 'Leer';    // Your cart is empty!
$config['text']['itemAdded']      = 'Speiße hinzugefügt';    // Item added!
$config['text']['priceError']     = 'Ungültiger Preis Format';    // Invalid price format!
$config['text']['quantityError']  = '';    // Item quantities must be whole numbers!
$config['text']['checkoutError']  = 'Bestellung kann nicht aufgenommen werden';    // Your order could not be processed!

// Override the default buttons by entering paths to your button images
$config['button']['checkout']     = '';
$config['button']['paypal']       = '';
$config['button']['update']       = '';
$config['button']['empty']        = '';


////////////////////////////////////////////////////////////////////////////////
// ADVANCED SETTINGS

// Display tooltip after the visitor adds an item to their cart?
$config['tooltip']                = true;

// Allow decimals in item quantities?
$config['decimalQtys']            = false;

// How many decimal places are allowed?
$config['decimalPlaces']          = 1;

// Number format for prices, see: http://php.net/manual/en/function.number-format.php
$config['priceFormat']            = array('decimals' => 2'dec_point' => '.''thousands_sep' => ',');

// Send visitor to PayPal via HTTPS?
$config['paypal']['https']        = true;

// Use PayPal sandbox?
$config['paypal']['sandbox']      = false;

// The URL a visitor is returned to after completing their PayPal transaction
$config['paypal']['returnUrl']    = '';

// The URL of your PayPal IPN script
$config['paypal']['notifyUrl']    = '';

?>
Config-Loader.php
PHP Code:

<?php

// jCart v1.3
// http://conceptlogic.com/jcart/

// By default, this file returns the $config array for use with PHP scripts
// If requested via Ajax, the array is encoded as JSON and echoed out to the browser

// Don't edit here, edit config.php
include_once('config.php');

// Use default values for any settings that have been left empty
if (!$config['currencyCode']) $config['currencyCode']                     = 'USD';
if (!
$config['text']['cartTitle']) $config['text']['cartTitle']           = 'Shopping Cart';
if (!
$config['text']['singleItem']) $config['text']['singleItem']         = 'Item';
if (!
$config['text']['multipleItems']) $config['text']['multipleItems']   = 'Items';
if (!
$config['text']['subtotal']) $config['text']['subtotal']             = 'Subtotal';
if (!
$config['text']['update']) $config['text']['update']                 = 'update';
if (!
$config['text']['checkout']) $config['text']['checkout']             = 'checkout';
if (!
$config['text']['checkoutPaypal']) $config['text']['checkoutPaypal'] = 'Checkout with PayPal';
if (!
$config['text']['removeLink']) $config['text']['removeLink']         = 'remove';
if (!
$config['text']['emptyButton']) $config['text']['emptyButton']       = 'empty';
if (!
$config['text']['emptyMessage']) $config['text']['emptyMessage']     = 'Your cart is empty!';
if (!
$config['text']['itemAdded']) $config['text']['itemAdded']           = 'Item added!';
if (!
$config['text']['priceError']) $config['text']['priceError']         = 'Invalid price format!';
if (!
$config['text']['quantityError']) $config['text']['quantityError']   = 'Item quantities must be whole numbers!';
if (!
$config['text']['checkoutError']) $config['text']['checkoutError']   = 'Your order could not be processed!';

if (
$_GET['ajax'] == 'true') {
    
header('Content-type: application/json; charset=utf-8');
    echo 
json_encode($config);
}
?>

Ein Beispiel für eine Checkbox wäre nett wenn es mir jemand mal eintrichtern könnte :|
Undaground is offline  
Old 05/13/2015, 22:16   #2
 
RecK's Avatar
 
elite*gold: 20
Join Date: Jan 2009
Posts: 304
Received Thanks: 55
Dein PHP Skript hat mit dem eigentlichen Warenkorb doch nichts zu tun bis auf die eine Debugausgabe er Config wenn GET Parameter "ajax" mitübergeben wird, oder?

Also prinzipiell fügst du deine Checkboxen zu deinem HTML Formular hinzu.
HTML Code:
<input type="checkbox" name="zutat[zutatenname]">
In deinem PHP Skript wo du die Daten des Formulars entgegen nimmst, greifst du so auf deine Zutaten zu:
PHP Code:
$zutaten filter_input(INPUT_POST'zutaten'); // PHP >5 glaube ich, ansonsten $_POST['zutaten']
echo $zutaten['zutatenname']; // "on" wenn angeklickt 
RecK is offline  
Old 05/14/2015, 10:50   #3
 
Undaground's Avatar
 
elite*gold: 5
Join Date: Dec 2009
Posts: 1,474
Received Thanks: 1,421
Hier müsste es dann praktisch so aussehen?
PHP Code:

// Sanitize values for output in the browser
        
$id    filter_var($idFILTER_SANITIZE_SPECIAL_CHARSFILTER_FLAG_STRIP_LOW);
        
$name  filter_var($nameFILTER_SANITIZE_SPECIAL_CHARSFILTER_FLAG_STRIP_LOW);
        
$url   filter_var($urlFILTER_SANITIZE_URL);
                
$zutaten filter_input(INPUT_POST'zutaten');

echo 
$zutaten['zutatenname']; 
Undaground is offline  
Old 05/15/2015, 08:17   #4
 
RecK's Avatar
 
elite*gold: 20
Join Date: Jan 2009
Posts: 304
Received Thanks: 55
Also die Variablen $id, $name und $url müssten natürlich bereits vorab einen Wert zugewiesen bekommen, da du sie bereits verwendets.

Wenn du diverse Informationen zu den Zutaten hast, geht das auch so:

HTML Code:
<input type="text" name="zutaten[zutat1][name]" value="Zutatenname">
<input type="checkbox" name="zutaten[zutat1][verwendung]" checked>
PHP Code:
$zutaten filter_input(INPUT_POST'zutaten');
var_dump($zutaten['zutat1']); // ergibt: { name: 'Zutatenname', verwendung: 'on' } 
RecK is offline  
Reply


Similar Threads Similar Threads
[Js] Artikel zum Warenkorb hinzufügen
05/08/2015 - Web Development - 1 Replies
Hallou Com, Ich habe ein kleines Problemchen und zwar habe ich Warenkorb mit HTML, CSS und JS gefunden aber mir fehlt das nötige Wissen dazu wie ich ihn Funktionsfähig machen könnte. Ich habe eine Speisekarte die auf der selben Page sein soll und von dort aus sollen die Gerichte auch zum Warenkorb hibzugefügt werden. Ich wäre sehr dankbar wenn mir jemand ein Beispielcode für das hinzufügen von 1-2 Artikeln zeigen könnte. http://http://codepen.io/anon/pen/waMwQp
Problem mit Sessions bei Warenkorb
03/10/2013 - .NET Languages - 1 Replies
Erstmal Hallo, undzwar habe ich einen Warenkorb erstellt, leider habe ich das Problem, dass wenn ich auf "in den Warenkorb" klicke die Session und die ID nicht übernommen werden, also es nicht in den Warenkorb kommt. Ich wäre sehr dankbar für jegliche Hilfe hier die Codes: Ist auf jeder Seite, da hab ich die ID's der Sachen festgelegt und Preise + name als variablen... <?php ini_set("session.use_cookies", "0"); ini_set("url_rewriter.tags", ""); session_start();...
Suche auf Facebook Fanpage mit PayPal Warenkorb System
02/18/2012 - elite*gold Trading - 7 Replies
Wie oben schon steht suche ich jemanden der mir was machen könnte. Preis bin bereit bis zu 30 Euro zu bezahlen in E gold,ÜW,PSC und weiteres auf Anfrage. Preis für max. 25 Produkte die eingefügt werden müßen Beispiel so Sabines Schmuck | Facebook
HP/Warenkorb Hilfe!
05/25/2011 - General Coding - 2 Replies
Moin Moin, als erstes hoffe ich das ich in der richtigen Topic bin! :s Wenn nicht sagt bescheid ;) Also meine eigentliche Frage: Ich arbeite immoment an einer Homepage für eine Schulaufgabe (Informatik, um genau zusein). Wir sollen einen Online-Pizza-Service Dienst erstellen. Mit Datenbankanschluss und was sonst noch alles dazu gehört. Jedoch habe ich zwei Probleme: das erste ist, dass ich kein Code für einen "Warenkorb" finde (Im Sinne von Online bestellen, also zuerst Sachen dort...



All times are GMT +1. The time now is 16:57.


Powered by vBulletin®
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.
This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Support | Contact Us | FAQ | Advertising | Privacy Policy | Terms of Service | Abuse
Copyright ©2026 elitepvpers All Rights Reserved.