From 2045401f9e25ce19474fec0fb5dc8fcd652fd062 Mon Sep 17 00:00:00 2001 From: vChabot Date: Tue, 27 Sep 2011 15:08:24 +0000 Subject: [PATCH] // cleaning code (norm / perf) git-svn-id: http://dev.prestashop.com/svn/v1/branches/1.5.x@8810 b9a71923-0436-4b27-9f14-aed3839534dd --- admin-dev/tabs/AdminAttributes.php | 2 +- admin-dev/tabs/AdminImport.php | 8 +++---- admin-dev/tabs/AdminProducts.php | 6 +++--- classes/Attribute.php | 16 +++++++------- classes/AttributeGroup.php | 18 ++++++++-------- classes/Feature.php | 18 ++++++++-------- controllers/front/CartController.php | 4 ++-- controllers/front/ParentOrderController.php | 7 +++--- js/attributesBack.js | 2 +- themes/prestashop/product.tpl | 24 ++++++++++----------- 10 files changed, 52 insertions(+), 53 deletions(-) diff --git a/admin-dev/tabs/AdminAttributes.php b/admin-dev/tabs/AdminAttributes.php index 3e8e20f42..140b2bf0f 100644 --- a/admin-dev/tabs/AdminAttributes.php +++ b/admin-dev/tabs/AdminAttributes.php @@ -177,7 +177,7 @@ class AdminAttributes extends AdminTab } // clean \n\r characters foreach ($_POST as $key => $value) - if (preg_match('/^name_/Ui', $key)) + if (stripos($key, 'name_') !== false) $_POST[$key] = str_replace ('\n', '', str_replace('\r', '', $value)); parent::postProcess(); } diff --git a/admin-dev/tabs/AdminImport.php b/admin-dev/tabs/AdminImport.php index f311ad6b6..46afaecef 100644 --- a/admin-dev/tabs/AdminImport.php +++ b/admin-dev/tabs/AdminImport.php @@ -179,7 +179,7 @@ class AdminImport extends AdminTab 'label' => $this->l('Delete existing images (0 = no, 1 = yes)'), 'help' => $this->l('If you do not specify this column and you specify the column images, all images of the product will be replaced by those specified in the import file') ), - 'features' => array('label' => $this->l('Feature(Name:Position)'), + 'features' => array('label' => $this->l('Feature(Name:Value:Position)'), 'help' => $this->l('Position of the feature.')), 'online_only' => array('label' => $this->l('Only available online')), 'condition' => array('label' => $this->l('Condition')), @@ -764,7 +764,7 @@ class AdminImport extends AdminTab $product->date_add = pSQL($datas['date_add']); $res = $product->update(); } // Else If id product AND id product already in base, trying to update - else if ($product->id AND Product::existsInDatabase((int)($product->id), 'product')) + elseif ($product->id AND Product::existsInDatabase((int)($product->id), 'product')) { $datas = Db::getInstance()->getRow('SELECT `date_add` FROM `'._DB_PREFIX_.'product` WHERE `id_product` = '.(int)($product->id)); $product->date_add = pSQL($datas['date_add']); @@ -962,7 +962,7 @@ class AdminImport extends AdminTab $this->_errors[] = ($fieldError !== true ? $fieldError : '').($langFieldError !== true ? $langFieldError : '').mysql_error(); } } - else if (isset($info['image_position']) && $info['image_position']) + elseif (isset($info['image_position']) && $info['image_position']) { $images = $product->getImages($defaultLanguage); @@ -1837,4 +1837,4 @@ class AdminImport extends AdminTab { $this->_warnings[] = $product_name.(isset($product_id) ? ' (ID '.$product_id.')' : '').' '.Tools::displayError($message); } -} +} \ No newline at end of file diff --git a/admin-dev/tabs/AdminProducts.php b/admin-dev/tabs/AdminProducts.php index 693d68f3d..93917b6df 100644 --- a/admin-dev/tabs/AdminProducts.php +++ b/admin-dev/tabs/AdminProducts.php @@ -3463,7 +3463,7 @@ class AdminProducts extends AdminTab '.$this->l('Available date:').' - +

'.$this->l('The available date when this product is out of stock').'

