2014-02-11 32 views

回答

0

我已经在我的自定义magneto API中创建了这个功能。它将生成带有选定产品列的sqlite数据库。您可以将它与您的magento一起使用并据此设置路径。 我很高兴在这里分享。如果您可以改进或想用我的代码向我推荐,那么欢迎您。

感谢所有提前。

/* **功能来创建产品的SQLite数据库 * */

public function sqlitedb() 
    { 
     $root= dirname(Mage::getRoot()); 
     $path=$root.'/marcodeappdb'; 
     if (!file_exists($path)) { 
      mkdir($path, 0777, true); 
     }    
     unlink($path.'/marcodeapp.zip'); 
     $database = new sqlite3($path.'/marcodeapp.sqlite');  

     $query = 'CREATE TABLE Products '.'(Sku TEXT, Name TEXT, Price INTEGER,ShortD TEXT,Description TEXT,Image TEXT,Categories TEXT)'; 
     $database->exec($query); 

      $collection=Mage::getResourceModel('catalog/product_collection'); 
      $collection->addAttributeToSelect('*'); 
      //pr($collection); 
     foreach($collection as $product){ 
       $sku=$product->sku; 
       $name=$product->getName(); 
       $price=$product->getPrice(); 
       $shortd=$product->getDescription(); 
       $description=$product->getDescription(); 
       $image=$product->getImageUrl(); 
       //categoryids 
       $catids=$product->getCategoryIds(); 
       $productcatname=array(); 
       foreach($catids as $catid){ 
         $category = Mage::getModel('catalog/category')->load($catid); 
        $productcatname[]=$category->getName(); 

       } 
       $productcate=implode(',',$productcatname); 

      $query ="INSERT INTO Products (Sku, Name, Price,ShortD,Description,Image,Categories) VALUES ('$sku', '$name', '$price','$shortd','$description','$image','$productcate');"; 
      $database->exec($query); 
      unset($query); 
      unset($sku); 
      unset($name);unset($price);unset($shortd);unset($description);unset($image); 
      unset($productcate);unset($productcatname); 
      } 
     $database->close(); 

     $files_to_zip = array($path.'/marcodeapp.sqlite');  
     $result = $this->create_zip($files_to_zip,$path.'/marcodeapp.zip'); 
     unlink($path.'/marcodeapp.sqlite'); 

     return 'http://mercode.com.br/MERCODE/marcodeappdb/marcodeapp.zip';   
    }