我有一个magento自定义模块,工作正常。我想要的是我有一个sql更新查询,它在表单加载时运行,而我希望它在保存/提交后运行。
form.php文件的第一个是这样的:
<?php
class Mywebsolutions_Autopriceupdate_Block_Adminhtml_Autopriceupdate_Edit_Tab_Form extends Mage_Adminhtml_Block_Widget_Form
{
protected function _prepareForm()
{
$form = new Varien_Data_Form();
$this->setForm($form);
$fieldset = $form->addFieldset("autopriceupdate_form", array("legend"=>Mage::helper("autopriceupdate")->__("Item information")));
$fieldset->addField("date", "date", array(
"label" =>Mage::helper ("autopriceupdate")->__("Date"),
"name" => "date",
'image' => $this->getSkinUrl('images/grid-cal.gif'),
'format' => Mage::app()->getLocale()->getDateFormat(Mage_Core_Model_Locale::FORMAT_TYPE_MEDIUM)
));
$fieldset->addField("goldrate", "text", array(
"label" => Mage::helper("autopriceupdate")->__("GoldRate"),
"name" => "goldrate",
));
/*
$fieldset->addField('status', 'select', array(
'label' => Mage::helper('autopriceupdate')->__('Status'),
'values' => Mywebsolutions_Autopriceupdate_Block_Adminhtml_Autopriceupdate_Grid::getValueArray2(),
'name' => 'status',
));*/
if (Mage::getSingleton("adminhtml/session")->getAutopriceupdateData())
{
$form->setValues(Mage::getSingleton("adminhtml/session")->getAutopriceupdateData());
Mage::getSingleton("adminhtml/session")->setAutopriceupdateData(null);
}
elseif(Mage::registry("autopriceupdate_data")) {
$form->setValues(Mage::registry("autopriceupdate_data")->getData());
}
return parent::_prepareForm();
}
}
from.php的第二部分,我想在提交/保存后运行
//database write adapter custom query by myweb solutions
$write = Mage::getSingleton('core/resource')->getConnection('core_write');
//update query for 22 carat making charges
$write->query("update catalog_product_entity_varchar cpev, (select value,entity_id from catalog_product_entity_varchar
where attribute_id=139) cpev1, eav_attribute eav, catalog_product_entity p, autopriceupdate a, catalog_product_flat_1 cpf
SET cpev.value =round((((a.goldrate)/24)*22*cpf.weight)*cpev1.value/100,-1)
where
a.autopriceupdate_id=(
SELECT max(autopriceupdate_id) FROM autopriceupdate
)
and
eav.entity_type_id =4
AND eav.attribute_code = 'price'
AND p.entity_id = cpev.entity_id
AND p.attribute_set_id =10
AND cpev.attribute_id=140
and cpev1.entity_id = cpev.entity_id
AND cpf.entity_id =cpev.entity_id
AND cpf.metal_purity=4");
//myweb solutions using a time gap before execution of next query;
sleep(5);
//update query for 18 carat making charges
$write->query("update catalog_product_entity_varchar cpev, (select value,entity_id from catalog_product_entity_varchar
where attribute_id=139) cpev1, eav_attribute eav, catalog_product_entity p, autopriceupdate a, catalog_product_flat_1 cpf
SET cpev.value =round((((a.goldrate)/24)*18*cpf.weight)*cpev1.value/100,-1)
where
a.autopriceupdate_id=(
SELECT max(autopriceupdate_id) FROM autopriceupdate
)
and
eav.entity_type_id =4
AND eav.attribute_code = 'price'
AND p.entity_id = cpev.entity_id
AND p.attribute_set_id =10
AND cpev.attribute_id=140
and cpev1.entity_id = cpev.entity_id
AND cpf.entity_id =cpev.entity_id
AND cpf.metal_purity=3");
//myweb solutions using a time gap before execution of next query;
sleep(5);
//update query for 22 carat price
$write->query("update catalog_product_entity_decimal val, eav_attribute eav, catalog_product_entity p, autopriceupdate a,
catalog_product_flat_1 cpf,
catalog_product_entity_varchar cpev
SET val.value =round(((((a.goldrate)/24)*22*cpf.weight)+cpev.value),-1)
WHERE
a.autopriceupdate_id=(
SELECT max(autopriceupdate_id) FROM autopriceupdate
)
and
eav.entity_type_id =4
AND eav.attribute_code = 'price'
AND p.entity_id = val.entity_id
AND p.entity_id = cpev.entity_id
AND cpev.attribute_id=140
AND p.attribute_set_id =10
AND val.attribute_id = eav.attribute_id
AND cpf.entity_id =val.entity_id
AND cpf.metal_purity=4");
//myweb solutions using a time gap before execution of next query;
sleep(5);
$write->query("update catalog_product_entity_decimal val, eav_attribute eav, catalog_product_entity p, autopriceupdate a,
catalog_product_flat_1 cpf,
catalog_product_entity_varchar cpev
SET val.value =round(((((a.goldrate)/24)*18*cpf.weight)+cpev.value),-1)
WHERE
a.autopriceupdate_id=(
SELECT max(autopriceupdate_id) FROM autopriceupdate
)
and
eav.entity_type_id =4
AND eav.attribute_code = 'price'
AND p.entity_id = val.entity_id
AND p.entity_id = cpev.entity_id
AND cpev.attribute_id=140
AND p.attribute_set_id =10
AND val.attribute_id = eav.attribute_id
AND cpf.entity_id =val.entity_id
AND cpf.metal_purity=3");
如何在magento中完成此操作。