2013-06-01 2 views
0

나는 원산지 국가의 고객을 열거하는 prestashop 용 탭을 쓰고 있습니다. 지금까지는 괜찮 았지만 쿼리 나 테이블을 국가별로 필터링하여 다음과 같이 추가하고 싶습니다. WHERE iso_code = 'IT' 분명히 prestashop은 허용하지 않습니다. 어떻게 할 수 있습니까? 이 내 코드입니다 : 여기Prestashop Admin Tab - Clausole이 작동하지 않는 곳

<?php 
include_once(PS_ADMIN_DIR.'/../classes/AdminTab.php'); 
class AdminCustomersCountries extends AdminTab 
{ 
    public function __construct() 
    { 
     $this->table = 'customer'; 
     $this->className = 'Customer'; 
     $this->lang = false; 
     $this->edit = false; 
     $this->view = true; 
     $this->delete = false; 
     $this->deleted = false; 
     $this->requiredDatabase = true; 

     $this->_select = '(SELECT cy.iso_code FROM ps_address AS addr, ps_country AS cy WHERE addr.id_customer=a.id_customer AND addr.id_country=cy.id_country) AS iso_code'; 
     $this->fieldsDisplay = array(
     'id_customer' => array('title' => $this->l('ID'), 'align' => 'center', 'width' => 25), 
     'lastname' => array('title' => $this->l('Last Name'), 'width' => 80), 
     'firstname' => array('title' => $this->l('First name'), 'width' => 60), 
     'email' => array('title' => $this->l('E-mail address'), 'width' => 120, 'maxlength' => 19), 
     'active' => array('title' => $this->l('Enabled'), 'width' => 25, 'align' => 'center', 'active' => 'status', 'type' => 'bool', 'orderby' => false), 
     'newsletter' => array('title' => $this->l('News.'), 'width' => 25, 'align' => 'center', 'type' => 'bool', 'callback' => 'printNewsIcon', 'orderby' => false), 
     'iso_code' => array('title' => "Nazione", 'width' => 60, 'orderby'=>false, 'search'=>false)); 

     $this->optionTitle = "Prova"; 
     parent::__construct(); 
    } 

    public function postProcess() 
    { 
     // This function is executed when the Submit button is clicked 
     // Use it to store the value of text fields in the database 

     parent::postProcess(); 
    } 

    public function displayForm($token=NULL) 
    { 
     // This function can be used to create a form with text fields 
    } 
} 

?> 

그러나, 나는 아무 결과, WHERE 절을 추가하려고 :

<?php 
include_once(PS_ADMIN_DIR.'/../classes/AdminTab.php'); 
class AdminCustomersCountries extends AdminTab 
{ 
    public function __construct() 
    { 
     $this->table = 'customer'; 
     $this->className = 'Customer'; 
     $this->lang = false; 
     $this->edit = false; 
     $this->view = true; 
     $this->delete = false; 
     $this->deleted = false; 
     $this->requiredDatabase = true; 

     $this->_select = '(SELECT cy.iso_code FROM ps_address AS addr, ps_country AS cy WHERE addr.id_customer=a.id_customer AND addr.id_country=cy.id_country AND cy.iso_code='IT') AS iso_code'; 
     $this->fieldsDisplay = array(
     'id_customer' => array('title' => $this->l('ID'), 'align' => 'center', 'width' => 25), 
     'lastname' => array('title' => $this->l('Last Name'), 'width' => 80), 
     'firstname' => array('title' => $this->l('First name'), 'width' => 60), 
     'email' => array('title' => $this->l('E-mail address'), 'width' => 120, 'maxlength' => 19), 
     'active' => array('title' => $this->l('Enabled'), 'width' => 25, 'align' => 'center', 'active' => 'status', 'type' => 'bool', 'orderby' => false), 
     'newsletter' => array('title' => $this->l('News.'), 'width' => 25, 'align' => 'center', 'type' => 'bool', 'callback' => 'printNewsIcon', 'orderby' => false), 
     'iso_code' => array('title' => "Nazione", 'width' => 60, 'orderby'=>false, 'search'=>false)); 

     $this->optionTitle = "Prova"; 
     parent::__construct(); 
    } 

