Forum

Thread tagged as: Question, Shop

perch if: display category if eq "New"

In Perch Shop - products list template, I want to display category of the product, only when it match cat with id 34

So, my <perch:showall /> shows

category    
Array
(
    [0] => 32
    [1] => 31
    [2] => 37
    [3] => 34
)

I try to use in the template

<perch:if id="category" match="eq" value="34">NEW!</perch:if>

But it doesnt seem to work. Can someone suggest me any solution for this?

Thanks!

Maciej Pieńczewski

Maciej Pieńczewski 0 points

  • 4 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

Can you post your diagnostics report?

Perch: 3.0.3
Production mode: Production (100)
Installed apps: content (3.0.3), assets (3.0.3), categories (3.0.3), perch_blog (5.5.1), perch_forms (1.9), perch_shop_orders (1.2.1), perch_shop_products (1.2.1), perch_shop (1.2.1), perch_members (1.6.2)
DB driver: PDO
DB tables: perch2_blog_authors (1), perch2_blog_comments (0), perch2_blog_index (72), perch2_blog_posts (3), perch2_blog_posts_to_tags (0), perch2_blog_sections (1), perch2_blog_tags (0), perch2_blogs (1), perch2_categories (12), perch2_category_counts (0), perch2_category_sets (2), perch2_content_index (3298), perch2_content_items (748), perch2_content_regions (67), perch2_forms (4), perch2_forms_responses (4), perch2_members (40), perch2_members_forms (1), perch2_members_member_tags (0), perch2_members_sessions (5), perch2_members_tags (0), perch2_menu_items (14), perch2_navigation (0), perch2_navigation_pages (0), perch2_page_templates (1), perch2_pages (18), perch2_resource_log (6425), perch2_resource_tags (109), perch2_resources (5148), perch2_resources_to_tags (1126), perch2_settings (34), perch2_shop_addresses (380), perch2_shop_admin_index (98), perch2_shop_brands (1), perch2_shop_cart (1473), perch2_shop_cart_data (361), perch2_shop_cart_items (100), perch2_shop_countries (250), perch2_shop_currencies (152), perch2_shop_customers (103), perch2_shop_emails (4), perch2_shop_index (57422), perch2_shop_option_values (136), perch2_shop_options (7), perch2_shop_order_items (182), perch2_shop_order_promotions (7), perch2_shop_order_statuses (9), perch2_shop_orders (86), perch2_shop_orders_meta (1), perch2_shop_product_files (0), perch2_shop_product_option_values (272), perch2_shop_product_options (65), perch2_shop_product_tags (0), perch2_shop_products (903), perch2_shop_promotions (1), perch2_shop_sales (0), perch2_shop_search (504), perch2_shop_shipping_zone_countries (1), perch2_shop_shipping_zones (1), perch2_shop_shippings (3), perch2_shop_tax_exhibits (139), perch2_shop_tax_group_rates (1), perch2_shop_tax_groups (1), perch2_shop_tax_locations (1), perch2_shop_tax_rates (1), perch2_shop_variants (1605), perch2_user_passwords (0), perch2_user_privileges (78), perch2_user_role_privileges (16), perch2_user_roles (2), perch2_users (1)
Users: 1
App runtimes:
<?php
    $apps_list = array(
        'content',
        'categories',
        'perch_blog',
        'perch_members',
        'perch_shop',
        'perch_forms',
    );
Scheduled tasks for perch_blog: delete_spam_comments (1440 mins)
Editor plug-ins: markitup
H1: 61a603508d38466e60f55f441dc129b8
L1: 894b0abc4ad842ebd30c9907cf2b48f0
F1: 0c66c2e1f82f9e0b7617b2cb8270f2c7
headerColour: #aab50d
content_singlePageEdit: 1
helpURL:
siteURL: /
hideBranding: 0
content_collapseList: 1
lang: en-gb
update_2.8.34: done
latest_version:
on_sale_version:
perch_shop_update: 1.2.1
headerScheme: light
perch_members_login_page: /members/login.php?r={returnURL}
perch_shop_price_tax_mode: inc
perch_shop_site_url: https://zielony-slon.com/
perch_shop_product_url: /shop/products/{slug}
perch_shop_reporting_currency: 110
dashboard: 1
hide_pwd_reset: 0
content_hideNonEditableRegions: 0
content_frontend_edit: 0
perch_shop_default_currency: 110
perch_shop_invoice_number_format: %d
perch_blog_site_name:
perch_blog_post_url: /blog/post.php?s={postSlug}
perch_blog_slug_format: %Y-%m-%d-{postTitle}
perch_blog_akismet_key:
perch_blog_max_spam_days: 0
perch_blog_comment_notify: 0
perch_members_update: 1.4
update_3.0: done
perch_blog_update: 5.0.1
update_3.0.3: done
content_skip_region_list: 0
PERCH_DEVELOPMENT: 10
PERCH_STAGING: 50
PERCH_PRODUCTION: 100
PERCH_DB_USERNAME: phoh3o_zielonys
PERCH_DB_SERVER: zielony-slon.com.mysql.dhosting.pl
PERCH_DB_DATABASE: uanoh7_zielonys
PERCH_DB_PREFIX: perch2_
PERCH_TZ: UTC
PERCH_LOGINPATH: /perch
PERCH_PATH: /home/klient.dhosting.pl/zielonyslon/zielony-slon.com/public_html/perch
PERCH_CORE: /home/klient.dhosting.pl/zielonyslon/zielony-slon.com/public_html/perch/core
PERCH_RESFILEPATH: /home/klient.dhosting.pl/zielonyslon/zielony-slon.com/public_html/perch/resources
PERCH_RESPATH: /perch/resources
PERCH_HTML5: 1
PERCH_RUNWAY:
PERCH_ERROR_MODE: DIE
PERCH_DATE_LONG: %d %B %Y
PERCH_DATE_SHORT: %d %b %Y
PERCH_TIME_SHORT: %H:%M
PERCH_TIME_LONG: %H:%M:%S
PERCH_RUNWAY_ROUTED:
PERCH_STRONG_PASSWORDS:
PERCH_ASSET_VERSION: ed79f7a54b300ef2b1e6
PERCH_DEBUG:
PERCH_PREVIEW_ARG: preview
PERCH_TEMPLATE_PATH: /home/klient.dhosting.pl/zielonyslon/zielony-slon.com/public_html/perch/templates
PERCH_TEMPLATE_FILTERS:
PERCH_DEFAULT_DOC: index.php
PERCH_DEFAULT_EXT: .php
PERCH_PRODUCTION_MODE: 100
PERCH_XHTML_MARKUP:
PERCH_RWD: 1
PERCH_HTML_ENTITIES:
PERCH_SSL:
PERCH_STRIPSLASHES:
PERCH_PROGRESSIVE_FLUSH: 1
PERCH_PARANOID:
PERCH_FORCE_SECURE_COOKIES:
PERCH_DEFAULT_BUCKET: default
PERCH_TRANSLATION_ASSIST:
PERCH_PASSWORD_MIN_LENGTH: 6
PERCH_MAX_FAILED_LOGINS: 10
PERCH_AUTH_LOCKOUT_DURATION: 1 HOUR
PERCH_VERIFY_UPLOADS:
PERCH_PRIV_ASSIST:
PERCH_AUTH_PLUGIN:
PERCH_DB_CHARSET: utf8
PERCH_DB_PORT:
PERCH_DB_SOCKET:
PERCH_SHOP_VERSION: 1.2.1
PERCH_APPS_EDITOR_PLUGIN: markitup
PERCH_APPS_EDITOR_MARKUP_LANGUAGE: markdown
Hosting settings

