[-] BO: Fix weight impact and default combination on combinations generator

git-svn-id: http://dev.prestashop.com/svn/v1/branches/1.5.x@17378 b9a71923-0436-4b27-9f14-aed3839534dd
This commit is contained in:
rGaillard
2012-09-14 15:45:11 +00:00
parent d59308a9b6
commit d13be9e69e
3 changed files with 30 additions and 29 deletions
+3 -3
View File
@@ -1079,12 +1079,12 @@ class ProductCore extends ObjectModel
$obj->available_date = '0000-00-00'; $obj->available_date = '0000-00-00';
} }
$obj->default_on = $default_on;
$default_on = 0;
foreach ($combination as $field => $value) foreach ($combination as $field => $value)
$obj->$field = $value; $obj->$field = $value;
$obj->default_on = $default_on;
$default_on = 0;
$obj->save(); $obj->save();
if (!$id_combination) if (!$id_combination)
@@ -46,7 +46,7 @@ class AdminAttributeGeneratorControllerCore extends AdminController
foreach ($attributes as $attribute) foreach ($attributes as $attribute)
{ {
$price += (float)preg_replace('/[^0-9.]/', '', str_replace(',', '.', Tools::getValue('price_impact_'.(int)$attribute))); $price += (float)preg_replace('/[^0-9.]/', '', str_replace(',', '.', Tools::getValue('price_impact_'.(int)$attribute)));
$weight += (float)preg_replace('/[^0-9.]/', '', str_replace(',', '.', Tools::getValue('weight_impact'.(int)$attribute))); $weight += (float)preg_replace('/[^0-9.]/', '', str_replace(',', '.', Tools::getValue('weight_impact_'.(int)$attribute)));
} }
if ($this->product->id) if ($this->product->id)
{ {
@@ -165,11 +165,11 @@ class AdminAttributeGeneratorControllerCore extends AdminController
$attributes = array(); $attributes = array();
foreach ($tab as $group) foreach ($tab as $group)
foreach ($group as $attribute) foreach ($group as $attribute)
{ {
$price = preg_replace('/[^0-9.]/', '', str_replace(',', '.', Tools::getValue('price_impact_'.(int)$attribute))); $price = preg_replace('/[^0-9.]/', '', str_replace(',', '.', Tools::getValue('price_impact_'.(int)$attribute)));
$weight = preg_replace('/[^0-9.]/', '', str_replace(',', '.', Tools::getValue('weight_impact'.(int)$attribute))); $weight = preg_replace('/[^0-9.]/', '', str_replace(',', '.', Tools::getValue('weight_impact_'.(int)$attribute)));
$attributes[] = '('.(int)$id_product.', '.(int)$attribute.', '.(float)$price.', '.(float)$weight.')'; $attributes[] = '('.(int)$id_product.', '.(int)$attribute.', '.(float)$price.', '.(float)$weight.')';
} }
return Db::getInstance()->execute(' return Db::getInstance()->execute('
INSERT INTO `'._DB_PREFIX_.'attribute_impact` (`id_product`, `id_attribute`, `price`, `weight`) INSERT INTO `'._DB_PREFIX_.'attribute_impact` (`id_product`, `id_attribute`, `price`, `weight`)
@@ -177,34 +177,35 @@ class AdminAttributeGeneratorControllerCore extends AdminController
ON DUPLICATE KEY UPDATE `price` = VALUES(price), `weight` = VALUES(weight)'); ON DUPLICATE KEY UPDATE `price` = VALUES(price), `weight` = VALUES(weight)');
} }
protected static function getAttributesImpacts($id_product) protected static function getAttributesImpacts($id_product)
{ {
$tab = array(); $tab = array();
$result = Db::getInstance()->executeS( $result = Db::getInstance()->executeS(
'SELECT ai.`id_attribute`, ai.`price`, ai.`weight` 'SELECT ai.`id_attribute`, ai.`price`, ai.`weight`
FROM `'._DB_PREFIX_.'attribute_impact` ai FROM `'._DB_PREFIX_.'attribute_impact` ai
WHERE ai.`id_product` = '.(int)$id_product); WHERE ai.`id_product` = '.(int)$id_product);
if (!$result)
return array(); if (!$result)
foreach ($result as $impact) return array();
{ foreach ($result as $impact)
$tab[$impact['id_attribute']]['price'] = (float)$impact['price']; {
$tab[$impact['id_attribute']]['weight'] = (float)$impact['weight']; $tab[$impact['id_attribute']]['price'] = (float)$impact['price'];
} $tab[$impact['id_attribute']]['weight'] = (float)$impact['weight'];
return $tab; }
return $tab;
} }
public function initGroupTable() public function initGroupTable()
{ {
$combinations_groups = $this->product->getAttributesGroups($this->context->language->id); $combinations_groups = $this->product->getAttributesGroups($this->context->language->id);
$attributes = array(); $attributes = array();
$impacts = AdminAttributeGeneratorController::getAttributesImpacts($this->product->id); $impacts = AdminAttributeGeneratorController::getAttributesImpacts($this->product->id);
foreach ($combinations_groups as &$combination) foreach ($combinations_groups as &$combination)
{ {
$target = &$attributes[$combination['id_attribute_group']][$combination['id_attribute']]; $target = &$attributes[$combination['id_attribute_group']][$combination['id_attribute']];
$target = $combination; $target = $combination;
if (isset($impacts[$combination['id_attribute']])) if (isset($impacts[$combination['id_attribute']]))
{ {
$target['price'] = $impacts[$combination['id_attribute']]['price']; $target['price'] = $impacts[$combination['id_attribute']]['price'];
$target['weight'] = $impacts[$combination['id_attribute']]['weight']; $target['weight'] = $impacts[$combination['id_attribute']]['weight'];
} }
+1 -1
View File
@@ -127,7 +127,7 @@ function create_attribute_row(id, id_group, name, price, weight)
html += '<td><input type="hidden" value="'+id+'" name="options['+id_group+']['+id+']" />'+name+'</td>'; html += '<td><input type="hidden" value="'+id+'" name="options['+id_group+']['+id+']" />'+name+'</td>';
html += '<td>'+i18n_tax_exc+'<input id="related_to_price_impact_ti_'+id+'" class="price_impact" style="width:50px" type="text" value="'+price+'" name="price_impact_'+id+'" onkeyup="calcPrice($(this), false)"></td>'; html += '<td>'+i18n_tax_exc+'<input id="related_to_price_impact_ti_'+id+'" class="price_impact" style="width:50px" type="text" value="'+price+'" name="price_impact_'+id+'" onkeyup="calcPrice($(this), false)"></td>';
html += '<td>'+i18n_tax_inc+'<input id="related_to_price_impact_'+id+'" class="price_impact_ti" style="width:50px" type="text" value="" name="price_impact_ti_'+id+'" onkeyup="calcPrice($(this), true)"></td>'; html += '<td>'+i18n_tax_inc+'<input id="related_to_price_impact_'+id+'" class="price_impact_ti" style="width:50px" type="text" value="" name="price_impact_ti_'+id+'" onkeyup="calcPrice($(this), true)"></td>';
html += '<td><input style="width:50px" type="text" value="'+weight+'" name="weight_impact['+id+']"></td>'; html += '<td><input style="width:50px" type="text" value="'+weight+'" name="weight_impact_'+id+'"></td>';
html += '</tr>'; html += '</tr>';
return html; return html;