2013-02-07 2 views
1

Prestashop 1.5에서는 카테고리를 국가 세트로 제한해야합니다. 이 제한은 해당 카테고리에 속한 제품의 배송을 금지합니다. 따라서 사용자는 여전히 제품을 볼 수는 있지만 구매할 수는 없습니다.Prestashop 1.5에서 특정 국가의 카테고리 제한

이상적으로는 카테고리 편집 페이지 내에 국가 목록 (모듈 -> 지불 페이지 (AdminPayment)과 같은 체크 박스 스타일)을 삽입하는 모듈을 개발하고 싶었지만 할 수 없었습니다. 그래서.

renderForm() 함수 내에 다음 코드를 붙여 넣을 수없는 이유는 무엇입니까? 내가 그렇게 할 경우 만 설명 ... 볼 수

array(
    'items' =>Country::getCountries(Context::getContext()->language->id), 
    'title' => $this->l('Country restrictions'), 
    'desc' => $this->l('Please mark the checkbox(es) for the country or countries for which you want to block the shipping.'), 
    'name_id' => 'country', 
    'identifier' => 'id_country', 
    'icon' => 'world', 
    ), 

편집 : 나는 이러한 값을 절약 할 수 있습니다 지금

array(
    'type' => 'checkbox', 
    'label' => $this->l('Restricted Countries').':', 
    'class' => 'sel_country', 
    'name' => 'restricted_countries', 
    'values' => array(
     'query' => Country::getCountries(Context::getContext()->language->id), 
     'id' => 'id_country', 
      'name' => 'name' 
    ), 
    'desc' => $this->l('Mark all the countries you want to block the selling to. The restrictions will always be applied to every subcategory as well') 
      ), 

: 나는 일 국가 목록을 얻을 수 있었다 "submitAddcategory"값이 postProcess 함수에서 제출되고 거기에 삽입 쿼리를 실행하는지 확인합니다. 마찬가지로 데이터베이스에서 차단 된 국가의 ID를로드 할 수도 있지만 국가 목록에서 각 선택 상자를 어떻게 체크 할 수 있습니까?

처음 생각한 "빠르고 지저분한"아이디어는 document.ready() 내에서 jQuery 선택기를 사용하는 것이었지만 코드는 다른 모든 것보다 먼저 삽입되기 때문에 jQuery가로드되지 않았기 때문에 코드가 삽입되지 않습니다. 아직.

어떻게이 작업을 수행 할 수 있습니까?

건배

답변

1

는 I 바로 renderForm() 함수가 끝나기 전에 다음 코드를 사용하여 해결. 슬프게도 내가 그 존재를 알지 못했던만큼, 피어스 레스트은 $ this-> fields_value였습니다.

public function getRestrictedCountries($obj) 
    { 
     // Loading blacklisted countries 
     $country = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS(' 
      SELECT DISTINCT id_country 
      FROM `'._DB_PREFIX_.'category_country_restriction` 
      WHERE id_category = ' . (int)Tools::getValue('id_category') . ';'); 

     $blacklisted_countries = array(); 

     if (is_array($country)) 
      foreach ($country as $cnt) 
       $blacklisted_countries[] = $cnt['id_country']; 

     // Global country list 
     $c_todos = Country::getCountries(Context::getContext()->language->id); 

     // Crossmatching everything 
     foreach ($c_todos as $c) 
      $this->fields_value['restricted_countries_'.$c['id_country']] = Tools::getValue('restricted_countries_'.$c['id_country'], (in_array($c['id_country'], $blacklisted_countries))); 
    } 

PS : 내가 읽는 오전 표는 기본적으로 '카테고리'와 '국가'

사이의 연관 테이블
관련 문제