0

We have a scenario where schools.csv file will be uploaded under schoolsearch folder under the Magento root directory. This should update the schools table under Magento database. But since migration its not working. We are using a module for this task. But its not working. The following is the content of observer.php

class Attigo_Schoolsearch_Model_Observer
{
    protected function getfilepath()
    {   
        Mage::getBaseDir(). DS .'csv'. DS . 'schoolsearch/schools.csv';

    }

    public function schoolDetail()
    { 

        $row=array();
        //$filePath = $this->getfilepath();
        $filePath = "/var/www/html/main/schoolsearch/schools.csv";


    if (($handle = fopen($filePath, 'r')) !== FALSE) 
        {
            $i=0;
            while (($data = fgetcsv($handle, 1000, '\t')) !== FALSE) 
            {

                    if($i==0)
                    {
                        $i++;
                        continue;
                    }

                     if($data != "")
                     {
                        foreach ($data as $school) {
                         //   echo $school.'';
                           $row=explode("\t",$school);

                        }

                        $school = Mage::getModel('schoolsearch/schools');

                        $school->setKundnr($row[0]);
                        $school->setSkola($row[1]);
                        $school->setBadress($row[2]);
                        $school->setBadress1($row[3]);
                        $school->setBpostnummer($row[4]);
                        $school->setBpostort($row[5]);
                        $school->setFakturamottagare($row[6]);
                        $school->setFakturaadress1($row[7]);
                        $school->setFakturaadress2($row[8]);
                        $school->setFpostnr($row[9]);
                        $school->setFpostort($row[10]);
                        $school->setBadressid($row[11]);
                        $school->setFakturaadressid($row[12]);
                        $school->setBcountrycode($row[13]);
                        $school->setFakturacountrycode($row[14]);
                        $school->save();

                       // print_r($school);
                       // echo $row[13].'->'.$row[14].'';


                     }

            $i++;
            }            
        }
        else
        {
            echo "permission denide";
        }
    }
    public function AddCustomerGroup(Varien_Event_Observer $observer)
    {
            $_post = Mage::app()->getFrontController()->getRequest()->getParams();

        try {

            $customer = $observer->getEvent()->getCustomer();

            $customer->setData('group_id', $_post['group_id']); // or whatever the group id should be
            $customer->save();

        } catch ( Exception $e ) {
            echo $e->getMessage;
        }


    }


}

Can any one help me where it goes wrong?

1
  • On which event observer trigger? Any error while you trying to import Apr 11, 2016 at 5:42

1 Answer 1

1

Replace your schoolDetail function to following code :

public function schoolDetail()
    { 

        $fileLocation = Mage::getBaseDir('media').DS.'importexpert/schools.csv';
        $mageCsv = new Varien_File_Csv(); 
        $data = $mageCsv->getData($fileLocation);   
        foreach($data as $row)
        {
            $school = Mage::getModel('schoolsearch/schools');
            $school->setKundnr($row[0]);
            $school->setSkola($row[1]);
            $school->setBadress($row[2]);
            $school->setBadress1($row[3]);
            $school->setBpostnummer($row[4]);
            $school->setBpostort($row[5]);
            $school->setFakturamottagare($row[6]);
            $school->setFakturaadress1($row[7]);
            $school->setFakturaadress2($row[8]);
            $school->setFpostnr($row[9]);
            $school->setFpostort($row[10]);
            $school->setBadressid($row[11]);
            $school->setFakturaadressid($row[12]);
            $school->setBcountrycode($row[13]);
            $school->setFakturacountrycode($row[14]);
            $school->save();
        }

    }

Put your schools.csv under media/importexpert/ folder and clear the cache run the code again.Hope it will work.

1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.