[-] BO: Fix weight impact and default combination on combinations generator
This commit is contained in:
+3
-3
@@ -1079,12 +1079,12 @@ class ProductCore extends ObjectModel
|
||||
$obj->available_date = '0000-00-00';
|
||||
}
|
||||
|
||||
$obj->default_on = $default_on;
|
||||
$default_on = 0;
|
||||
|
||||
foreach ($combination as $field => $value)
|
||||
$obj->$field = $value;
|
||||
|
||||
$obj->default_on = $default_on;
|
||||
$default_on = 0;
|
||||
|
||||
$obj->save();
|
||||
|
||||
if (!$id_combination)
|
||||
|
||||
@@ -46,7 +46,7 @@ class AdminAttributeGeneratorControllerCore extends AdminController
|
||||
foreach ($attributes as $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)
|
||||
{
|
||||
@@ -165,11 +165,11 @@ class AdminAttributeGeneratorControllerCore extends AdminController
|
||||
$attributes = array();
|
||||
foreach ($tab as $group)
|
||||
foreach ($group as $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)));
|
||||
$attributes[] = '('.(int)$id_product.', '.(int)$attribute.', '.(float)$price.', '.(float)$weight.')';
|
||||
}
|
||||
{
|
||||
$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)));
|
||||
$attributes[] = '('.(int)$id_product.', '.(int)$attribute.', '.(float)$price.', '.(float)$weight.')';
|
||||
}
|
||||
|
||||
return Db::getInstance()->execute('
|
||||
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)');
|
||||
}
|
||||
|
||||
protected static function getAttributesImpacts($id_product)
|
||||
{
|
||||
$tab = array();
|
||||
$result = Db::getInstance()->executeS(
|
||||
'SELECT ai.`id_attribute`, ai.`price`, ai.`weight`
|
||||
FROM `'._DB_PREFIX_.'attribute_impact` ai
|
||||
WHERE ai.`id_product` = '.(int)$id_product);
|
||||
if (!$result)
|
||||
return array();
|
||||
foreach ($result as $impact)
|
||||
{
|
||||
$tab[$impact['id_attribute']]['price'] = (float)$impact['price'];
|
||||
$tab[$impact['id_attribute']]['weight'] = (float)$impact['weight'];
|
||||
}
|
||||
return $tab;
|
||||
protected static function getAttributesImpacts($id_product)
|
||||
{
|
||||
$tab = array();
|
||||
$result = Db::getInstance()->executeS(
|
||||
'SELECT ai.`id_attribute`, ai.`price`, ai.`weight`
|
||||
FROM `'._DB_PREFIX_.'attribute_impact` ai
|
||||
WHERE ai.`id_product` = '.(int)$id_product);
|
||||
|
||||
if (!$result)
|
||||
return array();
|
||||
foreach ($result as $impact)
|
||||
{
|
||||
$tab[$impact['id_attribute']]['price'] = (float)$impact['price'];
|
||||
$tab[$impact['id_attribute']]['weight'] = (float)$impact['weight'];
|
||||
}
|
||||
return $tab;
|
||||
}
|
||||
|
||||
public function initGroupTable()
|
||||
{
|
||||
$combinations_groups = $this->product->getAttributesGroups($this->context->language->id);
|
||||
$attributes = array();
|
||||
$impacts = AdminAttributeGeneratorController::getAttributesImpacts($this->product->id);
|
||||
$impacts = AdminAttributeGeneratorController::getAttributesImpacts($this->product->id);
|
||||
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;
|
||||
if (isset($impacts[$combination['id_attribute']]))
|
||||
{
|
||||
if (isset($impacts[$combination['id_attribute']]))
|
||||
{
|
||||
$target['price'] = $impacts[$combination['id_attribute']]['price'];
|
||||
$target['weight'] = $impacts[$combination['id_attribute']]['weight'];
|
||||
}
|
||||
|
||||
@@ -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>'+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><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>';
|
||||
|
||||
return html;
|
||||
|
||||
Reference in New Issue
Block a user