Ond*_*něk -1 prestashop prestashop-1.6
有人可以指导我查看如何在 PrestaShop 1.6+ 中创建自定义 XML 提要的文档。我搜索了官方文档,但没有找到我需要的。
任务很简单 - 创建自定义 XML 提要,其他电子商店可以从中获取产品。
您可以获得产品列表,getProducts()然后使用SimpleXMLElement生成 xml。
include('config/config.inc.php');
include('init.php');
$productObj = new Product();
$products = $productObj -> getProducts($id_lang, 0, 0, 'id_product', 'DESC' );
$xml = new SimpleXMLElement('<xml/>');
foreach($products as $product) {
$productXml = $xml->addChild('product');
$productXml->addChild('id', $product->id);
$productXml->addChild('name', $product->name);
$productXml->addChild('description', $product->description);
}
Header('Content-type: text/xml');
print($xml->asXML());
Run Code Online (Sandbox Code Playgroud)
输出将是..
<xml>
<product>
<id>ID</id>
<name>NAME</name>
<description>DESCRIPTION</description>
</product>
<product>
<id>ID</id>
<name>NAME</name>
<description>DESCRIPTION</description>
</product>
...
...
...
</xml>
Run Code Online (Sandbox Code Playgroud)
请参阅getProducts()classes/Product.php 中的函数描述以了解参数。
/**
* Get all available products
*
* @param integer $id_lang Language id
* @param integer $start Start number
* @param integer $limit Number of products to return
* @param string $order_by Field for ordering
* @param string $order_way Way for ordering (ASC or DESC)
* @return array Products details
*/
public static function getProducts($id_lang, $start, $limit, $order_by, $order_way, $id_category = false,
$only_active = false, Context $context = null) {...}
Run Code Online (Sandbox Code Playgroud)
您可以将 xml.php 文件放置在您的 prestashop 根目录中,并且可以通过访问或发送请求来访问此 xml yourdomain.com/xml.php。
或者,如果您想为 xml 创建模块,则需要将代码放在前端控制器中,然后您可以通过访问 .xml 来访问 xml 文件yourdomain.com/index.php?fc=module&module=<ModuleName>&controller=<XMLFunction>。阅读Prestashop 文档以了解有关 prestashop 模块结构的更多信息。