Jump to content

Wyswietlanie pod kategori


oidnus

Recommended Posts

Jest jakaś zmienna funkcja która w plikach z szablonami przechowuje strukturę tabel. Potrzebuje cos takiego w stylu

 

$categories = getSubcategory(ID);

foreach ($categories as $category){

//tutaj robię sobie operacje do wyswietlania które potrzebuje

}

Link to comment
Share on other sites

Oczywiście myślałem o obiektach/tablicach ale już widać za długo walczę z sklepem.

 

Niestety twoje rozwiązanie nie działa zawsze zwraca null, za piękne by to było rozwiązanie żeby było prawdziwe. Podejrzewam że jedynym rozwiązaniem będzie stworzenie modułu do menu wczytanie struktury kategorii takiego jak potrzebuje i dopiero ich obrobienie.

Link to comment
Share on other sites

chyab nie bardzo zrozumiałem czego potrzebujesz.

Zwykle aby wyświetlić zawartość tablicy / obiektu w smarty używa się modyfikatora: |print_r lub |var_dump (przynajmniej ja tak robię;)

ale aby wyświetlić zawartość tablicy / obiektu - najpierw musi w nim coś być, inaczej wywala NULL / nic

Link to comment
Share on other sites

najlepiej jest podglądnąć kontrolery / klasy np. dla kategorii difinicja obiektu wygląda tak:

/**
 * @see ObjectModel::$definition
 */
public static $definition = array(
 'table' => 'category',
 'primary' => 'id_category',
 'multilang' => true,
 'multilang_shop' => true,
 'fields' => array(
  'nleft' =>	 array('type' => self::TYPE_INT, 'validate' => 'isUnsignedInt'),
  'nright' =>    array('type' => self::TYPE_INT, 'validate' => 'isUnsignedInt'),
  'level_depth' =>   array('type' => self::TYPE_INT, 'validate' => 'isUnsignedInt'),
  'active' =>    array('type' => self::TYPE_BOOL, 'validate' => 'isBool', 'required' => true),
  'id_parent' =>    array('type' => self::TYPE_INT, 'validate' => 'isUnsignedInt'),
  'id_shop_default' =>  array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId'),
  'is_root_category' =>  array('type' => self::TYPE_BOOL, 'validate' => 'isBool'),
  'position' =>    array('type' => self::TYPE_INT),
  'date_add' =>    array('type' => self::TYPE_DATE, 'validate' => 'isDate'),
  'date_upd' =>    array('type' => self::TYPE_DATE, 'validate' => 'isDate'),
  // Lang fields
  'name' =>	 array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isCatalogName', 'required' => true, 'size' => 64),
  'link_rewrite' =>   array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isLinkRewrite', 'required' => true, 'size' => 64),
  'description' =>   array('type' => self::TYPE_HTML, 'lang' => true, 'validate' => 'isString'),
  'meta_title' =>   array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isGenericName', 'size' => 128),
  'meta_description' =>  array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isGenericName', 'size' => 255),
  'meta_keywords' =>   array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isGenericName', 'size' => 255),
 ),
);

 

dodatkowo w klasie masz wyszczególnione pola:

 

public $id;
/** @var integer category ID */
public $id_category;
/** @var string Name */
public $name;
/** @var boolean Status for display */
public $active = 1;
/** @var  integer category position */
public $position;
/** @var string Description */
public $description;
/** @var integer Parent category ID */
public $id_parent;
/** @var integer default Category id */
public $id_category_default;
/** @var integer Parents number */
public $level_depth;
/** @var integer Nested tree model "left" value */
public $nleft;
/** @var integer Nested tree model "right" value */
public $nright;
/** @var string string used in rewrited URL */
public $link_rewrite;
/** @var string Meta title */
public $meta_title;
/** @var string Meta keywords */
public $meta_keywords;
/** @var string Meta description */
public $meta_description;
/** @var string Object creation date */
public $date_add;
/** @var string Object last modification date */
public $date_upd;
/** @var boolean is Category Root */
public $is_root_category;
/** @var integer */
public $id_shop_default;
public $groupBox;

 

ale to się sprawdza tylko gdy tworzysz obiekt metodą new Category(ID)

 

zwykle zawartość obiektów / tablic zależy od tego co masz w return danej funkcji... niestety ;)

Link to comment
Share on other sites

Wpisz sobie {debug} na dole footer.tpl na przykład i zobaczysz jakie zmienne masz dostępne na jakiej stronie.

 

Jeżeli chcesz mieć dostęp do wszystkich kategorii w całym sklepie to najefektywniej jest nadpisać FrontController i dać sobie wyciąganie ich do init(), oczywiście jeżeli nie masz ich dużo bo jeśli jest ich dużo to powinieneś już to bardziej optymalizować i wyciągać tam gdzie naprawdę tego potrzebujesz, a najlepiej dodatkowo trzymać w cache.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...