2015-04-19 2 views
0

В настоящее время я разрабатываю индивидуальную программу лояльности для своего клиента. Я собираюсь отобразить точки на отдельной вкладке, как это. Программы лояльности> (список клиентов)> (просмотреть свои точки)> (точки редактирования)Prestashop Объект не может быть загружен (или найден)

Когда я нажимаю клиент будет оказывать список точки клиента, но нет никаких проблем с оказанием но отображая следующее сообщение об ошибке ,

Объект не может быть загружен (или найден)

Пожалуйста, помогите мне преодолеть от этой ошибки.

require_once (_PS_MODULE_DIR_.'\loyaltyprogram\classes\LoyaltyClass.php'); 
class AdminLoyaltyController extends AdminController 
{ 

    public $module; 

    public function __construct() 
    { 
     $this->table = 'loyaltyprogram'; 
     $this->className = 'LoyaltyClass'; 
     $this->module = 'loyaltyprogram'; 
     $this->lang = false; 
     $this->bootstrap = true; 
     $this->need_instance = 0; 
     $this->context = Context::getContext(); 
     $this->fields_list = array(
      'id_customer' => array(
       'title' => $this->l('Id'), 
       'width' => 100, 
       'type' => 'text', 
      ), 
      'firstname' => array(
       'title' => $this->l('First Name'), 
       'width' => 440, 
       'type' => 'text' 
      ), 
      'lastname' => array(
       'title' => $this->l('Last Name'), 
       'width' => 440, 
       'type' => 'text' 
      ), 
      'email' => array(
       'title' => $this->l('Email'), 
       'width' => 440, 
       'type' => 'text' 
      ), 
      'point' => array(
       'title' => $this->l('Point'), 
       'width' => 440, 
       'type' => 'text' 
      ) 
     ); 
     $this->identifier = 'id_customer'; 
     if (!Tools::getValue('id_customer')) 
     { 
      $this->_select = 'SUM(a.point) point, b.*'; 
      $this->_join = 'LEFT JOIN `'._DB_PREFIX_.'customer` b ON b.id_customer=a.id_customer'; 
     } 
     $this->bulk_actions = array(
      'delete' => array(
       'text' => $this->l('Delete selected'), 
       'icon' => 'icon-trash', 
       'confirm' => $this->l('Delete selected items?') 
      ) 
     ); 
     parent::__construct(); 
    } 

    public function renderList() 
    { 
     $this->addRowAction('view'); 
     $this->addRowAction('edit'); 
     $this->addRowAction('delete'); 

     return parent::renderList(); 
    } 

    public function renderView() 
    { 
     if (($id = Tools::getValue('id_customer'))) 
     { 

      // Action for list 
      $this->addRowAction('edit'); 
      $this->addRowAction('delete');   


      $this->toolbar_title = 'Loyalty Program > '; 
      $this->fields_list = array(
       'id_loyaltyprogram' => array(
        'title' => $this->l('Id'), 
        'width' => 100, 
        'type' => 'text', 
       ), 
       'id_order' => array(
        'title' => $this->l('Order Id'), 
        'width' => 100, 
        'type' => 'text' 
       ), 
       'point' => array(
        'title' => $this->l('Point'), 
        'width' => 100, 
        'type' => 'text' 
       ), 
       'date' => array(
        'title' => $this->l('Date'), 
        'width' => 200, 
        'type' => 'text' 
       ) 
      ); 
      $this->identifier = 'id_loyaltyprogram'; 
      $this->_where = 'AND a.`id_customer` = '.(int)$id; 
      return parent::renderList(); 
     } 
    } 

} 

LoyaltyClass.php

class LoyaltyClass extends ObjectModel 
{ 

/** @var string Name */ 
public $id_loyaltyprogram; 

/** @var integer */ 
public $id_order; 

/** @var integer */ 
public $point; 
public $date; 

/** 
* @see ObjectModel::$definition 
*/ 
public static $definition = array(
    'table' => 'loyaltyprogram', 
    'primary' => 'id_loyaltyprogram', 
    'multilang' => false, 
    'fields' => array(
     'id_loyaltyprogram' => array('type' => self::TYPE_INT, 'validate' => 'isInt'), 
     'id_order' => array('type' => self::TYPE_INT, 'validate' => 'isInt', 'required' => true), 
     'id_customer' => array('type' => self::TYPE_INT, 'validate' => 'isInt', 'required' => true), 
     'point' => array('type' => self::TYPE_FLOAT, 'validate' => 'isUnsignedFloat', 'required' => true), 
     'date' => array('type' => self::TYPE_STRING, 'validate' => 'isCleanHtml', 'required' => true), 
    ), 
); 

public static function loadLoyaltyProgram() 
{ 
    $result = Db::getInstance()->getRow(' 
     SELECT * 
     FROM `' . _DB_PREFIX_ . 'loyaltyprogram` order_qty 
     ' 
    ); 
    return new LoyaltyClass($result['id_loyaltyprogram']); 
} 

} 
+0

Как файл класса указан и где он находится? – PrestaShopDeveloper

+0

Файл класса с именем loyaltyclass.php и его находится в папке моего класса модулей – Abu

ответ

0
  1. Следующий код не требуется на RenderView()

    $ this-> Таблица = 'loyaltyprogram'; $ this-> className = 'LoyaltyClass'; $ this-> module = 'loyaltyprogram';

  2. Вам необходимо включить файл класса, как:

    require_once; (имя_директории (FILE) '/ ../../классы/LoyaltyClass.php'.)

  3. Вместо того, чтобы новый экземпляр LoyaltyClas вам нужно вызвать метод loadObject(), поскольку он устанавливает $ this-> объект как:

    если (($ OBJ = $ this-> loadObject (правда,))) возвращение;

  4. Если вы не используете $ obj в renderList(), вам не нужно его загружать.

+0

Привет, как вы сказали, я включаю свой класс в свой контроллер лояльности, но все же сталкиваюсь с ошибкой. Проверьте измененный код и класс выше. – Abu

Смежные вопросы