Ñïèñîê òîâàðîâ â êàòåãîðèè ShopOS #

Ñïèñîê òîâàðîâ â êàòåãîðèè ShopOS

Íåìíîãî òåîðèè:
http://www.getinfo.ru/article610.html - êðóòàÿ ñòàòüÿ!
http://phpclub.ru/detail/article/db_tree

Ïî òîïèêó ïîíÿòíî, ÷òî îí ïîñâÿù¸í èìåííî äâèãó ShopOS. Êëàññíûé, â áåñïëàòíîé ñáîðêå îí èäåò áåç ïî÷òû (ôóíêöèÿ óìåëî óäàëåíà), íî èìåÿ ãóãë è ñíîðîâêó ìîæíî äîïèëèòü åãî, ÷òî áû îí çàðàáîòàë êàê ïîëíîôóíêöèîíàëüíûé ìàãàçèí÷èê. Äàëüøå î êàòåãîðèÿõ.

Äëÿ íà÷àëî íóæíî áûëî ïîëó÷èòü âîò òàêîå ìåíþ:
Ñïèñîê òîâàðîâ â êàòåãîðèè ShopOS

×òî áû ïðè íàæàòèè íà ãëàâíóþ êàòåãîðèþ âûïàäàë ñïèñîê òîâàðîâ. Íå äîëãî ìó÷àÿñü îòïèñàë íà îôèöèàëüíîì ôîðóìå . Óâû îòâåòîâ íå ïîëó÷èë, ãîòîâûõ ðåøåíèé íåò. Ïîíÿë, ÷òî ïðèä¸òñÿ ñàìîìó.

Ñ ×ÏÓ (âñòàâèòü â index.html âàøåãî øàáëîíà):

            {php}        
            $sql = "SELECT cat.categories_id, cd.categories_name FROM vip_categories cat, vip_categories_description cd WHERE cat.categories_status = '1' AND cd.categories_id = cat.categories_id";
            $sql = osDBquery($sql);
            while ($row = os_db_fetch_array($sql)) {
                    $menu[$row['categories_id']] = $row['categories_name'];
            }
            foreach ($menu as $CatId => $CatName )
            {
                echo "
  • ".$CatName."";
                echo "
      ";
                      $query = "SELECT * FROM
                          vip_products p,
                          vip_products_description pd,
                          vip_products_to_categories p2c,
                          vip_categories c
                      WHERE
                          c.categories_status='1'
                          and p.products_status = '1'
                          and p.products_id = p2c.products_id
                          and p.products_id=pd.products_id
                          and p2c.categories_id = '".$CatId."'
                          and c.categories_id = '".$CatId."'
                      ORDER by p.products_date_added";
                      $query = osDBquery($query);
                      while ($row1 = os_db_fetch_array($query)) {
                          echo "
    • ".$row1['products_name']."
    • ";
                      }
                  echo "
  • ";
            }
            {/php}            


Íà âûõîäå:


Îêàçàëîñü ÷òî íåîáõîäèìîñòü â äàííîì ìåíþ îòïàäàåò, íî ïîÿâëÿåòñÿ íîâàÿ!
Ñïèñîê òîâàðîâ â êàòåãîðèè ShopOS

Êëàññ! Òåïåðü åñòü åùå óðîâåíü âëîæåííîñòè.

Ñ ×ÏÓ (âñòàâèòü â index.html âàøåãî øàáëîíà):

    {php}
    $sql = "SELECT cat.categories_id, cat.parent_id, cat.categories_url, cd.categories_name FROM vip_categories cat, vip_categories_description cd WHERE cat.categories_status = '1' AND cd.categories_id = cat.categories_id ORDER BY cat.parent_id, cat.categories_id";
    $sql = osDBquery($sql);
    while ($row = os_db_fetch_array($sql)) {
            $menu[$row['parent_id']][$row['categories_id']] = $row['categories_name'];
    }
    foreach ($menu[0] as $CatId => $CatName )
    {
     echo "
  • ".$CatName."";
     if (isset($menu[$CatId])) {
            echo "
      ";
               foreach ($menu[$CatId] as $ItemId => $ItemName)
               {
                echo "
    • ".$ItemName."";
                echo "
        ";
                        $query = "SELECT * FROM
                                vip_products p,
                                vip_products_description pd,
                                vip_products_to_categories p2c,
                                vip_categories c
                        WHERE
                                c.categories_status='1'
                                and p.products_status = '1'
                                and p.products_id = p2c.products_id
                                and p.products_id=pd.products_id
                                and p2c.categories_id = '".$ItemId."'
                                and c.parent_id = '".$CatId."'
                        ORDER by p.products_date_added";
                        $query = osDBquery($query);
                        while ($row1 = os_db_fetch_array($query)) {
                                echo "
      • ".$row1['products_name']."
      • ";
                        }  
                   echo "
      ";
                echo "
    • ";
               }
              echo "
  • ";
     } else { echo "";}
    }
    {/php}


Íà âûõîäå:



