Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Improved performance with precount and foreach instead of while loops

  • Loading branch information...
commit bcba8f0177d8660f1a6410d26709e1d1929198f5 1 parent 133697e
@acidvertigo acidvertigo authored
View
6 catalog/includes/modules/shipping/item.php
@@ -98,12 +98,12 @@ function getNumberOfItems() {
if ($order->content_type == 'mixed') {
$number_of_items = 0;
- for ($i=0, $n=sizeof($order->products); $i<$n; $i++) {
+ $n=sizeof($order->products);
+ for ($i=0; $i<$n; $i++) {
$number_of_items += $order->products[$i]['qty'];
if (isset($order->products[$i]['attributes'])) {
- reset($order->products[$i]['attributes']);
- while (list($option, $value) = each($order->products[$i]['attributes'])) {
+ foreach ($order->products[$i]['attributes'] as $option => $value) {
$virtual_check_query = tep_db_query("select count(*) as total from " . TABLE_PRODUCTS_ATTRIBUTES . " pa, " . TABLE_PRODUCTS_ATTRIBUTES_DOWNLOAD . " pad where pa.products_id = '" . (int)$order->products[$i]['id'] . "' and pa.options_values_id = '" . (int)$value['value_id'] . "' and pa.products_attributes_id = pad.products_attributes_id");
$virtual_check = tep_db_fetch_array($virtual_check_query);
View
10 catalog/includes/modules/shipping/table.php
@@ -55,8 +55,8 @@ function quote($method = '') {
}
$table_cost = preg_split("/[:,]/" , MODULE_SHIPPING_TABLE_COST);
- $size = sizeof($table_cost);
- for ($i=0, $n=$size; $i<$n; $i+=2) {
+ $n = sizeof($table_cost);
+ for ($i=0; $i<$n; $i+=2) {
if ($order_total <= $table_cost[$i]) {
$shipping = $table_cost[$i+1];
break;
@@ -116,12 +116,12 @@ function getShippableTotal() {
if ($order->content_type == 'mixed') {
$order_total = 0;
- for ($i=0, $n=sizeof($order->products); $i<$n; $i++) {
+ $n=sizeof($order->products);
+ for ($i=0; $i<$n; $i++) {
$order_total += $currencies->calculate_price($order->products[$i]['final_price'], $order->products[$i]['tax'], $order->products[$i]['qty']);
if (isset($order->products[$i]['attributes'])) {
- reset($order->products[$i]['attributes']);
- while (list($option, $value) = each($order->products[$i]['attributes'])) {
+ foreach ($order->products[$i]['attributes'] as $option => $value) {
$virtual_check_query = tep_db_query("select count(*) as total from " . TABLE_PRODUCTS_ATTRIBUTES . " pa, " . TABLE_PRODUCTS_ATTRIBUTES_DOWNLOAD . " pad where pa.products_id = '" . (int)$order->products[$i]['id'] . "' and pa.options_values_id = '" . (int)$value['value_id'] . "' and pa.products_attributes_id = pad.products_attributes_id");
$virtual_check = tep_db_fetch_array($virtual_check_query);
Please sign in to comment.
Something went wrong with that request. Please try again.