Hello everyone, I'm developing a module for magento whose goal is to select 3 products for example and update an attribute where I created an X value that will add up to the total value of the product giving the result in another attribute is it possible? I'm doing this and saving product by product and it works but I wanted the same bulk option for example add 20 reais to 5 products with different values resulting in a new attribute, if I can help ...
<?xml version="1.0" encoding="UTF-8"?>
<config>
<modules>
<Ceicom_AdditionPriceMercadolivre>
<version>1.0</version>
</Ceicom_AdditionPriceMercadolivre>
</modules>
<models>
<Ceicom_AdditionPriceMercadolivre>
<class>Ceicom_AdditionPriceMercadolivre_Model</class>
</Ceicom_AdditionPriceMercadolivre>
</models>
<global>
<events>
<catalog_product_prepare_save>
<observers>
<Ceicom_AdditionPriceMercadolivre>
<type>singleton</type>
<class>Ceicom_AdditionPriceMercadolivre_Model_Observer</class>
<method>setPrices</method>
</Ceicom_AdditionPriceMercadolivre>
</observers>
</catalog_product_prepare_save><!-- catalog_product_save_before -->
</events>
</global>
</config>
class Ceicom_AdditionPriceMercadolivre_Model_Observer {
public function setPrices(Varien_Event_Observer $observer) {
$_product = $observer->getProduct();
$product = $observer->getProduct();
$price = $product->getFinalPrice();
//pega o valor do atributo
$addition_price = $_product->getResource()->getAttribute('acrescimo_mercadolivre');
$valueAddition = $addition_price ->getFrontend()->getValue($_product);
//faz o calculo
$finalPrice = $price + $valueAddition;
$formattedPrice = number_format($finalPrice, 2, '.', '');
//exibe o resultado
if($addition_price > 0){
$product->setData('mercadolivre_price', $formattedPrice);
}
}
}