Неправильный экспорт данных в php - PullRequest
0 голосов
/ 20 марта 2019

Мой код здесь

public function exportCsvAction()  
{  
    $fileName   = 'portfolios.csv';  
    $content    = $this->getLayout()->createBlock('adminhtml/catalog_product_grid');  
    $this->_prepareDownloadResponse($fileName, $content->getCsvFile());  
}
public function massExportAction()
{
    $productIds = $this->getRequest()->getParam('product');
    if (!is_array($productIds)) {
        $this->_getSession()->addError($this->__('Please select product(s).'));
        $this->_redirect('*/*/index');
    }
    else {
        //write headers to the csv file
        $content = "Id,android_live_url,approved_by_seo,blackberry_live_url,business_goal,busines_benefits,casestudy_title,challenges,client_gmailid,client_name,client_other_contacts,client_overview,client_skypeid,client_telephone,client_testimonial,country_of_manufacture,description,design_features,development_url,home_development_website_list,ios_live_url,live_url,main_technology,methodology,name,other_features,product_scrrenshot,product_solution,project_enrolment,project_nature_categories,project_pms_name,project_status,project_type,solutions,special_comments,summary,technologies_used,technology,windows_live_url\n";
        try {
            foreach ($productIds as $productId) {
                $product = Mage::getSingleton('catalog/product')->load($productId);
                /*$content .= "\"{$product->getId()}\",\"{$product->getName()}\",\"{$product->getProductUrl()}\",\"{$product->getSku()}\"\n";*/

                $content .="\"{$product->getId()}\",\"{$product->getAndroidLiveUrl()}\",\"{$product->getApprovedBySeo()}\",\"{$product->getBlackberryLiveUrl()}\",\"{$product->getBusinessGoal()}\",\"{$product->getBusinesBenefits()}\",\"{$product->getCasestudyTitle()}\",\"{$product->getChallenges()}\",\"{$product->getClientGmailid()}\",\"{$product->getClientName()}\",\"{$product->getClientOtherContacts()}\",\"{$product->getClientOverview()}\",\"{$product->getClientSkypeid()}\",\"{$product->getClientTelephone()}\",\"{$product->getClientTestimonial()}\",\"{$product->getCountryOfManufacture()}\",\"{$product->getDescription()}\",\"{$product->getDesignFeatures()}\",\"{$product->getDevelopmentUrl()}\",\"{$product->getHomeDevelopmentWebsiteList()}\",\"{$product->getIosLiveUrl()}\",\"{$product->getLiveUrl()}\",\"{$product->getMainTechnology()}\",\"{$product->getMethodology()}\",\"{$product->getName()}\",\"{$product->getOtherFeatures()}\",\"{$product->getProductScrrenshot()}\",\"{$product->getProductSolution()}\",\"{$product->getProjectEnrolment()}\",\"{$product->getProjectNatureCategories()}\",\"{$product->getProjectPmsName()}\",\"{$product->getProjectStatus()}\",\"{$product->getProjectType()}\",\"{$product->getSolutions()}\",\"{$product->getSpecialComments()}\",\"{$product->getSummary()}\",\"{$product->getTechnologiesUsed()}\",\"{$product->getTechnology()}\",\"{$product->getWindowsLiveUrl()}\"\n";
            }
        } catch (Exception $e) {
            $this->_getSession()->addError($e->getMessage());
            $this->_redirect('*/*/index');
        }
        $this->_prepareDownloadResponse('export.csv', $content, 'text/csv');
    }

}

Когда я экспортировал файл CSV, я получил несоответствие данных.Потому что это происходит в двойных кавычках (") в данных.

Пожалуйста, смотрите скриншот файла CSV .

...