0

I m trying to delete my db table row using below code from observer. but can't delete it gives error in system log

 Some transactions have not been committed or rolled back

$customFieldValue =  $this->_getRequest()->getPost();
             //$groupCodeArray = $customFieldValue['product']['customer_group_ids'];

             $DataCollectionDel = Mage::getModel('customerspecificproduct/customerspecificproduct')->getCollection()->addFieldToFilter(
                'product_ids',
                array(
                    'eq'=>$product->getId()
                )
            )->addFieldToFilter(
                'group_id',
                array(
                    'notnull'=>true,
                )
            );


            if($DataCollectionDel){
             foreach($DataCollectionDel as $data){
                    $deleteRow = Mage::getModel('customerspecificproduct/customerspecificproduct')->load($data->getId())->delete();

                }
             }exit;
Zaheerabbas
  • 1,119
  • 20
  • 46

2 Answers2

0

I found solution myself

$DataCollectionDel = Mage::getModel('customerspecificproduct/customerspecificproduct')->getCollection()->addFieldToFilter(
                'product_ids',
                array(
                    'eq'=>$product->getId()
                )
            )->addFieldToFilter(
                'group_id',
                array(
                    'notnull'=>true,
                )
            );



             try{
                if($DataCollectionDel){
             foreach($DataCollectionDel as $data){
                    $data->delete();
                }
             }
Zaheerabbas
  • 1,119
  • 20
  • 46
0

I found solution for it :3 without getCollection(). Model

 public function deleteByCondition($itemId,$vendor)
    {
        return $this->getResource()->deleteByCondition($itemId,$vendor);
    }

Resource Model

  public function deleteByCondition($itemId,$vendor)
    {
        $table = $this->getMainTable();
        $where = array();
        $where[] =  $this->_getWriteAdapter()->quoteInto('item_id = ?',$itemId);
        $where[] =  $this->_getWriteAdapter()->quoteInto("vendor = ? ", $vendor);
        $result = $this->_getWriteAdapter()->delete($table,$where);
        return $result;
    }
HoangHieu
  • 2,802
  • 3
  • 28
  • 44