|
You last visited: Today at 23:38
Advertisement
jCart | PHP | IF Abfrage
Discussion on jCart | PHP | IF Abfrage within the Web Development forum part of the Coders Den category.
05/21/2015, 18:54
|
#1
|
elite*gold: 5
Join Date: Dec 2009
Posts: 1,474
Received Thanks: 1,421
|
jCart | PHP | IF Abfrage
Hey com,
in php ist mir alles neu weil es die erste Programmiersprache ist die ich angehe. Ich habe einen Warenkorb mit Produkten. So, wenn man nun das selbe Produkt 2 mal in den Warenkorb einfügt wird die Anzahl der Produkte dem selben Produkt im Warenkorb addiert. Mein Problem ist aber das ich diese extern eingefügt haben möchte aber dazu muss sich die ID vom ersten eingefügten Produkt unterscheiden.
Ich habe den Folgenden Code geändert:
PHP Code:
// If the item is already in the cart, increase its quantity if($this->qtys[$id] > 0) { $this->qtys[$id] += $qty; $this->update_subtotal(); }
in:
PHP Code:
// If the item is already in the cart, increase its quantity if($this->qtys[$id] > 0 and $this->qtys[$id] <= 1) { $this->id[] = $id ++; $this->qtys[$id] = $qty; $this->items[] = $id; $this->names[$id] = $name; $this->zutats[$id] = $zutat; $this->prices[$id] = $price; $this->qtys[$id] = $qty; $this->urls[$id] = $url; $this->update_subtotal(); }
Jetzt bekomme ich 1 Produkt extern eingefügt so wie ich das wollte, nun aber wenn ich mehr als 2 gleiche Produkte einfügen möchte wird es dem 2ten Produkt zugeordnet aufgrund der selben ID.
Mir geht es darum das ich im diese Produkte mit verschiedenen Optionen in den Warenkorb einfügen möchte, falls sich jemand fragt warum überhaupt.
Wie könnte ich vergleichen ob die eingefügte ID schon einmal vorhanden ist um dann dem nächsten Produkt eine andere ID zu geben?
|
|
|
05/21/2015, 19:15
|
#2
|
elite*gold: 0
Join Date: Jan 2009
Posts: 731
Received Thanks: 233
|
moin,
ich bin mir nicht ganz sicher ob ich das problem richtig verstanden habe, da die code zeilen nicht unbedingt viel erklären.
Zum Prüfen ob eine Id schon in einem Array vorhanden ist, was vermutlich bei dir $this->qtys ist, könntest du via "isset($this->qtys[$id])" prüfen, aber um dir da richtig zu helfen brauch man da um einiges mehr background wissen von dem system, meiner meinung als die paar zeilchen =).
|
|
|
05/21/2015, 19:29
|
#3
|
elite*gold: 5
Join Date: Dec 2009
Posts: 1,474
Received Thanks: 1,421
|
Also das hier ist der ganze code:
jcart.php
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 $zutats = 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['zutat'] = $this->zutats[$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 string $zutat * @param float $price * @param mixed $qty * @param string $url * * @return mixed */ private function add_item($id, $name, $price, $qty = 1, $url, $zutat) {
$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($qty, FILTER_VALIDATE_FLOAT) && $qty > 0) { $validQty = true; } // By default, verify the quantity is a positive integer elseif (filter_var($qty, FILTER_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 and $this->qtys[$id] <= 1) { $this->id[] = $id ++; $this->qtys[$id] = $qty; $this->items[] = $id; $this->names[$id] = $name; $this->zutats[$id] = $zutat; $this->prices[$id] = $price; $this->qtys[$id] = $qty; $this->urls[$id] = $url; $this->update_subtotal(); } // This is a new item else { $this->items[] = $id; $this->names[$id] = $name; $this->zutats[$id] = $zutat; $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($qty, FILTER_VALIDATE_FLOAT)) { $validQty = true; } // By default, verify the quantity is an integer elseif (filter_var($qty, FILTER_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->zutats[$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->zutats = 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($qtys, FILTER_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']; $zutat = $config['item']['zutat']; $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]; $zutat = $_POST[$zutat]; $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($id, FILTER_SANITIZE_SPECIAL_CHARS, FILTER_FLAG_STRIP_LOW); $name = filter_var($name, FILTER_SANITIZE_SPECIAL_CHARS, FILTER_FLAG_STRIP_LOW); $zutat = filter_var($zutat, FILTER_SANITIZE_SPECIAL_CHARS, FILTER_FLAG_STRIP_LOW); $url = filter_var($url, FILTER_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, $zutat); // 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 '; break; case 'SEK': case 'DKK': case 'NOK': $currencySymbol = 'Kr '; break; case 'PLN': $currencySymbol = 'zł '; break; case 'HUF': $currencySymbol = 'Ft '; break; case 'CZK': $currencySymbol = 'Kč '; break; case 'ILS': $currencySymbol = '₪ '; 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>$currencySymbol" . number_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"; echo tab(7) . "<br>{$item['zutat']}\n"; } else { echo tab(7) . $item['name'] . "\n"; echo tab(7) . "<br> {$item['zutat']} \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>$currencySymbol" . number_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; } } ?>
in der index.php ist die form mit den ID´s
HTML Code:
<?php
// jCart v1.3
// http://conceptlogic.com/jcart/
// This file demonstrates a basic store setup
// If your page calls session_start() be sure to include jcart.php first
include_once('jcart/jcart.php');
session_start();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>jCart - Free Ajax/PHP shopping cart</title>
<link rel="stylesheet" type="text/css" media="screen, projection" href="style.css" />
<link rel="stylesheet" type="text/css" media="screen, projection" href="jcart/css/jcart.css" />
</head>
<body>
<div id="wrapper">
<h2>Demo Store</h2>
<div id="sidebar">
<div id="jcart"><?php $jcart->display_cart();?></div>
</div>
<div id="content">
<form method="post" action="" class="jcart">
<fieldset>
<input type="hidden" name="jcartToken" value="<?php echo $_SESSION['jcartToken'];?>" />
<input type="hidden" name="my-item-id" value="ABC-123" />
<input type="hidden" name="my-item-name" value="Soccer Ball" />
<input type="hidden" name="my-item-price" value="25.00" />
<input type="hidden" name="my-item-url" value="" />
<input type="checkbox" name="my-item-zutat" value="Zutat" /> Zutat 1
<ul>
<li><strong>Soccer Ball</strong></li>
<li>Price: $25.00</li>
<li>
<label>Qty: <input type="text" name="my-item-qty" value="1" size="3" /></label>
</li>
</ul>
<input type="submit" name="my-add-button" value="add to cart" class="button" />
</fieldset>
</form>
<form method="post" action="" class="jcart">
<fieldset>
<input type="hidden" name="jcartToken" value="<?php echo $_SESSION['jcartToken'];?>" />
<input type="hidden" name="my-item-id" value="PROD-123" />
<input type="hidden" name="my-item-name" value="Baseball Mitt" />
<input type="hidden" name="my-item-price" value="19.50" />
<input type="hidden" name="my-item-url" value="http://yahoo.com" />
<ul>
<li><strong>Baseball Mitt</strong></li>
<li>Price: $19.50</li>
<li>
<label>Qty: <input type="text" name="my-item-qty" value="1" size="3" /></label>
</li>
</ul>
<input type="submit" name="my-add-button" value="add to cart" class="button" />
</fieldset>
</form>
<form method="post" action="" class="jcart">
<fieldset>
<input type="hidden" name="jcartToken" value="<?php echo $_SESSION['jcartToken'];?>" />
<input type="hidden" name="my-item-id" value="DOP-123" />
<input type="hidden" name="my-item-name" value="Hockey Stick" />
<input type="hidden" name="my-item-price" value="33.25" />
<input type="hidden" name="my-item-url" value="http://bing.com" />
<ul>
<li><strong>Hockey Stick</strong></li>
<li>Price: $33.25</li>
<li>
<label>Qty: <input type="text" name="my-item-qty" value="1" size="3" /></label>
</li>
</ul>
<input type="submit" name="my-add-button" value="add to cart" class="button tip" />
</fieldset>
</form>
<div class="clear"></div>
<p><small>Having trouble? <a href="jcart/server-test.php">Test your server settings.</a></small></p>
<?php
//echo '<pre>';
//var_dump($_SESSION['jcart']);
//echo '</pre>';
?>
</div>
<div class="clear"></div>
</div>
<script type="text/javascript" src="jcart/js/jquery-1.4.4.min.js"></script>
<script type="text/javascript" src="jcart/js/jcart.min.js"></script>
</body>
</html>
Die ID vom ersten Produkt ist z.B ABC-123
mit dem
PHP Code:
$this->id[] = $id ++;
wird diese auf ABC-124 geändert
jetzt möchte ich aber prüfen ob die geänderte ID schon vorhanden ist um diese weiter zu ändern weil sonst immer die ABC-123 auf die ABC-124 geändert wird und ich damit nicht mehr als 2 Produkte einfügen kann :/
|
|
|
05/21/2015, 19:30
|
#4
|
elite*gold: 0
Join Date: Jun 2013
Posts: 405
Received Thanks: 84
|
Das Ganze könntest du eigentlich mit der if-Bedingung, die KoKsPfLaNzE schon gepostet hat, umsetzen. Falls ein Produkt schon im Warenkorb ist, kannst du es mit den Operatoren ++ um eins erhöhen.
Aber wie mein Vorposter schon schrieb, da braucht es mehr Codezeilen und/oder Backgroundwissen von deinem System.
Edit: Ich schaue mir deinen Code nachher mal an, wenn ich Zeit finde.
Edit2: Also ich habe mir das jcart Skript mal auf meinen Server gezogen und bei mir funktioniert es ohne Probleme. Manchmal ist von vorne Anfangen eine bessere Lösung. Was hast du denn an dem Skript geändert, dass es nicht mehr geht? Oder was wolltest du ändern?
|
|
|
05/21/2015, 19:36
|
#5
|
elite*gold: 5
Join Date: Dec 2009
Posts: 1,474
Received Thanks: 1,421
|
Ich tüftel noch ein bisschen rum in der Hoffnung das ich das hinbekomme aber würde mich über Hilfe sehr freuen
EDIT:
Ich glaube ich wurde falsch verstanden sorry weis nicht genau wie ich das erklären soll.
Also wenn ich z.B. Soccerball 2 mal in den Warenkorb einfüge, wird die Anzahl davon im Warenkorb auf 2 gestellt.
Aber ich möchte das Soccerball extern als 2tes Produkt mit einer anderen ID zum Warenkorb hinzugefügt wird
Bis 2 Produkten klappt es aber leider nicht mit mehr:
// Falls jemand selber Interesse an jCart hat ist hier ein altes Forum indem einige Probleme behandelt worden sind aber seit Ende der Weiterarbeit an dem Projekt leider geschlossen ist.
|
|
|
05/21/2015, 20:01
|
#6
|
elite*gold: 0
Join Date: Jun 2013
Posts: 405
Received Thanks: 84
|
Achso, jetzt versteh ich! Ich schaue mir das demnächst mal an.
|
|
|
05/21/2015, 20:49
|
#7
|
elite*gold: 5
Join Date: Dec 2009
Posts: 1,474
Received Thanks: 1,421
|
isset hat mir geholfen danke
Das ganze mit einer while Schleife war perfekt
PHP Code:
// If the item is already in the cart, increase its quantity if(isset($this->qtys[$id])) {
$this->id[] = $id ++; while(isset($this->qtys[$id])) { $this->id[] = $id ++; } $this->qtys[$id] = $qty; $this->items[] = $id; $this->names[$id] = $name; $this->zutats[$id] = $zutat; $this->prices[$id] = $price; $this->qtys[$id] = $qty; $this->urls[$id] = $url;
$this->update_subtotal(); }
Aber da ich viele Produkte habe die alle ID´s von 1-1000 haben wird z.B beim erstellen einer ID die "2" heißt damit wird eine bereits vorhandene ID überschrieben im Warenkorb.
Wenn ich z.B.
PHP Code:
$this->id[] = $id + 1000;
mach funktioniert das ganze nicht mehr
|
|
|
05/21/2015, 21:16
|
#8
|
elite*gold: 0
Join Date: Jan 2009
Posts: 731
Received Thanks: 233
|
Hab mir das script ma kurz angeguckt, hab leider gerade wenig Zeit das ma aufzusetzen un co. Aber es ist ziehmlich einfach erklärt du musst dich von dem Artikel Ids in dem Array Trennen und einfach eine Fortlaufendenummer eintragen. dir irgendwelche nummer zu berechnen bringt nichts, das macht nur neue Probleme, die aktuellen nummern werden in der "items" property gespeichert, somit sollte das ja kein großes problem sein, oder?
Will ungern den code-posten da lernst ja nix bei=)
|
|
|
05/21/2015, 21:21
|
#9
|
elite*gold: 5
Join Date: Dec 2009
Posts: 1,474
Received Thanks: 1,421
|
Hab das Problem ja schon gelöst danke  aber was kann ich anstatt ++ verwenden?
Möchte die ID "ABC-123" z.B. um 1000 erweitern was kann ich da machen?
|
|
|
05/21/2015, 21:23
|
#10
|
elite*gold: 0
Join Date: Jan 2009
Posts: 731
Received Thanks: 233
|
weil du die id mit 1000 addierst un das result, in eine andere property speicherst die sonst nicht verwendet wird. bei dem ++ un die schleife, da wird die id ja auch höher genommen.
du müsstest $id = $id + 1000 rechnen, aber schön is das net =(
|
|
|
05/21/2015, 21:48
|
#11
|
elite*gold: 5
Join Date: Dec 2009
Posts: 1,474
Received Thanks: 1,421
|
Quote:
Originally Posted by KoKsPfLaNzE
weil du die id mit 1000 addierst un das result, in eine andere property speicherst die sonst nicht verwendet wird. bei dem ++ un die schleife, da wird die id ja auch höher genommen.
du müsstest $id = $id + 1000 rechnen, aber schön is das net =(
|
Genau das habe ich auch versucht aber habe mich inzwischen für die übersichtlichere Lösung entschieden die ID´s meiner Produkte einfach anders zu beschreiben z.B. Pizza-Salami-1, Pizza-Margheritta-1
Danke
|
|
|
 |
Similar Threads
|
If Abfrage
03/17/2014 - Web Development - 0 Replies
-
Hat sich erledigt
#closerquest
|
AFK Abfrage ?
09/05/2012 - Guild Wars 2 - 4 Replies
Servus, habe grad bissel an meinem eigenen Bot rumgeschraut der nu auch laufen kann und auch das ein oder andere Event erledigt. So nun lasse ich ihn die dritte Testrunde laufen und bekomm aufeinmal ein Fenster (wie die normalen fenster wenn man mit einem NPC spricht) und dort steht " Wer ist der Moa wer ist der Mann ?" und als antwort möglichkeiten gabs Rechts , Links und in der Mitte. Dazu läuft eine art Counter runter. Ich hab aus Schock erstmal irgendwo draufgekickt. Ne minute später kam...
|
Abfrage in dec?
12/02/2010 - General Coding - 7 Replies
Hallo Leute,
ich habe mir hier schnell ein kleines Programm zum üben geschrieben und hab nun eine Frage.
Der Code sieht so aus:
/*
Autor: ******
E-mail: ******
Datum: 28.11.2010
Programm: Check if letter is uppercase or not
|
If abfrage
12/29/2009 - AutoIt - 8 Replies
Hallo leute.
Wollt ma fragen ob mir jemand sagen könnte wie ich abfragen kan ob in einer input box z.b steht xD und dan in der if abfrage so abfragen könnte wen dort xD steht das er z.b das script schliest weis das einer?
|
All times are GMT +1. The time now is 23:38.
|
|