Magento Expert Forum - Improve your Magento experience

Results 1 to 2 of 2

CSV import not working - Need Assistance

  1. #1
    New member
    Join Date
    Apr 2016
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Exclamation CSV import not working - Need Assistance

    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;
    }


    }


    }
    ?>

    Why its not working?

    View more threads in the same category:


  2. #2
    Junior Member
    Join Date
    Jun 2016
    Location
    Bhavnagar, Gujarat, India
    Posts
    1,125
    Thanks
    0
    Thanked 2 Times in 2 Posts

    Default

    You need to debug the code and find out the error point at which it doesn't provide proper output. Here are some case which you need to debug.

    1. First of all, Check File Path is Ok
    2. File is loaded or not
    3. Data is properly read from file
    4. Check the code applied on file data.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •