简体   繁体   中英

List products for specific category

I am trying to list 4 products based on the category of the product I am in, so if I were viewing "Cool product" which has the category "Awesome category", I would like to view 4 of the latest "Awesome category" products within that product.

I know that this can be achieved by manually adding products for each product to a specific block, unfortunately there are way too many products for this approach to be feasible.

I have gotten to the point where I am able to get the id's of the latest 4 products based on the current products category, but I am unable to get the thumb image or the product's URL, here is what I have thus far,

{php}
    $pid = $this->get_template_vars("product");
    $pid = $pid["product_id"];

    $cid = db_get_field("SELECT category_id FROM cscart_products_categories WHERE product_id = '$pid' AND link_type = 'M';");
    $prod_ids = db_get_fields("SELECT * FROM cscart_products_categories WHERE category_id = '$cid' LIMIT 4;");

    foreach($prod_ids as $prod_id){
        echo $prod_id;
    }

    print_r($prods);

{/php}

as you can see I have PHP enabled in the config. So in conclusion, I would like to display 4 products, inside of the product I am currently viewing, based on the current products category.

way 1 - when you have category_id

http://x.com/index.php?dispatch=categories.view&category_id=45

way 2 - when you have a product_id or a category_id

do a query (ex. for category)

select * from cscart_seo_redirects where object_id = 45 and type = 'c' and lang_code='en'

then read the src field!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM