Page 1 of 2 12 LastLast
Results 1 to 10 of 12
  1. #1
    Join Date
    May 2009
    Posts
    1,219
    Plugin Contributions
    2

    Default Can I add extra common text for same category products?

    Working on 1.5.7b

    How would I display category description, or extra_definition in product info page?

    I would like to have same text in addition to the specific product's description.

    I thought of two ways, although open to better ideas in case, and any other considerations about the idea itself:

    1 - check which category/sub-category is the product in, and add the category description the product is in
    2 - check which category/sub-category is the product in, and add an extra definition text

    I prefer the latter, as don't want to have too much info on the category description.

    Also would that work with linked products as well?

    Thank you

  2. #2
    Join Date
    Oct 2008
    Location
    Croatia
    Posts
    1,542
    Plugin Contributions
    19

    Default Re: Can I add extra common text for same category products?

    Not sure if I understand your request, but here's some options...
    # 1 - check which category/sub-category is the product in, and add the category description the product is in
    Code:
    if(zen_product_in_category((int)$_GET['products_id'], 22)) {
            echo zen_get_category_description($current_category_id, $_SESSION['languages_id']);
        }
    # 2 - check which category/sub-category is the product in, and add an extra definition text
    Code:
    if(zen_product_in_category((int)$_GET['products_id'], 22)) {
            echo DEFINE_EXTRA_PRODUCTINFO_TEXT;
        }
    Of course, the code in red depends on your category ID.

    I would opt for plan C - add a new field in the products table and have it controlled from the admin's product page. I understand it's product-based, instead of category-based, but it gives you more control over the contents displayed.
    This could be either an extra description, or a set of radio buttons (dropdown menu) to choose which pre-defined text to show or something else maybe. Either way, I'd make it product-based, making it easier to control from the admin. If it's product-based, it will always show with linked products, no matter which category.

  3. #3
    Join Date
    May 2009
    Posts
    1,219
    Plugin Contributions
    2

    Default Re: Can I add extra common text for same category products?

    Thank you.

    Plan C I think is/would be/could be even more difficult for me, not being a coder.

    Please let me clarify better my intention, if it could be a feasible idea.

    Let's assume I have two categories (or sub-categories): wood - plastic
    then I have same product type under both:

    wood -
    --- chair (model/title name A) - table (model/title name C) - cabinet (model/title name E)
    plastic
    --- chair (model/title name B)- table (model/title name D) - cabinet (model/title name F)

    When viewing
    wood -
    --- chair (model/title name A)
    user would read the detailed description for the name A
    and under that on the page there would be a text reagrding wood, i.e. wood is a natural resource has different grains, etc.
    and this would be the same text (wood is a natural resource has different grains, etc) if user views table (model/title name C), and cabinet (model/title name E)

    whereas if viewing
    plastic
    --- table (model/title name D)
    user would read the detailed description for the name D
    and under that on the page there would be a text reagrding plastic, i.e plastic is a synthetic material it can be hard, or soft, etc.
    and this would be the same text (plastic is a synthetic material it can be hard, or soft, etc.) if user views chair (model/title name B), and cabinet (model/title name F)

    I thought of this as to have same text for all products of given category (or sub) without having to write/edit it for each one.

    So to recap the code you gave, if I am not wrong comes close, but not on target, as I would expect zen cart to find the category ID without me tellin it, something like this:

    user has asked to see the product chair name A
    let me (zen cart) see what category [ID] is chair name A under
    it is under ID 1
    I (zen cart) display the product chair name A, and append to it the extra_definition_text_wood

    my logic would be
    Code:
    check category [ID] associated to this product's [ID]
    if
    category_id is xx
    echo extra_text_xx
    elseif
    category_id is yy
    echo extra_text_yy
    else
    echo extra_text_yy
    of course the above is just pseudo code (like said I don't know how to code), and would be good if it would consider more than 3 categories, meaning many ifs

    I would add this code to templates/tpl_product_info_display.php

  4. #4
    Join Date
    Jan 2004
    Posts
    66,373
    Blog Entries
    7
    Plugin Contributions
    274

    Default Re: Can I add extra common text for same category products?

    Improved pseudo-code would probably be:

    - lookup product's linked categories (products_to_categories table), preferably with the master_categories_id first in the list of retrieved linked categories
    - for each found linked category, find the first that has a secondary description (you'd need to add this into a db field in the categories_description table)
    - if any, display it, and then "break" out of the loop in order to stop displaying any subtext for additional linked categories

    And of course if you wish to edit the actual subtext via the Admin you'd need to build all the logic for adding the text, validating it, saving it, retrieving for edit, etc.
    .

    Zen Cart - putting the dream of business ownership within reach of anyone!
    Donate to: DrByte directly or to the Zen Cart team as a whole

    Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
    Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

  5. #5
    Join Date
    Oct 2008
    Location
    Croatia
    Posts
    1,542
    Plugin Contributions
    19

    Default Re: Can I add extra common text for same category products?

    Quote Originally Posted by keneso View Post
    Thank you.

    Plan C I think is/would be/could be even more difficult for me, not being a coder.

    I thought of this as to have same text for all products of given category (or sub) without having to write/edit it for each one.

    So to recap the code you gave, if I am not wrong comes close, but not on target, as I would expect zen cart to find the category ID without me tellin it, something like this:

    user has asked to see the product chair name A
    let me (zen cart) see what category [ID] is chair name A under
    it is under ID 1
    I (zen cart) display the product chair name A, and append to it the extra_definition_text_wood

    my logic would be
    Code:
    check category [ID] associated to this product's [ID]
    if
    category_id is xx
    echo extra_text_xx
    elseif
    category_id is yy
    echo extra_text_yy
    else
    echo extra_text_yy
    of course the above is just pseudo code (like said I don't know how to code), and would be good if it would consider more than 3 categories, meaning many ifs

    I would add this code to templates/tpl_product_info_display.php
    Well, the first example kinda auto-discovers the category...
    Code:
    echo zen_get_category_description($current_category_id, $_SESSION['languages_id']);
    This will display the category description for that product's master category. If you put your (wooden) chair in a plastic category as a linked product, it will still pull the description from your wood category. This, of course, assumes you actually do have descriptions for your categories, and that those can be used for this purpose.

    An alternative would be to create a new file in your includes/languages/YOUR_LANGUAGE/extra_definitions/YOUR_TEMPLATE/extra_product_descriptions.php and then manually add a description for each category:
    Code:
    define('TEXT_PRODUCT_EXTRA_DESC_CAT1', 'wood is a natural resource has different grains, etc.');
    define('TEXT_PRODUCT_EXTRA_DESC_CAT2', 'plastic is a synthetic material it can be hard, or soft, etc.');
    Then use this in your tpl_product_info_default.php
    Code:
    if(defined('TEXT_PRODUCT_EXTRA_DESC_CAT' . $current_category_id)) {
            echo constant('TEXT_PRODUCT_EXTRA_DESC_CAT' . $current_category_id);
        }
    This will NOT work with linked products - it will be based on the category you're currently browsing. If you want to focus on master category, you could do this:
    Code:
    if(defined('TEXT_PRODUCT_EXTRA_DESC_CAT' . $product_info->fields['master_categories_id'])) {
            echo constant('TEXT_PRODUCT_EXTRA_DESC_CAT' . $product_info->fields['master_categories_id']);
        }
    Or you can combine both in case your primary choice hasn't been defined...

    However, I'd still go with adding a field in the admin (and database) so it's controlled from the admin. Adding a secondary category description is not that hard, just follow the logic for the main description and duplicate it (with minor edits, of course).

  6. #6
    Join Date
    May 2009
    Posts
    1,219
    Plugin Contributions
    2

    Default Re: Can I add extra common text for same category products?

    Thank you both.
    When I'll get the time I'll look into it more deeply, so to include the linked ones as well.

    For now I played with balhir's snips, and got the results expected using, of course not working on linked ones.
    Code:
    if(defined('TEXT_PRODUCT_EXTRA_DESC_CAT' . $current_category_id)) {
            echo constant('TEXT_PRODUCT_EXTRA_DESC_CAT' . $current_category_id);
        }
    Using this nothing seemed happening, of course I might be missing something
    Code:
    if(defined('TEXT_PRODUCT_EXTRA_DESC_CAT' . $product_info->fields['master_categories_id'])) {
            echo constant('TEXT_PRODUCT_EXTRA_DESC_CAT' . $product_info->fields['master_categories_id']);
        }
    Tried being creative in combining the two, but didn't get results

    Will look into the secondary description, admin and database when getting some time like said.

  7. #7
    Join Date
    Oct 2008
    Location
    Croatia
    Posts
    1,542
    Plugin Contributions
    19

    Default Re: Can I add extra common text for same category products?

    Quote Originally Posted by keneso View Post
    Tried being creative in combining the two, but didn't get results

    Will look into the secondary description, admin and database when getting some time like said.
    Not sure why you're not getting any results with master_categories_id... You can try this as a combination:
    Code:
    if(defined('TEXT_PRODUCT_EXTRA_DESC_CAT' . $product_info->fields['master_categories_id'])) {
            echo constant('TEXT_PRODUCT_EXTRA_DESC_CAT' . $product_info->fields['master_categories_id']);
        } elseif(defined('TEXT_PRODUCT_EXTRA_DESC_CAT' . $current_category_id)) {
            echo constant('TEXT_PRODUCT_EXTRA_DESC_CAT' . $current_category_id);
        }
    So, if there's text for master category, show it, else check for current category text.

  8. #8
    Join Date
    May 2009
    Posts
    1,219
    Plugin Contributions
    2

    Default Re: Can I add extra common text for same category products?

    Thank you

    perhaps it was/is my confusion, as it depends where I access the product from, meaning which route to get to the product page
    i.e.
    hardware > printers > Hewlett Packard LaserJet 1100Xi Linked
    would display nothing (expecting the printer extra-definition)
    hardware > Hewlett Packard LaserJet 1100Xi Linked
    would display the TEXT_PRODUCT_EXTRA_DESC_CAT1 (hardware extra-definition)

    same with
    dvd > action > The Replacement Killers
    would display nothing (expecting the action extra-definition)
    dvd > The Replacement Killers
    would display the TEXT_PRODUCT_EXTRA_DESC_CAT3 (dvd extra-definition)

    Shouldn't it in the first cases (longer path/more clicks) display the master categories, which in the two examples should have been hardware, and dvd?
    Am I missing something a

    I am using a local setup to test, having installed with demo data.

    I put you last snip in
    includes/templates/CUSTOM/templates/tpl_prduct_info_display.php
    and the following definitions in
    includes/languages/LANGUAGE/extra_definitions/CUSTOM/extra_product_descriptions.php
    1 - hardware
    2 - software
    3 - dvd
    4 - graphic cards
    5 - printers
    6 - monitor
    7 - speakers
    8 - keyboards
    9 - mice
    10 - action
    12 - comedy
    22 - big-linked

    That said I am happy for now with the current-category display.

  9. #9
    Join Date
    Oct 2008
    Location
    Croatia
    Posts
    1,542
    Plugin Contributions
    19

    Default Re: Can I add extra common text for same category products?

    This is quite messy being category-based, that's why I originally said I'd be doing it product-based...

    Quote Originally Posted by keneso View Post
    hardware > printers > Hewlett Packard LaserJet 1100Xi Linked
    would display nothing (expecting the printer extra-definition)
    Actually, just as expected. If you search for that model number in admin->Catalog, you'll see there's 7 results for that product. You're looking at product_id 27, and if you check that product, you'll see its master category id is 5. And you're currently browsing category 5 ($current_category_id). You don't have any text for category 5, you only defined 1 and 3.

    Quote Originally Posted by keneso View Post
    hardware > Hewlett Packard LaserJet 1100Xi Linked
    would display the TEXT_PRODUCT_EXTRA_DESC_CAT1 (hardware extra-definition)
    How did you get there? Which link did you follow? Or did you manipulate the URL?

    Quote Originally Posted by keneso View Post
    same with
    dvd > action > The Replacement Killers
    would display nothing (expecting the action extra-definition)
    dvd > The Replacement Killers
    would display the TEXT_PRODUCT_EXTRA_DESC_CAT3 (dvd extra-definition)
    Same as above - that item is in category 10, not 3.

    Quote Originally Posted by keneso View Post
    Shouldn't it in the first cases (longer path/more clicks) display the master categories, which in the two examples should have been hardware, and dvd?
    Am I missing something a
    Don't confuse Master Categories ID with Parent Category - that's different things, and therefore requires different code. You would need to run the checks mentioned here, and then add another elseif and run the same checks through parent categories.
    Just to make sure you understand the difference - in the first case (hp printer), your URL looks like
    Code:
    index.php?main_page=product_info&cPath=1_5&products_id=27
    where 5 is current category id, 1 is parent category, and in this case 5 happens to be master category id as well. If you look at the same product under "big linked", the URL will be
    Code:
    index.php?main_page=product_info&cPath=22&products_id=27
    so current category id will be 22, but master category id will still be 5 (that's how the product is configured in admin).
    Hope this makes sense...

  10. #10
    Join Date
    Feb 2006
    Location
    Tampa Bay, Florida
    Posts
    9,671
    Plugin Contributions
    123

    Default Re: Can I add extra common text for same category products?

    Have you looked at my Boilerplate mod?

    https://www.thatsoftwareguy.com/zenc...scription.html

    It's a set of instructions for doing this sort of thing.
    That Software Guy. My Store: Zen Cart Modifications
    Available for hire - See my ad in Services
    Plugin Moderator, Documentation Curator, Chief Cook and Bottle-Washer.
    Do you benefit from Zen Cart? Then please support the project.

 

 
Page 1 of 2 12 LastLast

Similar Threads

  1. common or shared options for all products (in certain category)
    By sunraise2005 in forum Setting Up Categories, Products, Attributes
    Replies: 5
    Last Post: 13 Sep 2010, 07:13 AM
  2. Common image for all products in a category
    By camioman in forum Setting Up Categories, Products, Attributes
    Replies: 4
    Last Post: 14 May 2006, 01:34 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
disjunctive-egg
Zen-Cart, Internet Selling Services, Klamath Falls, OR