// cleaning code (norm / perf)

git-svn-id: http://dev.prestashop.com/svn/v1/branches/1.5.x@8810 b9a71923-0436-4b27-9f14-aed3839534dd
This commit is contained in:
vChabot
2011-09-27 15:08:24 +00:00
parent 810f17c38e
commit 2045401f9e
10 changed files with 52 additions and 53 deletions
+1 -1
View File
@@ -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();
}
+4 -4
View File
@@ -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);
}
}
}
+3 -3
View File
@@ -3463,7 +3463,7 @@ class AdminProducts extends AdminTab
</tr>
<tr>
<td style="width:150px;vertical-align:top;text-align:right;padding-right:10px;font-weight:bold;" class="col-left" style="width:150px">'.$this->l('Available date:').'</td>
<td style="padding-bottom:5px;"><input id="available_date" name="available_date" value="'.(($this->getFieldValue($obj, 'available_date')!=0) ? stripslashes(htmlentities(Tools::displayDate($this->getFieldValue($obj, 'available_date'), $language['id_lang']))) : '0000-00-00').'" style="text-align: center;" type="text" />
<td style="padding-bottom:5px;"><input id="available_date" name="available_date" value="'.(($this->getFieldValue($obj, 'available_date') != 0) ? stripslashes(htmlentities(Tools::displayDate($this->getFieldValue($obj, 'available_date'), $language['id_lang']))) : '0000-00-00').'" style="text-align: center;" type="text" />
<p>'.$this->l('The available date when this product is out of stock').'</p>
</td>
</tr>';
@@ -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 '
<tr'.($irow++ % 2 ? ' class="alt_row"' : '').($product_attribute['default_on'] ? ' style="background-color:#D1EAEF"' : '').'>
<td>'.stripslashes($list).'</td>
@@ -3583,7 +3583,7 @@ class AdminProducts extends AdminTab
<a style="cursor: pointer;">
<img src="../img/admin/edit.gif" alt="'.$this->l('Modify this combination').'"
onclick="javascript:fillCombinaison(\''.$product_attribute['wholesale_price'].'\', \''.$product_attribute['price'].'\', \''.$product_attribute['weight'].'\', \''.$product_attribute['unit_impact'].'\', \''.$product_attribute['reference'].'\', \''.$product_attribute['supplier_reference'].'\', \''.$product_attribute['ean13'].'\',
\''.$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'].'\', \''.$available_date.'\'); calcImpactPriceTI();" /></a>&nbsp;
\''.$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();" /></a>&nbsp;
'.(!$product_attribute['default_on'] ? '<a href="'.self::$currentIndex.'&defaultProductAttribute&id_product_attribute='.$id_product_attribute.'&id_product='.$obj->id.'&'.(Tools::isSubmit('id_category') ? 'id_category='.(int)(Tools::getValue('id_category')).'&' : '&').'token='.Tools::getAdminToken('AdminCatalog'.(int)(Tab::getIdFromClassName('AdminCatalog')).$this->context->employee->id).'">
<img src="../img/admin/asterisk.gif" alt="'.$this->l('Make this the default combination').'" title="'.$this->l('Make this combination the default one').'"></a>' : '').'
<a href="'.self::$currentIndex.'&deleteProductAttribute&id_product_attribute='.$id_product_attribute.'&id_product='.$obj->id.'&'.(Tools::isSubmit('id_category') ? 'id_category='.(int)(Tools::getValue('id_category')).'&' : '&').'token='.Tools::getAdminToken('AdminCatalog'.(int)(Tab::getIdFromClassName('AdminCatalog')).(int)$this->context->employee->id).'" onclick="return confirm(\''.$this->l('Are you sure?', __CLASS__, true, false).'\');">
+8 -8
View File
@@ -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;
}
}
+9 -9
View File
@@ -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;
}
}
+9 -9
View File
@@ -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;
}
}
+2 -2
View File
@@ -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
+3 -4
View File
@@ -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);
+1 -1
View File
@@ -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';
+12 -12
View File
@@ -170,7 +170,7 @@ var fieldRequired = '{l s='Please fill in all required fields, then save the cus
{if isset($images) && count($images) > 3}<a id="view_scroll_right" title="{l s='Other views'}" href="javascript:{ldelim}{rdelim}">{l s='Next'}</a>{/if}
</div>
{/if}
{if isset($images) && count($images) > 1}<p class="align_center clear"><span id="wrapResetImages" style="display: none;"><img src="{$img_dir}icon/cancel_16x18.gif" alt="{l s='Cancel'}" width="16" height="18"/> <a id="resetImages" href="{$link->getProductLink($product)}" onclick="$('span#wrapResetImages').hide('slow');return (false);">{l s='Display all pictures'}</a></span></p>{/if}
{if isset($images) && count($images) > 1}<p class="align_center clear"><span id="wrapResetImages" style="display: none"><img src="{$img_dir}icon/cancel_16x18.gif" alt="{l s='Cancel'}" width="16" height="18"/> <a id="resetImages" href="{$link->getProductLink($product)}" onclick="$('span#wrapResetImages').hide('slow');return (false);">{l s='Display all pictures'}</a></span></p>{/if}
<!-- usefull links-->
<ul id="usefull_link_block">
{if $HOOK_EXTRA_LEFT}{$HOOK_EXTRA_LEFT}{/if}
@@ -324,17 +324,17 @@ var fieldRequired = '{l s='Please fill in all required fields, then save the cus
{/foreach}
</div>
{/if}
<p id="product_reference" {if isset($groups) OR !$product->reference}style="display: none;"{/if}>
<p id="product_reference" {if isset($groups) OR !$product->reference}style="display: none"{/if}>
<label for="product_reference">{l s='Reference :'} </label>
<span class="editable">{$product->reference|escape:'htmlall':'UTF-8'}</span>
</p>
<!-- quantity wanted -->
<p id="quantity_wanted_p"{if (!$allow_oosp && $product->quantity <= 0) OR $virtual OR !$product->available_for_order OR $PS_CATALOG_MODE} style="display: none;"{/if}>
<p id="quantity_wanted_p"{if (!$allow_oosp && $product->quantity <= 0) OR $virtual OR !$product->available_for_order OR $PS_CATALOG_MODE} style="display: none"{/if}>
<label>{l s='Quantity :'}</label>
<input type="text" name="qty" id="quantity_wanted" class="text" value="{if isset($quantityBackup)}{$quantityBackup|intval}{else}{if $product->minimal_quantity > 1}{$product->minimal_quantity}{else}1{/if}{/if}" size="2" maxlength="3" {if $product->minimal_quantity > 1}onkeyup="checkMinimalQuantity({$product->minimal_quantity});"{/if} />
</p>
<!-- minimal quantity wanted -->
<p id="minimal_quantity_wanted_p"{if $product->minimal_quantity <= 1 OR !$product->available_for_order OR $PS_CATALOG_MODE} style="display: none;"{/if}>
<p id="minimal_quantity_wanted_p"{if $product->minimal_quantity <= 1 OR !$product->available_for_order OR $PS_CATALOG_MODE} style="display: none"{/if}>
{l s='You must add '}<b id="minimal_quantity_label">{$product->minimal_quantity}</b>{l s=' as a minimum quantity to buy this product.'}
</p>
{if $product->minimal_quantity > 1}
@@ -343,7 +343,7 @@ var fieldRequired = '{l s='Please fill in all required fields, then save the cus
</script>
{/if}
<!-- availability -->
<p id="availability_statut"{if ($product->quantity <= 0 && !$product->available_later && $allow_oosp) OR ($product->quantity > 0 && !$product->available_now) OR !$product->available_for_order OR $PS_CATALOG_MODE} style="display: none;"{/if}>
<p id="availability_statut"{if ($product->quantity <= 0 && !$product->available_later && $allow_oosp) OR ($product->quantity > 0 && !$product->available_now) OR !$product->available_for_order OR $PS_CATALOG_MODE} style="display: none"{/if}>
<span id="availability_label">{l s='Availability:'}</span>
<span id="availability_value"{if $product->quantity <= 0} class="warning_inline"{/if}>
{if $product->quantity <= 0}{if $allow_oosp}{$product->available_later}{else}{l s='This product is no longer in stock'}{/if}{else}{$product->available_now}{/if}
@@ -351,32 +351,32 @@ var fieldRequired = '{l s='Please fill in all required fields, then save the cus
{if ($product->available_date && $product->available_date != 0) && ($product->available_date|date_format:"%Y-%m-%d" >= $smarty.now|date_format:"%Y-%m-%d") && $product->quantity <= 0}<br /><span id="availability_date_label">{l s='Restocking:'}</span><span id="availability_date_value" class="success_inline">{$product->available_date|date_format:"%d-%m-%Y"}</span>
{else}
<br /><span id="availability_date_label" style="display:none;">{l s='Restocking:'}</span><span id="availability_date_value" class="success_inline" style="display:none;">{$product->available_date|date_format:"%d-%m-%Y"}</span>
<br /><span id="availability_date_label" style="display:none">{l s='Restocking:'}</span><span id="availability_date_value" class="success_inline" style="display:none">{$product->available_date|date_format:"%d-%m-%Y"}</span>
{/if}
</p>
<!-- number of item in stock -->
{if ($display_qties == 1 && !$PS_CATALOG_MODE && $product->available_for_order)}
<p id="pQuantityAvailable"{if $product->quantity <= 0} style="display: none;"{/if}>
<p id="pQuantityAvailable"{if $product->quantity <= 0} style="display: none"{/if}>
<span id="quantityAvailable">{$product->quantity|intval}</span>
<span {if $product->quantity > 1} style="display: none;"{/if} id="quantityAvailableTxt">{l s='item in stock'}</span>
<span {if $product->quantity == 1} style="display: none;"{/if} id="quantityAvailableTxtMultiple">{l s='items in stock'}</span>
<span {if $product->quantity > 1} style="display: none"{/if} id="quantityAvailableTxt">{l s='item in stock'}</span>
<span {if $product->quantity == 1} style="display: none"{/if} id="quantityAvailableTxtMultiple">{l s='items in stock'}</span>
</p>
{/if}
<!-- Out of stock hook -->
{if !$allow_oosp}
<p id="oosHook"{if $product->quantity > 0} style="display: none;"{/if}>
<p id="oosHook"{if $product->quantity > 0} style="display: none"{/if}>
{$HOOK_PRODUCT_OOS}
</p>
{/if}
<p class="warning_inline" id="last_quantities"{if ($product->quantity > $last_qties OR $product->quantity <= 0) OR $allow_oosp OR !$product->available_for_order OR $PS_CATALOG_MODE} style="display: none;"{/if} >{l s='Warning: Last items in stock!'}</p>
<p class="warning_inline" id="last_quantities"{if ($product->quantity > $last_qties OR $product->quantity <= 0) OR $allow_oosp OR !$product->available_for_order OR $PS_CATALOG_MODE} style="display: none"{/if} >{l s='Warning: Last items in stock!'}</p>
{if $product->online_only}
<p>{l s='Online only'}</p>
{/if}
<p{if (!$allow_oosp && $product->quantity <= 0) OR !$product->available_for_order OR (isset($restricted_country_mode) AND $restricted_country_mode) OR $PS_CATALOG_MODE} style="display: none;"{/if} id="add_to_cart" class="buttons_bottom_block"><input type="submit" name="Submit" value="{l s='Add to cart'}" class="exclusive" /></p>
<p{if (!$allow_oosp && $product->quantity <= 0) OR !$product->available_for_order OR (isset($restricted_country_mode) AND $restricted_country_mode) OR $PS_CATALOG_MODE} style="display: none"{/if} id="add_to_cart" class="buttons_bottom_block"><input type="submit" name="Submit" value="{l s='Add to cart'}" class="exclusive" /></p>
{if isset($HOOK_PRODUCT_ACTIONS) && $HOOK_PRODUCT_ACTIONS}{$HOOK_PRODUCT_ACTIONS}{/if}
<div class="clear"></div>
</form>