2012-01-19 90 views
0

我在php4中有一個presta模塊。它通過連接到prestashop的數據庫並打印出xml來工作。當試圖上傳到他們的應用程序商店,他們問我做了php5並遵循某些程序。在prestashop中創建一個模塊:error'class Module can not be found'

  • 簡而言之,它只是一個完整的結構代碼,有1個方法可以連接到prestashop數據庫並打印出xml。

所以問題是如何讓它符合prestashop所要求的php5標準。當我嘗試時,我得到這個錯誤。 「類模塊無法找到」

<?php 
include('config/settings.inc.php'); 
$con = mysql_connect(_DB_SERVER_, _DB_USER_, _DB_PASSWD_); 
mysql_select_db(_DB_NAME_); 
$str = '_DB_PREFIX_'; 
$str1 = constant($str); 
$sql = 'SELECT '. 
$str1.'product_lang.name,'. 
$str1.'product.id_product as id,'. 
$str1.'product.quantity,'. 
$str1.'product.price,'. 
$str1.'product.weight,'. 
$str1.'product_lang.description,'. 
$str1.'product_lang.link_rewrite as url,'. 
$str1.'category_lang.name as category,'. 
$str1.'manufacturer.name as manufacturer,'. 
$str1.'image.id_image '. 

'FROM '. 
$str1.'product_lang '. 
'INNER JOIN ' .$str1.'product '. 
'ON ('.$str1.'product_lang.id_product = '.$str1.'product.id_product) '. 
'INNER JOIN ' .$str1.'image '. 
'ON ('.$str1.'image.id_product = '.$str1.'product.id_product) '. 
'INNER JOIN ' .$str1.'manufacturer '. 
'ON ('.$str1.'manufacturer.id_manufacturer = '.$str1.'product.id_manufacturer) '. 
'INNER JOIN ' .$str1.'category_lang '. 
'ON ('.$str1.'category_lang.id_category = '.$str1.'product.id_category_default) '. 
//'WHERE '.$str1.'product_lang.id_lang = 1 AND '.$str1.'category_lang.id_lang = 1'; 
    'WHERE '.$str1.'product_lang.id_lang = 1'; 
    $result = mysql_query($sql); 

    header("Content-Type: text/xml; charset=ISO-8859-1"); 
    $output = '<?xml version="1.0" encoding="utf-8"?> 
    <products>'; 
    while($row = mysql_fetch_assoc($result)): 
    //echo "<br><br><b>text:</b>".$text = addslashes($text); 
    $text = str_replace(chr(145), "\'", $text); 
$output .= ' 
<product> 
    <id>'. $row['id'].'</id> 
    <name><![CDATA['.$name.']]></name> 
    <description><![CDATA['.$text.']]></description> 
      <image><![CDATA['. 'http://'.$_SERVER['HTTP_HOST'].__PS_BASE_URI__.'img/p/'.$row['id'].'-'.$row['id_image'].'.jpg' .']]></image> 
     <quantity><![CDATA['. $row['quantity'] .']]></quantity> 
     <price><![CDATA['. $row['price'] .']]></price> 
     <weight>'. $row['weight'] .'</weight> 
    <category><![CDATA['.$category.']]></category> 
    <manufacturer><![CDATA['. $manufacturer.']]></manufacturer> 
      <url><![CDATA['.'http://'.$_SERVER['HTTP_HOST'].'/product.php?id_product='.$row['id'].']]></url> 

    </product>'; 
endwhile; 

print $output .= ' 
</products>'; 

這是編碼的我需要的Prestashop遵循

<?php 
     //Your class must have the same name than this file. 

     class module_name extends Module 
     { 
     public function __construct() 
     { 

    //Name of your module. It must have the same name than the class 
    $this->name = 'module_name'; 

    //You must choose an existing tab amongst the ones that are available 
    $this->tab = 'You choose'; 

    //The version of your module. Do not forget to increment the version for each modification 
    $this->version = '1.0'; 

    //The constructor must be called after the name has been set, but before you try to use any functions like $this->l() 
    parent::__construct(); 

    //Name displayed in the module list 
    $this->displayName = $this->l('Display Name on Back Office'); 

    //Short description displayed in the module list 
    $this->description = $this->l('Description On Back Office');  
} 

//You must implement the following methods if your module need to create a table, add configuration variables, or hook itself somewhere. 
//------------------------------- 
public function install() 
{ 
    return parent::install(); 
} 

public function uninstall() 
{ 
    return parent::install(); 
} 
//------------------------------- 

//Display Configuration page of your module. 
public function getContent() 
{ 
    return 'Hello World!'; 
} 

    } 

?> 

回答

1

我前段時間寫了一系列的文章寫作模塊的Prestashop的proceedure,你可能找到有幫助的:Writing your own Prestashop Module Part 1

這些描述了基本的體系結構以及模塊的典型實現方式。

雖然你希望這個腳本是獨立的而不是從Backoffice管理界面中生成的xml,如果是這種情況,那麼這不會被Prestashop定義歸類爲「模塊」,這就是它被拒絕的原因。

無論您是在編寫獨立腳本還是模塊,還需要使用各種Prestashop API調用來檢索產品信息,而不僅僅是在原始數據庫表上執行sql。原因是原始的sql不會考慮諸如語言,稅收或貨幣轉換之類的因素。

的如何獲取所有產品,並從的Prestashop模塊內打印有關它們的詳細信息的一個例子是:

global $cookie; 

$products = Product::getProducts($cookie->id_lang, 0, NULL,'id_product', 'ASC'); 
foreach ($products AS product) { 
    echo 'title: '. $product['name']; 
    echo 'weight: '. $product['weight']; 
    // .. etc. 
} 

所有最好與你的Prestashop編程!

+0

我很樂意看到它並提供幫助,只需給我發一條消息,如果您仍在處理此問題,我們可以對其進行排序。 –

+0

好的。將它貼在您的牆上http://www.ecartservice.net/free-prestashop-modules/prestashop-google-product-search/comment-page-1/#comment-14877 – karto

0

你在這裏需要的是你的代碼獨立。要做到這一點,你需要自己初始化prestashop。這可能是最可靠的方法。

if (!defined('_PS_VERSION_')) { 
    require_once '../../config/config.inc.php'; 
    require_once '../../init.php'; 
} 

這將允許您使用module類,以及其他任何需要從你使用的Prestashop框架。

相關問題