Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

CHECKOUT_PROCESS stock error


Guest

Recommended Posts

Maybe this as been answered before but I am not able to find the answer in the forum.

 

I have to make a complete count of my phisical stock 2 times in the month becouse of some erros in the stock. In the beggining I suppose that these erros are originating from bad human operation but they seem to be a constant. Every month I have some erros in the stock, so I start to track when these erros occur. I found that when there is a lot of people at the same time in the store the erros are more frequently. The problem is this:

 

-I have only 1 item in the stock of a "blue ball" ( example ).

-There are 2 customers with this ball in the shopping cart.

-The customer A go trough the checkout_shipping

-The customers B go trough the checkout_shipping

At this point the check for the low stock is working fine, if the stock dont have enought quantity of the product the customer is informed.

-The customer A go trough the checkout_payment

-The customer B go trough the checkout_payment

Until now the low stock is working too.

-The customer A go trough the checkout_confirmation

-The customer B go trough the checkout_confirmation

-The customer A click on the confirmation button and go to the checkou_success

-The stock for this product is decremented, in this example it goes to zero because I only have one ball in the stock.

-The customer B that already was in the checkout_confirmation click on the confirmation button. And the store ALLOW the order to be created without checking the stock level!!!

 

How to make a checking of the stock level in the checkout_confirmation when clicking in the confirmation button?

I have to make this in the checkout_process?

Link to comment
Share on other sites

I understand ... well yes the checkout_process.php file logic would have to be changed. Rigth now does the payment before process, then it enters a bunch of info into the database and then loops through your products. You need to pull that looping pretty much to the top (before payment) and redirect to the cart if stock is checked and stock == 0. This is the relevant part:

 

  for ($i=0, $n=sizeof($order->products); $i<$n; $i++) {
// Stock Update - Joao Correia
if (STOCK_LIMITED == 'true') {
  if (DOWNLOAD_ENABLED == 'true') {
	$stock_query_raw = "SELECT products_quantity, pad.products_attributes_filename 
						FROM " . TABLE_PRODUCTS . " p
						LEFT JOIN " . TABLE_PRODUCTS_ATTRIBUTES . " pa
						 ON p.products_id=pa.products_id
						LEFT JOIN " . TABLE_PRODUCTS_ATTRIBUTES_DOWNLOAD . " pad
						 ON pa.products_attributes_id=pad.products_attributes_id
						WHERE p.products_id = '" . tep_get_prid($order->products[$i]['id']) . "'";
// Will work with only one option for downloadable products
// otherwise, we have to build the query dynamically with a loop
	$products_attributes = $order->products[$i]['attributes'];
	if (is_array($products_attributes)) {
	  $stock_query_raw .= " AND pa.options_id = '" . $products_attributes[0]['option_id'] . "' AND pa.options_values_id = '" . $products_attributes[0]['value_id'] . "'";
	}
	$stock_query = tep_db_query($stock_query_raw);
  } else {
	$stock_query = tep_db_query("select products_quantity from " . TABLE_PRODUCTS . " where products_id = '" . tep_get_prid($order->products[$i]['id']) . "'");
  }
  if (tep_db_num_rows($stock_query) > 0) {
	$stock_values = tep_db_fetch_array($stock_query);
// do not decrement quantities if products_attributes_filename exists
	if ((DOWNLOAD_ENABLED != 'true') || (!$stock_values['products_attributes_filename'])) {
	  $stock_left = $stock_values['products_quantity'] - $order->products[$i]['qty'];
	} else {
	  $stock_left = $stock_values['products_quantity'];
	}
	tep_db_query("update " . TABLE_PRODUCTS . " set products_quantity = '" . $stock_left . "' where products_id = '" . tep_get_prid($order->products[$i]['id']) . "'");
	if ( ($stock_left < 1) && (STOCK_ALLOW_CHECKOUT == 'false') ) {
	  tep_db_query("update " . TABLE_PRODUCTS . " set products_status = '0' where products_id = '" . tep_get_prid($order->products[$i]['id']) . "'");
	}
  }
}

 

make your check on the $stock_left and do not manipulate the database unless enough stock is there

:-)

Monika

 

addicted to writing code ... can't get enough of databases either, LOL!

 

my toolbox: Textpad - Compare and Merge - phpMyAdmin - WS_FTP - Photoshop - How to search the forum

 

Interactive Media Award July 2007 ~ category E-Commerce

my advice on the forum is for free, PMs where you send me work are considered consultation which I charge for ...

Link to comment
Share on other sites

Thanks Monika,

 

but I am more a network administrator them a PHP programmer. :) I know a little of PHP and some things about OSCOMMERCE but I have to confess that the logic of the checkout_process is a litle confusing to me. My checkout_proccess also have some minor changes due to some contributions.

Could you help me to put the code in the right place in caheckout_process?

 

PS: Sorry for the bad English.

 

My checkout_process:

 

<?php
/*
 $Id: checkout_process.php,v 1.128 2003/05/28 18:00:29 hpdl Exp $

 osCommerce, Open Source E-Commerce Solutions
 http://www.oscommerce.com

 Copyright (c) 2003 osCommerce

 Released under the GNU General Public License
*/

 include('includes/application_top.php');

// if the customer is not logged on, redirect them to the login page
 if (!tep_session_is_registered('customer_id')) {
$navigation->set_snapshot(array('mode' => 'SSL', 'page' => FILENAME_CHECKOUT_PAYMENT));
tep_redirect(tep_href_link(FILENAME_LOGIN, '', 'SSL'));
 }

 if (!tep_session_is_registered('sendto')) {
tep_redirect(tep_href_link(FILENAME_CHECKOUT_PAYMENT, '', 'SSL'));
 }

 if ( (tep_not_null(MODULE_PAYMENT_INSTALLED)) && (!tep_session_is_registered('payment')) ) {
tep_redirect(tep_href_link(FILENAME_CHECKOUT_PAYMENT, '', 'SSL'));
}

