Forum

Thread tagged as: Question, Problem, Shop

Current category/subcategory

I'm using

                <?php 

                 PerchSystem::set_var('current_category', perch_get('cat'));

                 perch_categories();
                ?>

and

<perch:before>
    <h4 class="hide-show">Kategorie</h4>
    <ul></perch:before>
<li class="catDepth<perch:category id="catDepth" type="hidden" />">
        <a href="/shop/<perch:category id="catPath" type="hidden"/>" 
       <perch:if id="catSlug" match="eq" value="{current_category}"> class="selected"  
       </perch:if> 
        title="<perch:category id="catTitle" label="Tytuł kategorii" required="true"/>" ><perch:category id="catTitle" type="smarttext" label="Title" required="true" /></a>
    <perch:category id="catSlug" type="slug" for="catTitle" suppress="true" />
    <perch:category id="desc" type="textarea" label="Description" editor="markitup" markdown="true" size="s" suppress="true"  />
</li>
<perch:after></ul></perch:after>

to get current category. It works fine for categories (depth 1) but it does not work for subcategories. I guess the url in subcategories does not match cutSlug, but I have no idea why.

showall

IID Value
current_category    bursztyn/dla-niego
perch_page_path /shop/category.php
desc    
catID   18
setID   1
catParentID 6
catTitle    Dla Niego
catSlug dla-niego
catPath products/bursztyn/dla-niego/
catDisplayPath  Bursztyn › Dla Niego
catOrder    2
catTreePosition 001-003-002
catDynamicFields    {"desc":{"_flang":"markdown","raw":"","processed":""}}
perch_desc  
catDepth    2
perch_item_zero_index   4
perch_item_index    5
perch_item_rev_index    9
perch_item_rev_zero_index   8
perch_item_odd  
perch_item_count    13

