[-] BO: Fix weight impact and default combination on combinations generator
This commit is contained in:
@@ -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'];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user