    public function postProcess() 
    { 
     // This function is executed when the Submit button is clicked 
     // Use it to store the value of text fields in the database 

     parent::postProcess(); 
    } 

    public function displayForm($token=NULL) 
    { 
     // This function can be used to create a form with text fields 
    } 
} 

?> 

답변

0

라인 IT는 'IT'를 사용 $this->_select = '(SELECT cy.iso_code FROM ps_address AS addr, ps_country AS cy WHERE addr.id_customer=a.id_customer AND addr.id_country=cy.id_country AND cy.iso_code='IT') AS iso_code'; 검색합니다.

아포스트로피가 이스케이프되지 않기 때문에 PHP가 IT를 읽지 않습니다. 나는 AND cy.iso_code=\'IT\')을 사용해야한다고 생각한다.

+1

죄송합니다. 게시 된 두 번째 코드를 편집 할 때 작성 오류가 발생했습니다. 그러나 cy.iso_code = \ 'IT \'로 시도했지만 작동하지 않습니다 .. – user2443268

+0

흠 ... 어쩌면 그것은'선택 cy.iso_code FROM ps_address'입니다. 늘어나는만큼 내가 잘못된 테이블에서 iso_code를 요청하고 있다고 말할 수 있습니다. SELECT SQL_CALC_FOUND_ROWS \t \t \t : – Aram

+0

음에는, 시스템은 나에게, 나는 절 또는 PrestaShop 버전 기능 – user2443268

1

하위 쿼리를 사용하는 이유가 확실하지 않지만 PS AdminTab 클래스가 제공하는 다른 두 가지 옵션이 있습니다.

1) 여기서 추가 당신을 위해 기능을 조인 PS도 제공하고

처럼 쓸 수 있습니다 : 당신은 또한 필요할 때마다 where 절, 당신이

$this->_where = 'your condition here'; 

2) 조인 아래처럼 쓸 수 있습니다

$this->_join = 'write down all your joins here like normal queries'; 
$this->_join = 'write down all your joins here like normal queries'; 

이제 다른 테이블에서 추가 체크 (wheres)로 추가 정보를 얻으려면 다음과 같이하십시오. :

** 참고 : 테이블의 경우 PS는 "a"로 시작하는 별칭을 제공하고 언어 테이블과 같은 추가 테이블이 있으면 b와 함께갑니다. 그래서 여러분은 알맞은 별명을 사용해야 함에도 불구하고 _select와 _에서 조인을해야합니다. **

$this->_select = 'all your additional fields from the tables you need. Those tables should be joined in the _join query.'; 

$this->_join = 'All your joins here with correct aliases, as these aliases are used in _select query and in _where'; 

$this->_where = 'your where clauses here.'; 

여러분의 질문을 수정하는 데 도움이되기를 바랍니다.

감사합니다.

+0

prestashop 하위 쿼리 대신 사용자 지정 쿼리를 사용할 수 있습니까? 내가 어떻게 할 수 있니? prestashop 탭 쿼리에 대한 설명서는 어디에서 찾을 수 있습니까? – user2443268

+0

'WHERE'라는 키워드를 써야합니까? 같은 일을하고 있지만 오류가 발생하기 때문에 묻습니다 : 나쁜 SQL 쿼리. 나는이 행을 추가했다. $ this -> _ where = 'a.id_customer! = 0'; '또한 $ this -> _ where'where a.id_customer! = 0 '; 둘 다 작동하지 않습니다 – VeeK

+0

SQL 쿼리를 볼 수 있도록 전체 오류 메시지를 공유하십시오 –

관련 문제