Debug Message
[1] SELECT * FROM perch2_members_sessions WHERE sessionID='427c4f4ca068a800a9f524e821152187e4347904' AND sessionHttpFootprint='d48de8de3e9ce98461367d804049d3f3f248b8fc' AND sessionExpires>'2016-08-12 08:54:12' LIMIT 1
User is logged in
[1] SELECT * FROM perch2_pages WHERE pagePath='/shop/category.php' LIMIT 1
[1] SELECT * FROM perch2_shop_cart WHERE cartID=1231
[1] SELECT * FROM perch2_shop_cart WHERE cartID=1231
[0] SELECT setID FROM perch2_category_sets WHERE setSlug='' LIMIT 1
[13] SELECT main.* FROM perch2_categories main WHERE 1=1 ORDER BY catTreePosition ASC
[13] Using template: /templates/categories/category.html
[1] SELECT setID FROM perch2_category_sets WHERE setSlug='products' LIMIT 1
[1] SELECT main.* FROM perch2_categories main WHERE 1=1 AND (catSlug='bursztyn') AND setID=1 ORDER BY catTreePosition ASC
[1] Using template: /templates/categories/category_description.html
[5] SELECT DISTINCT idx.itemID FROM perch2_shop_index idx JOIN perch2_shop_products main ON idx.itemID=main.productID AND idx.itemKey='productID' AND ((idx.indexKey='_category' AND idx.indexValue LIKE 'products/bursztyn%' OR idx.indexKey='_category' AND idx.indexValue='products/bursztyn'))
[110] SELECT DISTINCT idx.itemID FROM perch2_shop_index idx JOIN perch2_shop_products main ON idx.itemID=main.productID AND idx.itemKey='productID' AND ((idx.indexKey='status' AND idx.indexValue='1')) GROUP BY idx.itemID HAVING COUNT(idx.itemID)=1
[93] SELECT DISTINCT idx.itemID FROM perch2_shop_index idx JOIN perch2_shop_products main ON idx.itemID=main.productID AND idx.itemKey='productID' AND ((idx.indexKey='parentID' AND idx.indexValue='')) GROUP BY idx.itemID HAVING COUNT(idx.itemID)=1
[5] SELECT tbl.* FROM ( SELECT idx.itemID, main.*, idx2.indexValue as sortval FROM perch2_shop_index idx JOIN perch2_shop_products main ON idx.itemID=main.productID AND idx.itemKey='productID' JOIN perch2_shop_index idx2 ON idx.itemID=idx2.itemID AND idx.itemKey='productID' AND idx2.indexKey='title' AND idx.itemID IN ('68', '64', '60', '65', '67') AND idx.itemID IN ('1', '100', '101', '102', '103', '104', '105', '106', '107', '108', '109', '11', '110', '111', '112', '113', '114', '115', '116', '117', '118', '119', '12', '120', '121', '122', '123', '124', '125', '126', '127', '128', '129', '130', '131', '132', '133', '14', '15', '16', '17', '18', '19', '20', '21', '22', '23', '24', '25', '26', '27', '28', '29', '30', '31', '32', '33', '34', '35', '36', '37', '38', '39', '42', '43', '44', '45', '46', '48', '50', '53', '56', '57', '58', '6', '60', '61', '62', '63', '64', '65', '67', '68', '69', '70', '72', '74', '75', '76', '77', '78', '79', '80', '81', '82', '83', '84', '85', '86', '87', '88', '90', '91', '93', '94', '95', '96', '97', '98', '99') AND idx.itemID IN ('1', '100', '101', '102', '103', '104', '105', '106', '107', '108', '109', '11', '110', '111', '112', '113', '114', '115', '116', '117', '118', '119', '12', '120', '121', '122', '123', '124', '125', '126', '127', '128', '129', '13', '130', '131', '132', '133', '14', '15', '16', '17', '18', '19', '20', '21', '22', '23', '34', '37', '42', '43', '46', '48', '50', '53', '56', '57', '58', '6', '60', '64', '65', '66', '67', '68', '69', '72', '74', '75', '76', '77', '78', '79', '80', '81', '82', '83', '84', '85', '86', '87', '88', '89', '90', '91', '93', '94', '95', '96', '97', '98', '99') WHERE 1=1 AND idx.itemID=idx2.itemID AND idx.itemKey=idx2.itemKey GROUP BY idx.itemID, idx2.indexValue, productID ) as tbl WHERE (productDeleted IS NULL) GROUP BY itemID, sortval ORDER BY sortval ASC
[31] SELECT DISTINCT settingID, settingValue FROM perch2_settings WHERE userID=0
[5] Using template: /templates/shop/products/list.html
[1] SELECT * FROM perch2_shop_currencies WHERE currencyID=110 LIMIT 1
[3] SELECT productID, productVariantDesc, stock_level FROM perch2_shop_products WHERE parentID=60 AND productDeleted IS NULL ORDER BY productOrder ASC
[1] SELECT o.* FROM perch2_shop_options o, perch2_shop_product_options po WHERE o.optionID=po.optionID AND po.productID=60 AND o.optionDeleted IS NULL ORDER BY optionPrecendence ASC
[5] SELECT valueID AS id, valueTitle AS title, valueSKUCode AS skucode FROM perch2_shop_option_values WHERE optionID=1 AND valueDeleted IS NULL ORDER BY valueOrder ASC
[3] SELECT pov.prodoptID, pov.optionID, pov.valueID, o.optionTitle, ov.* FROM perch2_shop_product_option_values pov, perch2_shop_options o, perch2_shop_option_values ov WHERE pov.productID='60' AND pov.optionID=o.optionID AND pov.valueID=ov.valueID AND o.optionDeleted IS NULL AND ov.valueDeleted IS NULL AND o.optionID='1' ORDER BY o.optionPrecendence ASC, ov.valueOrder ASC
Maciej Pieńczewski

Maciej Pieńczewski 0 points

  • 5 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

Right:

current_category    bursztyn/dla-niego
catSlug    dla-niego

So, do I need to edit catSlug manualy in admin panel? Or is it posible to create cutSlug for subcategory with parent slug?

Ok. I have changed perchIf, to match catPath to current category.


<perch:if id="catPath" match="eq" value="{current_category}"> class="selected" </perch:if>

Thanks Drew!