observador evento que necesite para el producto de importación Salvo controlador de fila
-
16-10-2019 - |
Pregunta
¿Cómo puedo coger la importación de productos modelo Mage_Catalog_Model_Convert_Adapter_Product saverow () evento usando observador.
Mage::dispatchEvent('catalog_product_import_profile_after', array('adapter'=>$this));
i utilizar este, pero no conseguir el éxito.
Este es mi código: en mis \ APP \ code \ comunidad \ Compnyname \ ImportProduct \ controllers \ Adminhtml \ RunProfileController.php
class Compnyname_ImportProduct_Adminhtml_RunProfileController extends Mage_Adminhtml_Controller_action
{
protected function _initAction()
{
.....
}
public function indexAction()
{
........
}
public function runAction()
{
...........
}
public function batchRunAction()
{
$currentUrl = Mage::helper('core/url')->getCurrentUrl();
$ids = explode("/", $currentUrl);
$id=$ids[11];
$file=explode("?",$id);
$file_name = $file[0];
$path = Mage::getBaseDir('var') . DS . 'import' . DS ;
$filepath =$path.$file_name;
$header=array();
$header1=array();
$i = 0;
if(($handle = fopen("$filepath", "r")) !== FALSE)
{
while(($data = fgetcsv($handle, 1000, ",")) !== FALSE)
{
if($i==0)
{
$header1[$i]=$data;
}
else
{
$header[$i]=$data;
}
$i++;
}
$array1=array();
$array2=array();
for($kd=1;$kd<=count($header);$kd++)
{
$jk=0;
foreach ($header1[0] as $key => $value)
{
$array1[$value]=$header[$kd][$jk];
$jk++;
}
$this->updateData($array1);
}
}
return true;
}
public function updateData($data)
{
//$importData=$data;
$collection = Mage::getModel('importproduct/convert_adapter_product')->saveRow($data);
if($collection)
{
$this->batchFinish();
}else{
$this->batchError();
}
//$j = $j + 1;
//return "hello";
}
public function batchFinish()
{
//$batchId = $this->getRequest()->getParam('id');
Mage::dispatchEvent('catalog_product_import_profile_after', array('adapter'=>$this));
//Mage::dispatchEvent('catalog_product_prepare_save', array('adapter'=>$this));
//catalog_product_prepare_save
//echo "hello".$var;
echo "batchfinish....";
}
public function batchError()
{
echo "error";
}
function testAction()
{
echo "testing...";
}
}
?>
aplicación \ code \ comunidad \ Compnyname \ ImportProduct \ Model \ Convert \ Adapter \ product.php
class Compmyname_ImportProduct_Model_Convert_Adapter_Product extends Mage_Catalog_Model_Convert_Adapter_Product
{
.....
public function saveRow(array $importData)
{
code for save raw
}
......
}
Quiero llamar observador durante el proceso de importación de productos se está ejecutando y después de la llamada de observador cuando una fila es de importación. Por ejemplo, si en csv hay 500 producto, entonces llamada observador 500 tiempo.
Por favor, ayuda a resolver este problema.
Solución
Parece como si está reescribiendo el método Mage_Catalog_Model_Convert_Adapter_Product
- añadir su despacho allí:
class Compmyname_ImportProduct_Model_Convert_Adapter_Product extends Mage_Catalog_Model_Convert_Adapter_Product
{
public function saveRow(array $importData)
{
//do the work from the parent class
parent::saveRow($importData);
//dispatch your own event
Mage::dispatchEvent('convert_adapter_product_save_row_after', array('import_data'=>$importData, 'product'=>$this));
}
}