'; @@ -3569,7 +3569,7 @@ class AdminProducts extends AdminTab $list = rtrim($list, ', '); $jsList = rtrim($jsList, ', '); $attrImage = $product_attribute['id_image'] ? new Image($product_attribute['id_image']) : false; - $available_date = ($product_attribute['available_date'] != 0) ? date('Y-m-j', strtotime($product_attribute['available_date'])) : '0000-00-00'; + $available_date = ($product_attribute['available_date'] != 0) ? date('Y-m-d', strtotime($product_attribute['available_date'])) : '0000-00-00'; echo ' '.stripslashes($list).' @@ -3583,7 +3583,7 @@ class AdminProducts extends AdminTab '.$this->l('Modify this combination').'  + \''.$product_attribute['quantity'].'\', \''.($attrImage ? $attrImage->id : 0).'\', Array('.$jsList.'), \''.$id_product_attribute.'\', \''.$product_attribute['default_on'].'\', \''.$product_attribute['ecotax'].'\', \''.$product_attribute['location'].'\', \''.$product_attribute['upc'].'\', \''.$product_attribute['minimal_quantity'].'\', \''.pSQL($available_date).'\'); calcImpactPriceTI();" />  '.(!$product_attribute['default_on'] ? ' '.$this->l('Make this the default combination').'' : '').' diff --git a/classes/Attribute.php b/classes/Attribute.php index f81fb3968..6d06d1118 100644 --- a/classes/Attribute.php +++ b/classes/Attribute.php @@ -306,14 +306,14 @@ class AttributeCore extends ObjectModel $sql .= ' ORDER BY `position`'; $result = Db::getInstance()->ExecuteS($sql); - $sizeof = sizeof($result); - for ($i = 0; $i < $sizeof; $i++) + $i = 0; + foreach ($result as $value) $return = Db::getInstance()->Execute(' UPDATE `'._DB_PREFIX_.'attribute` - SET `position` = '.(int)$i.' + SET `position` = '.(int)$i++.' WHERE `id_attribute_group` = '.(int)$id_attribute_group.' - AND `id_attribute` = '.(int)$result[$i]['id_attribute']); + AND `id_attribute` = '.(int)$value['id_attribute']); return $return; } @@ -327,11 +327,11 @@ class AttributeCore extends ObjectModel */ public static function getHigherPosition($id_attribute_group) { - $sql = 'SELECT `position` + $sql = 'SELECT MAX(`position`) FROM `'._DB_PREFIX_.'attribute` - WHERE id_attribute_group = '.(int)$id_attribute_group.' - ORDER BY position DESC'; - return ((DB::getInstance()->getValue($sql)!==false)) ? DB::getInstance()->getValue($sql) : -1; + WHERE id_attribute_group = '.(int)$id_attribute_group; + $position = DB::getInstance()->getValue($sql); + return ($position !== false) ? $position : -1; } } diff --git a/classes/AttributeGroup.php b/classes/AttributeGroup.php index f3fceaf42..9311b97be 100644 --- a/classes/AttributeGroup.php +++ b/classes/AttributeGroup.php @@ -262,17 +262,17 @@ class AttributeGroupCore extends ObjectModel $return = true; $sql = ' - SELECT * + SELECT `id_attribute_group` FROM `'._DB_PREFIX_.'attribute_group` ORDER BY `position`'; $result = Db::getInstance()->ExecuteS($sql); - $sizeof = sizeof($result); - for ($i = 0; $i < $sizeof; $i++) + $i = 0; + foreach ($result as $value) $return = Db::getInstance()->Execute(' UPDATE `'._DB_PREFIX_.'attribute_group` - SET `position` = '.(int)$i.' - WHERE `id_attribute_group` = '.(int)$result[$i]['id_attribute_group']); + SET `position` = '.(int)$i++.' + WHERE `id_attribute_group` = '.(int)$value['id_attribute_group']); return $return; } @@ -285,10 +285,10 @@ class AttributeGroupCore extends ObjectModel */ public static function getHigherPosition() { - $sql = 'SELECT `position` - FROM `'._DB_PREFIX_.'attribute_group` - ORDER BY position DESC'; - return ((DB::getInstance()->getValue($sql)!==false)) ? DB::getInstance()->getValue($sql) : -1; + $sql = 'SELECT MAX(`position`) + FROM `'._DB_PREFIX_.'attribute_group`'; + $position = DB::getInstance()->getValue($sql); + return ($position !== false) ? $position : -1; } } diff --git a/classes/Feature.php b/classes/Feature.php index b9922d738..76cc899ea 100644 --- a/classes/Feature.php +++ b/classes/Feature.php @@ -285,17 +285,17 @@ class FeatureCore extends ObjectModel $return = true; $sql = ' - SELECT * + SELECT `id_feature` FROM `'._DB_PREFIX_.'feature` ORDER BY `position`'; $result = Db::getInstance()->ExecuteS($sql); - $sizeof = sizeof($result); - for ($i = 0; $i < $sizeof; $i++) + $i = 0; + foreach ($result as $value) $return = Db::getInstance()->Execute(' UPDATE `'._DB_PREFIX_.'feature` - SET `position` = '.(int)$i.' - WHERE `id_feature` = '.(int)$result[$i]['id_feature']); + SET `position` = '.(int)$i++.' + WHERE `id_feature` = '.(int)$value['id_feature']); return $return; } @@ -308,10 +308,10 @@ class FeatureCore extends ObjectModel */ public static function getHigherPosition() { - $sql = 'SELECT `position` - FROM `'._DB_PREFIX_.'feature` - ORDER BY position DESC'; - return ((DB::getInstance()->getValue($sql)!==false)) ? DB::getInstance()->getValue($sql) : -1; + $sql = 'SELECT MAX(`position`) + FROM `'._DB_PREFIX_.'feature`; + $position = DB::getInstance()->getValue($sql); + return ($position !== false) ? $position : -1; } } diff --git a/controllers/front/CartController.php b/controllers/front/CartController.php index 3555fefb9..9574841c1 100644 --- a/controllers/front/CartController.php +++ b/controllers/front/CartController.php @@ -52,8 +52,8 @@ class CartControllerCore extends FrontController $result['HOOK_SHOPPING_CART_EXTRA'] = Module::hookExec('shoppingCartExtra', $result['summary']); // Display reduced price (or not) without quantity discount if (Tools::getIsset('getproductprice')) - foreach ($result['summary']['products'] as $key => $product) - $result['summary']['products'][$key]['price_without_quantity_discount'] = Product::getPriceStatic($product['id_product'], !Product::getTaxCalculationMethod(), $product['id_product_attribute']); + foreach ($result['summary']['products'] as $key => &$product) + $product['price_without_quantity_discount'] = Product::getPriceStatic($product['id_product'], !Product::getTaxCalculationMethod(), $product['id_product_attribute']); die(Tools::jsonEncode($result)); } else diff --git a/controllers/front/ParentOrderController.php b/controllers/front/ParentOrderController.php index 20b609ace..3ed46dfcd 100644 --- a/controllers/front/ParentOrderController.php +++ b/controllers/front/ParentOrderController.php @@ -257,11 +257,10 @@ class ParentOrderControllerCore extends FrontController } $this->context->smarty->assign('free_ship', $total_free_ship); } - foreach ($summary['products'] AS $key => $product) + foreach ($summary['products'] AS $key => &$product) { - $summary['products'][$key]['quantity'] = $product['cart_quantity'];// for compatibility with 1.2 themes - $std_product = new Product($summary['products'][$key]['id_product']); - $summary['products'][$key]['price_without_specific_price'] = $std_product->getPrice(!Product::getTaxCalculationMethod(), $summary['products'][$key]['id_product_attribute']); + $product['quantity'] = $product['cart_quantity'];// for compatibility with 1.2 themes + $product['price_without_specific_price'] = Product::getPriceStatic($product['id_product'], !Product::getTaxCalculationMethod(), $product['id_product_attribute']); } $this->context->smarty->assign($summary); diff --git a/js/attributesBack.js b/js/attributesBack.js index 19b427b75..e34d2a1c9 100644 --- a/js/attributesBack.js +++ b/js/attributesBack.js @@ -34,7 +34,7 @@ function fillCombinaison(wholesale_price, price_impact, weight_impact, unit_impa $('#attribute_quantity').html(quantity); $('#attribute_quantity').show(); $('#attr_qty_stock').show(); - if(available_date!=undefined) + if(available_date != undefined) getE('available_date').value = available_date; else getE('available_date').value = '0000-00-00'; diff --git a/themes/prestashop/product.tpl b/themes/prestashop/product.tpl index d263996ad..632498f34 100644 --- a/themes/prestashop/product.tpl +++ b/themes/prestashop/product.tpl @@ -170,7 +170,7 @@ var fieldRequired = '{l s='Please fill in all required fields, then save the cus {if isset($images) && count($images) > 3}{l s='Next'}{/if} {/if} - {if isset($images) && count($images) > 1}

{/if} + {if isset($images) && count($images) > 1}

{/if}