Prestashop 1.6,我的课程在其他模块中不起作用

我创建了一个模块,该模块中有一个类扩展到ObjectModel: 模块名称:

<?php
if (!defined('_PS_VERSION_'))
    exit;

class StoreOrder extends ObjectModel
{
    public $id_store_order;
    public $id_customer;
    public $nature_piece;
    public $client_code;
    public $internal_reference;
    public $store_code;
    public $store_name;
    public $ticket_date;
    public $custumer_name;
    public $ticket_number;
    public $product_number;
    public $total_ht;
    public $total_ttc;
    public $payment_mode;

    public static $definition = array(
        'table' => 'ps_store_order','primary' => 'id_store_order','fields' => array(
            'id_store_order' => array('type' => self::TYPE_INT),'id_customer' => array('type' => self::TYPE_INT),'store_code' => array('type' => self::TYPE_STRING),'store_name' => array('type' => self::TYPE_STRING),'ticket_date' =>    array('type' => self::TYPE_STRING),'ticket_number' =>  array('type' => self::TYPE_STRING),'product_number' => array('type' => self::TYPE_STRING),'total_ht' => array('type' => self::TYPE_STRING),'total_ttc' => array('type' => self::TYPE_STRING),'payment_mode' => array('type' => self::TYPE_STRING),)
    );

    public function __construct()
  {
    parent::__construct();
    }

    public static function getByIdCustomer($id_customer) {
        $sql = "SELECT * FROM `ps_store_order` WHERE `id_customer` = ".$id_customer;
        $result = Db::getInstance()->executeS($sql);
        return $result;
    }


}

但是,如果我将此类包含在其他模块中以使用它,则该类将在未定义的“ _PS_VERSION_”步骤中阻塞,并且我将删除它不返回任何条件的条件(代码是库存的,我不知道为什么)>

谢谢你。

hell_liul 回答:Prestashop 1.6,我的课程在其他模块中不起作用

  • 您不应在对象模型上检查“ _PS_VERSION _”
  • 您不应在对象模型上为表名添加“ ps_”前缀:

'table' => 'store_order',

尝试一下:

include_once _PS_MODULE_DIR_ . 'path-to-your-model';
dd(StoreOrder::getByIdCustomer(2));

也建议对($ id_customer)使用(int):

$sql = "SELECT * FROM `ps_store_order` WHERE `id_customer` = " . (int)$id_customer;
本文链接:https://www.f2er.com/3111326.html

大家都在问