// avoid hack attempts during the checkout procedure by checking the internal cartID
 if (isset($cart->cartID) && tep_session_is_registered('cartID')) {
if ($cart->cartID != $cartID) {
  tep_redirect(tep_href_link(FILENAME_CHECKOUT_SHIPPING, '', 'SSL'));
}
 }

 include(DIR_WS_LANGUAGES . $language . '/' . FILENAME_CHECKOUT_PROCESS);

// load selected payment module
 require(DIR_WS_CLASSES . 'payment.php');
 $payment_modules = new payment($payment);

// load the selected shipping module
 require(DIR_WS_CLASSES . 'shipping.php');
 $shipping_modules = new shipping($shipping);

 require(DIR_WS_CLASSES . 'order.php');
 $order = new order;

// load the before_process function from the payment modules
 $payment_modules->before_process();

// account balance mod
$begin_account_balance_query = tep_db_query("select customers_account_balance from " . TABLE_CUSTOMERS . " where customers_id = '" . (int)$customer_id . "'");
$begin_account_balance_result = tep_db_fetch_array($begin_account_balance_query);
$begin_account_balance = tep_round($begin_account_balance_result['customers_account_balance'],2);
//end mod


 require(DIR_WS_CLASSES . 'order_total.php');
 $order_total_modules = new order_total;

 $order_totals = $order_total_modules->process();

 $sql_data_array = array('customers_id' => $customer_id,
					  'customers_name' => $order->customer['firstname'] . ' ' . $order->customer['lastname'],
					  'customers_company' => $order->customer['company'],
					  'customers_street_address' => $order->customer['street_address'],
					  'customers_suburb' => $order->customer['suburb'],
					  'customers_city' => $order->customer['city'],
					  'customers_postcode' => $order->customer['postcode'], 
					  'customers_state' => $order->customer['state'], 
					  'customers_country' => $order->customer['country']['title'], 
					  'customers_telephone' => $order->customer['telephone'], 
					  'customers_email_address' => $order->customer['email_address'],
					  'customers_address_format_id' => $order->customer['format_id'], 
					  'delivery_name' => $order->delivery['firstname'] . ' ' . $order->delivery['lastname'], 
					  'delivery_company' => $order->delivery['company'],
					  'delivery_street_address' => $order->delivery['street_address'], 
					  'delivery_suburb' => $order->delivery['suburb'], 
					  'delivery_city' => $order->delivery['city'], 
					  'delivery_postcode' => $order->delivery['postcode'], 
					  'delivery_state' => $order->delivery['state'], 
					  'delivery_country' => $order->delivery['country']['title'], 
					  'delivery_address_format_id' => $order->delivery['format_id'], 
					  'billing_name' => $order->billing['firstname'] . ' ' . $order->billing['lastname'], 
					  'billing_company' => $order->billing['company'],
					  'billing_street_address' => $order->billing['street_address'], 
					  'billing_suburb' => $order->billing['suburb'], 
					  'billing_city' => $order->billing['city'], 
					  'billing_postcode' => $order->billing['postcode'], 
					  'billing_state' => $order->billing['state'], 
					  'billing_country' => $order->billing['country']['title'], 
					  'billing_address_format_id' => $order->billing['format_id'], 
					  'payment_method' => $order->info['payment_method'], 
					  'cc_type' => $order->info['cc_type'], 
					  'cc_owner' => $order->info['cc_owner'], 
					  'cc_number' => $order->info['cc_number'], 
					  'cc_expires' => $order->info['cc_expires'], 
					  'date_purchased' => 'now()', 
					  'orders_status' => $order->info['order_status'], 
					  'currency' => $order->info['currency'], 
					  'currency_value' => $order->info['currency_value']);
 tep_db_perform(TABLE_ORDERS, $sql_data_array);
 $insert_id = tep_db_insert_id();
 for ($i=0, $n=sizeof($order_totals); $i<$n; $i++) {
$sql_data_array = array('orders_id' => $insert_id,
						'title' => $order_totals[$i]['title'],
						'text' => $order_totals[$i]['text'],
						'value' => $order_totals[$i]['value'], 
						'class' => $order_totals[$i]['code'], 
						'sort_order' => $order_totals[$i]['sort_order']);
tep_db_perform(TABLE_ORDERS_TOTAL, $sql_data_array);
 }

// Acrescenta customer_discount
$sql_data_array = array('orders_id' => $insert_id,
						'title' => 'Desconto',
						'text' => 'R$0.00',
						'value' => '0.0000',
						'class' => 'ot_customer_discount',
						'sort_order' => '2');
tep_db_perform(TABLE_ORDERS_TOTAL, $sql_data_array);

//


 $customer_notification = (SEND_EMAILS == 'true') ? '1' : '0';
 $sql_data_array = array('orders_id' => $insert_id, 
					  'orders_status_id' => $order->info['order_status'], 
					  'date_added' => 'now()', 
					  'customer_notified' => $customer_notification,
					  'comments' => $order->info['comments']);
 tep_db_perform(TABLE_ORDERS_STATUS_HISTORY, $sql_data_array);