Ìíå ×ÏÓ íå íàäî - ÁÅÇ ×ÏÓ (âñòàâèòü â index.html âàøåãî øàáëîíà):


    {php}
    $sql = "SELECT cat.categories_id, cat.parent_id, cat.categories_url, cd.categories_name FROM vip_categories cat, vip_categories_description cd WHERE cat.categories_status = '1' AND cd.categories_id = cat.categories_id ORDER BY cat.parent_id, cat.categories_id";
    $sql = osDBquery($sql);
    while ($row = os_db_fetch_array($sql)) {
            $menu[$row['parent_id']][$row['categories_id']] = $row['categories_name'];
    }
    foreach ($menu[0] as $CatId => $CatName )
    {
     echo "
  • ".$CatName."";
     if (isset($menu[$CatId])) {
            echo "
      ";
               foreach ($menu[$CatId] as $ItemId => $ItemName)
               {
                echo "
    • ".$ItemName."";
                echo "
        ";
                        $query = "SELECT * FROM
                                vip_products p,
                                vip_products_description pd,
                                vip_products_to_categories p2c,
                                vip_categories c
                        WHERE
                                c.categories_status='1'
                                and p.products_status = '1'
                                and p.products_id = p2c.products_id
                                and p.products_id=pd.products_id
                                and p2c.categories_id = '".$ItemId."'
                                and c.parent_id = '".$CatId."'
                        ORDER by p.products_date_added";
                        $query = osDBquery($query);
                        while ($row1 = os_db_fetch_array($query)) {
                                //echo "
        ";
                                //print_r($row1);
                                //echo "
        ";
                                echo "
      • ".$row1['products_name']."
      • ";
                        }  
                   echo "
      ";
                echo "
    • ";
               }
              echo "
  • ";
     } else { echo "";}
    }
    {/php}


Íà âûõîäå:

Ïîëó÷èëè ÷òî õîòåëè, íà íå ñîâñåì òàê. Òåïåðü ÿ íå ìîãó ïîïàñòü â ðàçäåë ÊÀÒÅÃÎÐÈÈ, îí òî íå êëèêàáåëüíûé (ÿ èñïîëüçóþ ÿâà ìåíþ ïðè êëèêå íà êàòåãîðèþ âûïàäàåò âëîæåííûé UL), à ýòî ñóùåñòâåííî è â ÒÇ ïðîïèñàíî.

Ïîýòîìó ýòîò âàðèàíò ìíå íå ïîäõîäèò, ñîâñåì. Áóäåì ðàáîòàòü ñ {$box_CATEGORIES}.

Èäåì â íàø_ñàéò\themes\íàø_øàáëîí\source\inc\show_category.inc.php. Ïðîâåðÿåì ÷òî áû ïàðàìåòð $MaxLevel ðàâåí áûë 1, ýòî çíà÷èò, ÷òî ïî óìîë÷àíèþ áóäåò ïîêàçûâàòüñÿ 1 óðîâåíü âëîæåííîñòè.
 òîì æå ôàéëèêå íàõîäèì:
if ($old_level > $level) {

è ïîñëå âñòàâëÿåì:
                        if ( isset($GLOBALS['cPath']) ) {
                            if ( !strpos($GLOBALS['cPath'], "_")===false ) {
                            $path = explode('_',$GLOBALS['cPath']);
                                $query = "SELECT * FROM
                                    vip_products p,
                                    vip_products_description pd,
                                    vip_products_to_categories p2c,
                                    vip_categories c
                                WHERE
                                    c.categories_status='1'
                                    and p.products_status = '1'
                                    and p.products_id = p2c.products_id
                                    and p.products_id=pd.products_id
                                    and p2c.categories_id = '".$path[1]."'
                                    and c.parent_id = '".$path[0]."'
                                ORDER by p.products_date_added";
                                $query = osDBquery($query);
                                $categories_string .= "
    ";
                                    while ($row1 = os_db_fetch_array($query)) {
                                        $categories_string .= "
  • ".$row1['products_name']."
  • ";
                                    }      
                                    $categories_string .= "
";
                            }
                        }

Èòîãî: åñëè åñòü ïàðàìåòð cPath (îí ïîêàçûâàåò êàòåãîðèþ òåêóùóþ), òî ñìîòðèì âëîæåííàÿ îíà, åñëè äà, òî ðàçáèâàåì è ïîëó÷àåì àéäè êàòåãîðèè è ïîäêàòåãîðèè. À äàëüøå çàïðîñ - ðèñóåì ñïèñîê.
Ñïèñîê òîâàðîâ â êàòåãîðèè ShopOS

Òåïåðü, êîãäà âû íàæèìàåòå íà ïîäêàòåãîðèþ âûïàäàåò åùå è ñïèñîê òîâàðîâ. Îïòèìèçèðóéòå è êîâûðÿéòå -) Äà è íå çàáóäüòå â êîäå ïîìåíÿòü ïðåôèêñ ÁÄ íà ñâîé.