【问题标题】:How to get all products without Context Prestashop如何在没有 Context Prestashop 的情况下获取所有产品
【发布时间】:2017-05-23 22:24:45
【问题描述】:

我正在尝试编写一个 cron 脚本来自动化我的模块,但我在使用 Prestashop 1.6 Core 时遇到了一些错误。

我想从商店中检索所有具有核心功能的产品。在 Prestashop 后台工作正常,但是当我只想使用它执行 cron 时,我在上下文中遇到错误:“尝试获取非对象的属性”

我检索所有产品的功能是这样的:

    public static function getAllProducts() {
    $lang = (int)Configuration::get('PS_LANG_DEFAULT');
    return (Product::getProducts($lang, 0, 0, 'id_product', 'DESC', false, false, null));
}

我的 cron_script.php 是这样的:

include(dirname(__FILE__).'/../../config/config.inc.php');
require_once('mymodule.php');

$products = MyModule::getAllProducts();

是否有任何方法可以在不使用上下文且不使用 SQL 语句的情况下检索所有产品?

谢谢

【问题讨论】:

    标签: php cron prestashop


    【解决方案1】:

    试试:

      return (Product::getProducts($lang, 0, 0, 'id_product', 'DESC');
    

    问候

    【讨论】:

    • 这个函数的第一行是if (!$context) {$context = Context::getContext();},所以它需要和使用上下文数据。
    • 确实如此。我正在尝试使用默认值,但什么也没有
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-01-16
    • 2022-06-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-09-12
    • 1970-01-01
    相关资源
    最近更新 更多