// initialized for the email confirmation
 $products_ordered = '';
 $subtotal = 0;
 $total_tax = 0;

 for ($i=0, $n=sizeof($order->products); $i<$n; $i++) {
// Stock Update - Joao Correia
if (STOCK_LIMITED == 'true') {
  if (DOWNLOAD_ENABLED == 'true') {
	$stock_query_raw = "SELECT products_quantity, products_bundle, pad.products_attributes_filename 
						FROM " . TABLE_PRODUCTS . " p
						LEFT JOIN " . TABLE_PRODUCTS_ATTRIBUTES . " pa
						 ON p.products_id=pa.products_id
						LEFT JOIN " . TABLE_PRODUCTS_ATTRIBUTES_DOWNLOAD . " pad
						 ON pa.products_attributes_id=pad.products_attributes_id
						WHERE p.products_id = '" . tep_get_prid($order->products[$i]['id']) . "'";
// Will work with only one option for downloadable products
// otherwise, we have to build the query dynamically with a loop
	$products_attributes = $order->products[$i]['attributes'];
	if (is_array($products_attributes)) {
	  $stock_query_raw .= " AND pa.options_id = '" . $products_attributes[0]['option_id'] . "' AND pa.options_values_id = '" . $products_attributes[0]['value_id'] . "'";
	}
	$stock_query = tep_db_query($stock_query_raw);
  } else {
	$stock_query = tep_db_query("select products_quantity, products_bundle from " . TABLE_PRODUCTS . " where products_id = '" . tep_get_prid($order->products[$i]['id']) . "'");
  }

  if (tep_db_num_rows($stock_query) > 0) {
	  $stock_values = tep_db_fetch_array($stock_query);
	  if ($stock_values['products_bundle'] == 'yes') {
		// order item is a bundle and must be separated
		$report_text .= "Bundle found in order : " . tep_get_prid($order->products[$i]['id']) . "<br>\n";
		  $bundle_query = tep_db_query("select pb.subproduct_id, pb.subproduct_qty, p.products_model, p.products_quantity, p.products_bundle 
									from " . TABLE_PRODUCTS_BUNDLES . " pb 
									LEFT JOIN " . TABLE_PRODUCTS . " p 
									ON p.products_id=pb.subproduct_id 
									where pb.bundle_id = '" . tep_get_prid($order->products[$i]['id']) . "'");
		while ($bundle_data = tep_db_fetch_array($bundle_query)) {
			if ($bundle_data['products_bundle'] == "yes") {
				$report_text .= "<br>level 2 bundle found in order :  " . $bundle_data['products_model'] . "<br>";
				  $bundle_query_nested = tep_db_query("select pb.subproduct_id, pb.subproduct_qty, p.products_model, p.products_quantity, p.products_bundle 
												from " . TABLE_PRODUCTS_BUNDLES . " pb 
												LEFT JOIN " . TABLE_PRODUCTS . " p 
												ON p.products_id=pb.subproduct_id 
												where pb.bundle_id = '" . $bundle_data['subproduct_id'] . "'");
				while ($bundle_data_nested = tep_db_fetch_array($bundle_query_nested)) {
					$stock_left = $bundle_data_nested['products_quantity'] - $bundle_data_nested['subproduct_qty'] * $order->products[$i]['qty'];
					$report_text .= "updating level 2 item " . $bundle_data_nested['products_model'] . " : was " . $bundle_data_nested['products_quantity'] . " and number ordered is " . ($bundle_data_nested['subproduct_qty'] * $order->products[$i]['qty']) . " <br>\n";
					tep_db_query("update " . TABLE_PRODUCTS . " set products_quantity = '" . $stock_left . "' where products_id = '" . $bundle_data_nested['subproduct_id'] . "'");
				}
			} else {
				$stock_left = $bundle_data['products_quantity'] - $bundle_data['subproduct_qty'] * $order->products[$i]['qty'];
				$report_text .= "updating level 1 item " . $bundle_data['products_model'] . " : was " . $bundle_data['products_quantity'] . " and number ordered is " . ($bundle_data['subproduct_qty'] * $order->products[$i]['qty']) . " <br>\n";
				tep_db_query("update " . TABLE_PRODUCTS . " set products_quantity = '" . $stock_left . "' where products_id = '" . $bundle_data['subproduct_id'] . "'");
			}
		}

	  } else {
// order item is normal and should be treated as such
		$report_text .= "Normal product found in order : " . tep_get_prid($order->products[$i]['id']) . "\n";
// do not decrement quantities if products_attributes_filename exists
		if ((DOWNLOAD_ENABLED != 'true') || (!$stock_values['products_attributes_filename'])) {
		  $stock_left = $stock_values['products_quantity'] - $order->products[$i]['qty'];
		} else {
		  $stock_left = $stock_values['products_quantity'];
		}
		tep_db_query("update " . TABLE_PRODUCTS . " set products_quantity = '" . $stock_left . "' where products_id = '" . tep_get_prid($order->products[$i]['id']) . "'");
// Desbilitado AZZ - Fazia com que os produtos ficassem indisponiveis quando zeravam no estoque e o flag "Permitir ir ao caixa" fosse 0
//			if ( ($stock_left < 1) && (STOCK_ALLOW_CHECKOUT == 'false') ) {
//			  tep_db_query("update " . TABLE_PRODUCTS . " set products_status = '0' where products_id = '" . tep_get_prid($order->products[$i]['id']) . "'");
//			}
	  }
  }
}




// Update products_ordered (for bestsellers list)
tep_db_query("update " . TABLE_PRODUCTS . " set products_ordered = products_ordered + " . sprintf('%d', $order->products[$i]['qty']) . " where products_id = '" . tep_get_prid($order->products[$i]['id']) . "'");

$sql_data_array = array('orders_id' => $insert_id, 
						'products_id' => tep_get_prid($order->products[$i]['id']), 
						'products_model' => $order->products[$i]['model'], 
						'products_name' => $order->products[$i]['name'], 
						'products_price' => $order->products[$i]['price'], 
						'final_price' => $order->products[$i]['final_price'], 
						'products_tax' => $order->products[$i]['tax'], 
						'products_quantity' => $order->products[$i]['qty']);
tep_db_perform(TABLE_ORDERS_PRODUCTS, $sql_data_array);
$order_products_id = tep_db_insert_id();

//------insert customer choosen option to order--------
$attributes_exist = '0';
$products_ordered_attributes = '';
if (isset($order->products[$i]['attributes'])) {
  $attributes_exist = '1';
  for ($j=0, $n2=sizeof($order->products[$i]['attributes']); $j<$n2; $j++) {
	if (DOWNLOAD_ENABLED == 'true') {
	  $attributes_query = "select popt.products_options_name, poval.products_options_values_name, pa.options_values_price, pa.price_prefix, pad.products_attributes_maxdays, pad.products_attributes_maxcount , pad.products_attributes_filename 
						   from " . TABLE_PRODUCTS_OPTIONS . " popt, " . TABLE_PRODUCTS_OPTIONS_VALUES . " poval, " . TABLE_PRODUCTS_ATTRIBUTES . " pa 
						   left join " . TABLE_PRODUCTS_ATTRIBUTES_DOWNLOAD . " pad
							on pa.products_attributes_id=pad.products_attributes_id
						   where pa.products_id = '" . $order->products[$i]['id'] . "' 
							and pa.options_id = '" . $order->products[$i]['attributes'][$j]['option_id'] . "' 
							and pa.options_id = popt.products_options_id 
							and pa.options_values_id = '" . $order->products[$i]['attributes'][$j]['value_id'] . "' 
							and pa.options_values_id = poval.products_options_values_id 
							and popt.language_id = '" . $languages_id . "' 
							and poval.language_id = '" . $languages_id . "'";
	  $attributes = tep_db_query($attributes_query);
	} else {
	  $attributes = tep_db_query("select popt.products_options_name, poval.products_options_values_name, pa.options_values_price, pa.price_prefix from " . TABLE_PRODUCTS_OPTIONS . " popt, " . TABLE_PRODUCTS_OPTIONS_VALUES . " poval, " . TABLE_PRODUCTS_ATTRIBUTES . " pa where pa.products_id = '" . $order->products[$i]['id'] . "' and pa.options_id = '" . $order->products[$i]['attributes'][$j]['option_id'] . "' and pa.options_id = popt.products_options_id and pa.options_values_id = '" . $order->products[$i]['attributes'][$j]['value_id'] . "' and pa.options_values_id = poval.products_options_values_id and popt.language_id = '" . $languages_id . "' and poval.language_id = '" . $languages_id . "'");
	}
	$attributes_values = tep_db_fetch_array($attributes);

	$sql_data_array = array('orders_id' => $insert_id, 
							'orders_products_id' => $order_products_id, 
							'products_options' => $attributes_values['products_options_name'],
							'products_options_values' => $attributes_values['products_options_values_name'], 
							'options_values_price' => $attributes_values['options_values_price'], 
							'price_prefix' => $attributes_values['price_prefix']);
	tep_db_perform(TABLE_ORDERS_PRODUCTS_ATTRIBUTES, $sql_data_array);

	if ((DOWNLOAD_ENABLED == 'true') && isset($attributes_values['products_attributes_filename']) && tep_not_null($attributes_values['products_attributes_filename'])) {
	  $sql_data_array = array('orders_id' => $insert_id, 
							  'orders_products_id' => $order_products_id, 
							  'orders_products_filename' => $attributes_values['products_attributes_filename'], 
							  'download_maxdays' => $attributes_values['products_attributes_maxdays'], 
							  'download_count' => $attributes_values['products_attributes_maxcount']);
	  tep_db_perform(TABLE_ORDERS_PRODUCTS_DOWNLOAD, $sql_data_array);
	}
	$products_ordered_attributes .= "\n\t" . $attributes_values['products_options_name'] . ' ' . $attributes_values['products_options_values_name'];
  }
}
//------insert customer choosen option eof ----
$total_weight += ($order->products[$i]['qty'] * $order->products[$i]['weight']);
$total_tax += tep_calculate_tax($total_products_price, $products_tax) * $order->products[$i]['qty'];
$total_cost += $total_products_price;

//TotalB2B start
$products_ordered .= $order->products[$i]['qty'] . ' x ' . $order->products[$i]['name'] . ' (' . $order->products[$i]['model'] . ') = ' . $currencies->display_price_nodiscount($order->products[$i]['final_price'], $order->products[$i]['tax'], $order->products[$i]['qty']) . $products_ordered_attributes . "\n";
//TotalB2B end

 }



// account balance mod
$this_order_total_query = tep_db_query("SELECT value FROM " . TABLE_ORDERS_TOTAL . " WHERE orders_id = '" . (int)$insert_id . "' AND class = 'ot_total'");
$this_order_total = tep_db_fetch_array($this_order_total_query);
$order_total_variable = tep_round($this_order_total['value'],2);
if ($begin_account_balance > 0) {
if ($begin_account_balance > $order_total_variable) { $ending_account_balance_unrounded = (-($order_total_variable));
}
if ($begin_account_balance < $order_total_variable) {
$ending_account_balance_unrounded = "0.00";
}
$ending_account_balance = tep_round($ending_account_balance_unrounded,2);

$ending_account_balance_query = tep_db_query("UPDATE " . TABLE_CUSTOMERS . " SET customers_account_balance = '" . $ending_account_balance . "' WHERE customers_id = '" . (int)$customer_id . "'");
}
if ($begin_account_balance < 0) {
$ending_account_balance_unrounded = "0.00";
$ending_account_balance = tep_round($ending_account_balance_unrounded,2);

$ending_account_balance_query = tep_db_query("UPDATE " . TABLE_CUSTOMERS . " SET customers_account_balance = '" . $ending_account_balance . "' WHERE customers_id = '" . (int)$customer_id . "'");
}
// end mod





// lets start with the email confirmation
  //// PAYPAL ALTERACAO 

$payment_class = $$payment;
$metodo_pg = $payment_class->code; 
 if ($metodo_pg == 'paypal'){

$query_dolar = tep_db_query("select configuration_value from " . TABLE_CONFIGURATION . " where configuration_key = 'MODULE_PAYMENT_PAYPAL_DOLAR'");
$result_dolar= tep_db_fetch_array($query_dolar);
$dolar = $result_dolar['configuration_value'];
$subtotal_dolar = $order_total_variable / $dolar; 
$total_dolar = round($subtotal_dolar, 2); 
$email_dolar = str_replace(".", "%2e", $total_dolar); 

///////HTML do PAYPAL
$email_order .= '<html><head><meta content="text/html; charset=ISO-8859-1" http-equiv="content-type"><title>paypal</title></head><body>
<div style="text-align: center;"><big>Caso tenha ocorrido algum erro pagando suas compras pelo site, voce pode paga-las clicando no link abaixo.<br>
<a style="font-weight: bold;" href="https://www.paypal.com/cgi-bin/webscr?cmd=_xclick&business=vendas%40asaseletricas%2ecom%2ebr&item_name=Produtos%20Asas%20Eletricas&item_number=' . $insert_id . '&amount=' . $email_dolar . '&page_style=Asas&no_shipping=1&no_note=1&currency_code=USD&bn=PP%2dBuyNowBF&charset=UTF%2d8">CLIQUE AQUI PARA PAGAR COM SEU CART?O!!</a><div style="text-align: center;"><form action="https://www.paypal.com/cgi-bin/webscr" method="post"><input name="cmd" value="_xclick" type="hidden"><input name="business" value="[email protected]" type="hidden"><input name="item_name" value="Produtos Asas Eletricas" type="hidden"><input name="item_number" value="' . $insert_id .'" type="hidden"><input name="amount" value="' . $total_dolar . '" type="hidden"><input name="no_shipping" value="1" type="hidden"><input name="return" value="http://www.asaseletricas.com.br/loja/checkout_success.php" type="hidden"><input name="cancel_return" value="http://www.asaseletricas.com.br/loja/shopping_cart.php" type="hidden"><input name="no_note" value="1" type="hidden"><input name="currency_code" value="USD" type="hidden"><input name="bn" value="PP-BuyNowBF" type="hidden"><input src="https://www.paypal.com/en_US/i/btn/x-click-butcc.gif" name="submit" alt="Make payments with PayPal - its fast, free and secure!" border="0" type="image"><br></form>
</div><big><span style="font-weight: bold;">Informa??es sobre o PAYPAL:</span></big><br>
<ul style="text-align: left;"><li style="text-align: left;">Este ? o m?todo mais r?pido e pr?tico de pagamento de suas compras no Asas El?tricas.</li>
<li style="text-align: left;">Para pagar suas compras no Asas El?tricas com este m?todo voc? precisa ter um <span style="font-weight: bold;">CART?O de CR?DITO INTERNACIONAL </span>do tipo <span style="font-weight: bold;">MasterCard, VISA</span> ou<span style="font-weight: bold;"><span style="font-weight: bold;"> <span style="font-weight: bold;">AMEX</span></span></span>, ou uma conta <span style="font-weight: bold;">PAYPAL</span>. </li>
<li style="text-align: left;">Como utilizamos uma operadora internacional os valores a serem pagos ser?o convertidos para o <span style="font-weight: bold;">Dolar Comercial</span>, cotado a <big style="font-weight: bold;">R$ ' . $dolar . '</big>.</li>
<li style="text-align: left;">O total de sua compra em <span style="font-weight: bold;"><big>Dolar</big> </span>ser? de <big><span style="font-weight: bold;">US$ ' . $total_dolar . ' </span></big> .</li>
<li style="text-align: left;">Se voc? n?o tem uma conta no <span style="font-weight: bold;">PAYPAL</span> e quer comprar diretamente usando apenas seu cart?o, seu limite de compra ? de apenas US$ 500,00. Caso j? tenha uma conta no <span style="font-weight: bold;">PAYPAL </span> seu limite ser? de US$ 750,00, ou mais se voc? j? comprou antes pelo sistema e expandiu seu limite.</li>
<li style="text-align: left;">A p?gina da operadora <span style="font-weight: bold;">PAYPAL</span> esta em Ingl?s.</li>
<li style="text-align: left;">Qualquer d?vida ? s? responder a este e-mail.</li>
</ul><hr style="width: 100%; height: 2px;"><big><span style="font-weight: bold;">Para efetuar o pagamento:</span></big><br>
<ul style="text-align: left;"><li style="text-align: left;">Clique no bot?o acima, voc? ser? direcionado para o site de pagamentos <span style="font-weight: bold;">PAYPAL</span>.</li>
<li style="text-align: left;">Caso voc? j? tenha uma conta <span style="font-weight: bold;">PAYPAL</span>, ? s? preencher seu e-mail e senha do <span style="font-weight: bold;">PAYPAL.</span></li>
<li style="text-align: left;">Caso voc? n?o tenha uma conta no <span style="font-weight: bold;">PAYPAL</span> e queira pagar com seu <span style="font-weight: bold;">CART?O de CR?DITO</span> diretamente, clique na op??o: "<span style="font-style: italic; text-decoration: underline;">If you do not currently have a PayPal account click here.</span>", e preencha todos os dados corretamente.</li>
<li style="text-align: left;">Ap?s confirmado o pagamento voc? receber? um e-mail confirmando a opera??o.</li>
<li style="text-align: left;">O Asas El?tricas receber? um e-mail da operadora confirmando seu pagamento e imediatamente procedermos com o processamento do seu pedido.</li>
<li style="text-align: left;">Caso tenha acesso ao seu extrato do cart?o online, a compra s? aparecer? no extrato ap?s 3 ou 4 dias ?teis. Isto ? normal pois a operadora ? internacional.</li>
</ul><hr style="width: 100%; height: 2px; margin-left: 0px; margin-right: auto;">
</body></html>';
} 
///////FIM HTML do PAYPAL
///// FIM PAYPAL ALTERACAO
$email_order .= STORE_NAME . "\n" . 
			 EMAIL_SEPARATOR . "\n" . 
			 EMAIL_TEXT_ORDER_NUMBER . ' ' . $insert_id . "\n" .
			 EMAIL_TEXT_INVOICE_URL . ' ' . tep_href_link(FILENAME_ACCOUNT_HISTORY_INFO, 'order_id=' . $insert_id, 'SSL', false) . "\n" .
			 EMAIL_TEXT_DATE_ORDERED . ' ' . strftime(DATE_FORMAT_LONG) . "\n\n";
 if ($order->info['comments']) {
$email_order .= tep_db_output($order->info['comments']) . "\n\n";
 }
 $email_order .= EMAIL_TEXT_PRODUCTS . "\n" . 
			  EMAIL_SEPARATOR . "\n" . 
			  $products_ordered . 
			  EMAIL_SEPARATOR . "\n";

 for ($i=0, $n=sizeof($order_totals); $i<$n; $i++) {
$email_order .= strip_tags($order_totals[$i]['title']) . ' ' . strip_tags($order_totals[$i]['text']) . "\n";
 }

 if ($order->content_type != 'virtual') {
$email_order .= "\n" . EMAIL_TEXT_DELIVERY_ADDRESS . "\n" . 
				EMAIL_SEPARATOR . "\n" .
				tep_address_label($customer_id, $sendto, 0, '', "\n") . "\n";
 }

 $email_order .= "\n" . EMAIL_TEXT_BILLING_ADDRESS . "\n" .
			  EMAIL_SEPARATOR . "\n" .
			  tep_address_label($customer_id, $billto, 0, '', "\n") . "\n\n";
 if (is_object($$payment)) {
$email_order .= EMAIL_TEXT_PAYMENT_METHOD . "\n" . 
				EMAIL_SEPARATOR . "\n";
$payment_class = $$payment;
$email_order .= $payment_class->title . "\n\n";

  if ($payment_class->email_footer) { 
  $email_order .= $payment_class->email_footer . "\n\n";
}
 }
 tep_mail($order->customer['firstname'] . ' ' . $order->customer['lastname'], $order->customer['email_address'], EMAIL_TEXT_SUBJECT, $email_order, STORE_OWNER, STORE_OWNER_EMAIL_ADDRESS);

// send emails to other people
 if (SEND_EXTRA_ORDER_EMAILS_TO != '') {
tep_mail('', SEND_EXTRA_ORDER_EMAILS_TO, EMAIL_TEXT_SUBJECT, $email_order, STORE_OWNER, STORE_OWNER_EMAIL_ADDRESS);
 }



// load the after_process function from the payment modules
 $payment_modules->after_process();

 $cart->reset(true);

// unregister session variables used during checkout
 tep_session_unregister('sendto');
 tep_session_unregister('billto');
 tep_session_unregister('shipping');
 tep_session_unregister('payment');
 tep_session_unregister('comments');

 tep_redirect(tep_href_link(FILENAME_CHECKOUT_SUCCESS, '', 'SSL'));

 require(DIR_WS_INCLUDES . 'application_bottom.php');
?>

Link to comment
Share on other sites

Can I use this code from checkout_payment in the checkout_process?

 

// Stock Check
 if ( (STOCK_CHECK == 'true') && (STOCK_ALLOW_CHECKOUT != 'true') ) {
$products = $cart->get_products();
for ($i=0, $n=sizeof($products); $i<$n; $i++) {
  if (tep_check_stock($products[$i]['id'], $products[$i]['quantity'])) {
	tep_redirect(tep_href_link(FILENAME_SHOPPING_CART));
	break;
  }
}
 }

 

And if possible to use, where tu put it?

Link to comment
Share on other sites

ok this is a serious hack so I want you to take backups and only try it in a development area ...

 

well your bundle products mod doesn't really help :-)

 

ok what I would do to make it quick is copy the long code bit that is coming below right before this

// load the before_process function from the payment modules
 $payment_modules->before_process();

 

 

this code will only check if quantity goes below 0, if yes redirects to cart

I commented out all updates and report parts (I hope)

 

  for ($i=0, $n=sizeof($order->products); $i<$n; $i++) {
// Stock Update - Joao Correia
if (STOCK_LIMITED == 'true') {
  if (DOWNLOAD_ENABLED == 'true') {
	$stock_query_raw = "SELECT products_quantity, products_bundle, pad.products_attributes_filename 
						FROM " . TABLE_PRODUCTS . " p
						LEFT JOIN " . TABLE_PRODUCTS_ATTRIBUTES . " pa
						 ON p.products_id=pa.products_id
						LEFT JOIN " . TABLE_PRODUCTS_ATTRIBUTES_DOWNLOAD . " pad
						 ON pa.products_attributes_id=pad.products_attributes_id
						WHERE p.products_id = '" . tep_get_prid($order->products[$i]['id']) . "'";
// Will work with only one option for downloadable products
// otherwise, we have to build the query dynamically with a loop
	$products_attributes = $order->products[$i]['attributes'];
	if (is_array($products_attributes)) {
	  $stock_query_raw .= " AND pa.options_id = '" . $products_attributes[0]['option_id'] . "' AND pa.options_values_id = '" . $products_attributes[0]['value_id'] . "'";
	}
	$stock_query = tep_db_query($stock_query_raw);
  } else {
	$stock_query = tep_db_query("select products_quantity, products_bundle from " . TABLE_PRODUCTS . " where products_id = '" . tep_get_prid($order->products[$i]['id']) . "'");
  }

  if (tep_db_num_rows($stock_query) > 0) {
	  $stock_values = tep_db_fetch_array($stock_query);
	  if ($stock_values['products_bundle'] == 'yes') {
		// order item is a bundle and must be separated
//			$report_text .= "Bundle found in order : " . tep_get_prid($order->products[$i]['id']) . "<br>\n";
		  $bundle_query = tep_db_query("select pb.subproduct_id, pb.subproduct_qty, p.products_model, p.products_quantity, p.products_bundle 
									from " . TABLE_PRODUCTS_BUNDLES . " pb 
									LEFT JOIN " . TABLE_PRODUCTS . " p 
									ON p.products_id=pb.subproduct_id 
									where pb.bundle_id = '" . tep_get_prid($order->products[$i]['id']) . "'");
		while ($bundle_data = tep_db_fetch_array($bundle_query)) {
			if ($bundle_data['products_bundle'] == "yes") {
//					$report_text .= "<br>level 2 bundle found in order :  " . $bundle_data['products_model'] . "<br>";
				  $bundle_query_nested = tep_db_query("select pb.subproduct_id, pb.subproduct_qty, p.products_model, p.products_quantity, p.products_bundle 
												from " . TABLE_PRODUCTS_BUNDLES . " pb 
												LEFT JOIN " . TABLE_PRODUCTS . " p 
												ON p.products_id=pb.subproduct_id 
												where pb.bundle_id = '" . $bundle_data['subproduct_id'] . "'");
				while ($bundle_data_nested = tep_db_fetch_array($bundle_query_nested)) {
					$stock_left = $bundle_data_nested['products_quantity'] - $bundle_data_nested['subproduct_qty'] * $order->products[$i]['qty'];
		// if if quantity goes below 0, redirect them to the shopping cart page
		  if ($stock_left < 0) {
			tep_redirect(tep_href_link(FILENAME_SHOPPING_CART));
		  }

//						$report_text .= "updating level 2 item " . $bundle_data_nested['products_model'] . " : was " . $bundle_data_nested['products_quantity'] . " and number ordered is " . ($bundle_data_nested['subproduct_qty'] * $order->products[$i]['qty']) . " <br>\n";
//						tep_db_query("update " . TABLE_PRODUCTS . " set products_quantity = '" . $stock_left . "' where products_id = '" . $bundle_data_nested['subproduct_id'] . "'");
				}
			} else {
				$stock_left = $bundle_data['products_quantity'] - $bundle_data['subproduct_qty'] * $order->products[$i]['qty'];
				// if if quantity goes below 0, redirect them to the shopping cart page
		  if ($stock_left < 0) {
			tep_redirect(tep_href_link(FILENAME_SHOPPING_CART));
		  }

//					$report_text .= "updating level 1 item " . $bundle_data['products_model'] . " : was " . $bundle_data['products_quantity'] . " and number ordered is " . ($bundle_data['subproduct_qty'] * $order->products[$i]['qty']) . " <br>\n";
//					tep_db_query("update " . TABLE_PRODUCTS . " set products_quantity = '" . $stock_left . "' where products_id = '" . $bundle_data['subproduct_id'] . "'");
			}
		}

	  } else {
// order item is normal and should be treated as such
//			$report_text .= "Normal product found in order : " . tep_get_prid($order->products[$i]['id']) . "\n";
// do not decrement quantities if products_attributes_filename exists
		if ((DOWNLOAD_ENABLED != 'true') || (!$stock_values['products_attributes_filename'])) {
		  $stock_left = $stock_values['products_quantity'] - $order->products[$i]['qty'];
		  // if if quantity goes below 0, redirect them to the shopping cart page
		if ($stock_left < 0) {
		  tep_redirect(tep_href_link(FILENAME_SHOPPING_CART));
		}

		} else {
		  $stock_left = $stock_values['products_quantity'];
		  // if if quantity goes below 0, redirect them to the shopping cart page
		if ($stock_left < 0) {
		  tep_redirect(tep_href_link(FILENAME_SHOPPING_CART));
		}

		}
//			tep_db_query("update " . TABLE_PRODUCTS . " set products_quantity = '" . $stock_left . "' where products_id = '" . tep_get_prid($order->products[$i]['id']) . "'");
// Desbilitado AZZ - Fazia com que os produtos ficassem indisponiveis quando zeravam no estoque e o flag "Permitir ir ao caixa" fosse 0
//			if ( ($stock_left < 1) && (STOCK_ALLOW_CHECKOUT == 'false') ) {
//			  tep_db_query("update " . TABLE_PRODUCTS . " set products_status = '0' where products_id = '" . tep_get_prid($order->products[$i]['id']) . "'");
//			}
	  }
  }
}
}

:-)

Monika

 

addicted to writing code ... can't get enough of databases either, LOL!

 

my toolbox: Textpad - Compare and Merge - phpMyAdmin - WS_FTP - Photoshop - How to search the forum

 

Interactive Media Award July 2007 ~ category E-Commerce

my advice on the forum is for free, PMs where you send me work are considered consultation which I charge for ...

Link to comment
Share on other sites

Can I use this code from checkout_payment in the checkout_process?

 

// Stock Check
 if ( (STOCK_CHECK == 'true') && (STOCK_ALLOW_CHECKOUT != 'true') ) {
$products = $cart->get_products();
for ($i=0, $n=sizeof($products); $i<$n; $i++) {
  if (tep_check_stock($products[$i]['id'], $products[$i]['quantity'])) {
	tep_redirect(tep_href_link(FILENAME_SHOPPING_CART));
	break;
  }
}
 }

 

And if possible to use, where tu put it?

I do not think so due to your bundle products ... but not sure, not so familiar with that contrib!

:-)

Monika

 

addicted to writing code ... can't get enough of databases either, LOL!

 

my toolbox: Textpad - Compare and Merge - phpMyAdmin - WS_FTP - Photoshop - How to search the forum

 

Interactive Media Award July 2007 ~ category E-Commerce

my advice on the forum is for free, PMs where you send me work are considered consultation which I charge for ...

Link to comment
Share on other sites

I do not think so due to your bundle products ... but not sure, not so familiar with that contrib!

 

Monika,

 

I had tested in my development server, and it worked just fine!!

 

I had put it here:

 

// load the before_process function from the payment modules
 $payment_modules->before_process();

// account balance mod
$begin_account_balance_query = tep_db_query("select customers_account_balance from " . TABLE_CUSTOMERS . " where customers_id = '" . (int)$customer_id . "'");
$begin_account_balance_result = tep_db_fetch_array($begin_account_balance_query);
$begin_account_balance = tep_round($begin_account_balance_result['customers_account_balance'],2);
//end mod



// Stock Check - ADICIONADO AZZ
 if ( (STOCK_CHECK == 'true') && (STOCK_ALLOW_CHECKOUT != 'true') ) {
$products = $cart->get_products();
for ($i=0, $n=sizeof($products); $i<$n; $i++) {
  if (tep_check_stock($products[$i]['id'], $products[$i]['quantity'])) {
	tep_redirect(tep_href_link(FILENAME_SHOPPING_CART));
	break;
  }
}
 }
//



 require(DIR_WS_CLASSES . 'order_total.php');
 $order_total_modules = new order_total;

 $order_totals = $order_total_modules->process();

 

I have tested some scenarios and in all it worked fine. Do you see any problem in that solution?

 

I am not using the BUNDLE anymore, but I left the code in the files. Maybe some day I get the courage for removing the code.

Link to comment
Share on other sites

Monika,

 

I had tested in my development server, and it worked just fine!!

 

I had put it here:

 

// load the before_process function from the payment modules
 $payment_modules->before_process();

// account balance mod
$begin_account_balance_query = tep_db_query("select customers_account_balance from " . TABLE_CUSTOMERS . " where customers_id = '" . (int)$customer_id . "'");
$begin_account_balance_result = tep_db_fetch_array($begin_account_balance_query);
$begin_account_balance = tep_round($begin_account_balance_result['customers_account_balance'],2);
//end mod



// Stock Check - ADICIONADO AZZ
 if ( (STOCK_CHECK == 'true') && (STOCK_ALLOW_CHECKOUT != 'true') ) {
$products = $cart->get_products();
for ($i=0, $n=sizeof($products); $i<$n; $i++) {
  if (tep_check_stock($products[$i]['id'], $products[$i]['quantity'])) {
	tep_redirect(tep_href_link(FILENAME_SHOPPING_CART));
	break;
  }
}
 }
//



 require(DIR_WS_CLASSES . 'order_total.php');
 $order_total_modules = new order_total;

 $order_totals = $order_total_modules->process();

 

I have tested some scenarios and in all it worked fine. Do you see any problem in that solution?

 

I am not using the BUNDLE anymore, but I left the code in the files. Maybe some day I get the courage for removing the code.

 

without the bundle I definitely do not see an issue. I wasn't sure how well the contrib had adjusted that function (sometimes I find bugs in such spots), but if you're not using it more power to you!

 

You should move it up though because there is no use to do all those processes if you are redirecting anyway.

:-)

Monika

 

addicted to writing code ... can't get enough of databases either, LOL!

 

my toolbox: Textpad - Compare and Merge - phpMyAdmin - WS_FTP - Photoshop - How to search the forum

 

Interactive Media Award July 2007 ~ category E-Commerce

my advice on the forum is for free, PMs where you send me work are considered consultation which I charge for ...

Link to comment
Share on other sites

  • 5 years later...

New to Oscommerce. Running 2.3 with a couple of mods. Just noticed in the checkout process it gives me the following message on items I added yesterday:

Products marked with *** dont exist in desired quantity in our stock.

You can buy them anyway and check the quantity we have in stock for immediate deliver in the checkout process.

Did not make any changes any of the PHP files just used the admin panel to add new products and images.

Any help on this would be greatly appreciated!

Thanks,

J~

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...