PHP: 5.6.29-dh1
Zend: 2.6.0
OS: Linux
SAPI: litespeed
Safe mode: not detected
MySQL client: mysqlnd 5.0.11-dev - 20120503 - $Id: 76b08b24596e12d4553bd41fc93cccd5bac2fe7a $
MySQL server: 5.5.5-10.0.27-MariaDB-cll-lve
Free disk space: 736,17 GB
Extensions: Core, date, ereg, libxml, openssl, pcre, sqlite3, zlib, bcmath, bz2, calendar, ctype, curl, dom, hash, fileinfo, filter, ftp, gd, gettext, SPL, iconv, session, interbase, intl, json, ldap, mbstring, mcrypt, mssql, standard, mysqlnd, mysqli, odbc, mysql, PDO, pdo_mysql, PDO_ODBC, pdo_pgsql, pdo_sqlite, pgsql, Phar, posix, Reflection, imap, shmop, SimpleXML, snmp, soap, sockets, exif, sybase_ct, sysvmsg, tokenizer, wddx, xml, xmlreader, xmlrpc, xmlwriter, xsl, zip, litespeed, dba, geoip, imagick, mailparse, memcache, memcached, SQLite, mhash, ionCube Loader, Zend OPcache
GD: Yes
ImageMagick: Yes
PHP max upload size: 200M
PHP max form post size: 32M
PHP memory limit: 2048M
Total max uploadable file size: 32M
Resource folder writeable: Yes
Session timeout: 16,65 minutes
Native JSON: Yes
Filter functions: Yes
Transliteration functions: Yes
TMPDIR: /home/klient.dhosting.pl/zielonyslon/.tmp
PHPRC: /home/klient.dhosting.pl/zielonyslon/.settings/
LANG: pl_PL.UTF8
MAGICK_THREAD_LIMIT: 1
PATH: /bin:/usr/bin:/usr/local/bin
HTTP_ACCEPT: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8
HTTP_ACCEPT_ENCODING: gzip, deflate
HTTP_ACCEPT_LANGUAGE: en-GB,en-US;q=0.8,en;q=0.6
HTTP_CONNECTION: keep-alive
HTTP_COOKIE: off=1; admin_skin=netart_rwd; __utma=147753532.729289033.1494485386.1498896670.1498920505.53; __utmc=147753532; __utmz=147753532.1498844264.51.5.utmcsr=google|utmccn=(organic)|utmcmd=organic|utmctr=(not%20provided); p_m=; cmsa=1; cookiebar=hide; PHPSESSID=61c4b2055e72ba132ca70eb633a4c01e
HTTP_HOST: zielony-slon.com
HTTP_REFERER: https://zielony-slon.com/perch/core/settings/diagnostics/
HTTP_USER_AGENT: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.115 Safari/537.36
HTTP_UPGRADE_INSECURE_REQUESTS: 1
DOCUMENT_ROOT: /home/klient.dhosting.pl/zielonyslon/zielony-slon.com/public_html
REMOTE_ADDR: 95.160.149.212
REMOTE_PORT: 57058
SERVER_ADDR: 109.95.158.2
SERVER_NAME: zielony-slon.com
SERVER_ADMIN: admin@demonek.com
SERVER_PORT: 80
REQUEST_URI: /perch/core/settings/diagnostics/?extended
SCRIPT_FILENAME: /home/klient.dhosting.pl/zielonyslon/zielony-slon.com/public_html/perch/core/settings/diagnostics/index.php
QUERY_STRING: extended
SCRIPT_URI: https://zielony-slon.com/perch/core/settings/diagnostics/
SCRIPT_URL: /perch/core/settings/diagnostics/
SCRIPT_NAME: /perch/core/settings/diagnostics/index.php
SERVER_PROTOCOL: HTTP/1.1
SERVER_SOFTWARE: LiteSpeed
REQUEST_METHOD: GET
X-LSCACHE: 1
PHP_SELF: /perch/core/settings/diagnostics/index.php
REQUEST_TIME_FLOAT: 1499172830,0631
REQUEST_TIME: 1499172830
argc: 1
Drew McLellan

Drew McLellan 2638 points
Perch Support

The first thing to do is make sure your problem still exists in the current version of the software.

Updated. But unfortunately this still exists in current version.

Using this on my home page

                    <?php
                        perch_shop_products([
                            'count' => 8,
                            'category' => 'produkty/polecamy/',
                            'template' => 'products/list-home-page.html',
                        ]);
                    ?>    

list-home-page.html

<a  href="https://zielony-slon.com/sklep/produkty/produkt.php?s=<perch:shop id="slug" type="slug" />" class="products-list__item--enter">
    <div class="products-list__item--imageWrap">
        <div class="products-list__item--image img-responsive">
            <img src="<perch:shop id="image" type="image" label="Zdjecie glowne" width="465" height="525" crop="true" order="2" />" alt="produkt">
        </div>
        <div class="products-list__item--imageSec img-responsive">
            <img src="<perch:shop id="image-hover" type="image" label="Zdjęcie drugie" order="4" width="465" height="525" crop="true" order="4" />" alt="produkt">
        </div>
        <perch:if exists="on_sale">
                <span class="on-sale-note">PROMOCJA</span>
        </perch:if>
    </div>
    <div class="item--info group">
        <div class="item--name"><perch:shop id="title" type="text" /></div>
        <div class="item--price">
                <perch:if exists="on_sale">
                        <span class="on-sale"><perch:shop id="price" type="shop_currency_value" label="Price" divider-before="Pricing" size="m" min="0" step="any" /></span>
                        <span class="on-sale-price"><perch:shop id="sale_price" type="shop_currency_value" label="Sale price" size="m" min="0" step="any"  /></span>
                 <perch:else />
                        <perch:shop id="price" type="text" label="Price" divider-before="Pricing" size="m" min="0" step="any" type="shop_currency_value" />                         
                </perch:if>
        </div>
        <perch:if id="perch_category" match="eq" value="34"><div class="item--category">NEW!</div></perch:if>
    </div>
</a>
Drew McLellan

Drew McLellan 2638 points
Perch Support

I don't think you'll be able to do it in the template, then. You'll need to use an each callback, look at the categories, and then set a value to check for/display in the template.