Viewing 12 posts - 1 through 12 (of 12 total)
  • Author
    Posts
  • #14014

    Can I ask if the SORTING feature for Products Elements in the template builder is implemented already?

    Based on this thread: http://www.kriesi.at/support/topic/sorting-products-in-custom-pages-built-in-template-builder

    Hoping for a reply.

    I really need this feature badly.

    #81716

    I have created a new template called ‘Products Order by Price’ in the template builder.

    Its displaying the products in an order by price and by date, in which I want only the price as the sorting parameter in ASC order.

    How can I do that?

    Below in the code I used to do this.

    ‘Products Order by Price’ Elements codes in register-admin-dynamic-options.php

    $elements[] = array(

    “dynamic” => ‘shop_order_by_price’,

    “name” => “Products Order By Popularity”,

    “slug” => “”,

    “type” => “group”,

    “id” => “dynamic_shop_order_by_popularity”,

    “linktext” => “Add another Slide”,

    “deletetext” => “Remove Slide”,

    “removable” => ‘remove element’,

    “blank” => true,

    “nodescription” => true,

    ‘subelements’ => array(

    array( “name” => “Which shop categories should be used?”,

    “desc” => “You can select multiple categories here. Products from those categories will be shown.”,

    “id” => “shop_cats_dynamic”,

    “type” => “select”,

    “slug” => “”,

    “multiple”=>6,

    “taxonomy” => “product_cat”,

    “subtype” => “cat”),

    array(

    “slug” => “”,

    “name” => “Shop Columns”,

    “desc” => “How many columns should be displayed?”,

    “id” => “shop_columns”,

    “type” => “select”,

    “std” => “3”,

    “no_first”=>true,

    “subtype” => array(‘2’=>’2′,’3’=>’3′,’4’=>’4′,’5’=>’5′)),

    array(

    “slug” => “”,

    “name” => “Products per page”,

    “desc” => “How many items should be displayed?”,

    “id” => “shop_item_count”,

    “type” => “select”,

    “std” => “24”,

    “no_first”=>true,

    “subtype” => $itemcount),

    array(

    “slug” => “”,

    “name” => “Product Excerpt”,

    “desc” => “Should a small text excerpt of the product entry be displayed?”,

    “id” => “shop_text”,

    “type” => “select”,

    “std” => “no”,

    “no_first”=>true,

    “subtype” => array(‘yes’=>’yes’,’no’=>’no’)),

    array(

    “slug” => “”,

    “name” => “Shop Pagination”,

    “desc” => “Should a shop pagination be displayed?”,

    “id” => “shop_pagination”,

    “type” => “select”,

    “std” => “yes”,

    “no_first”=>true,

    “subtype” => array(‘yes’=>’yes’,’no’=>’no’)),

    array(

    “slug” => “”,

    “name” => “Shop Slider Row”,

    “desc” => “Should the products appear as a horizontal slider that only shows one row at a time?”,

    “id” => “shop_slider”,

    “type” => “select”,

    “std” => “no”,

    “no_first”=>true,

    “subtype” => array(‘yes’=>’yes’,’no’=>’no’)),

    array(

    “slug” => “”,

    “name” => “Shop Slider Autorotation”,

    “desc” => “Should the slider autorotate? if so choose how many seconds each product set should be visible”,

    “id” => “shop_autorotate”,

    “type” => “select”,

    “std” => “0”,

    “required”=>array(‘shop_slider’,’yes’),

    “no_first”=>true,

    “subtype” => array(‘Off’=>’0′,’2’=>’2′,’3’=>’3′,’4’=>’4′,’5’=>’5′,’6’=>’6′,’7’=>’7′,’8’=>’8′,’9’=>’9′,’10’=>’10’,’15’=>’15’,’20’=>’20’,’30’=>’30’)),

    )

    );

    Added function in helper-templates.php

    function shop_order_by_price($element)

    {

    $output = “”;

    $terms = “‘”. $_SERVER .”‘”;

    //check if the plugin is enabled

    if(!avia_woocommerce_enabled())

    {

    $url = network_site_url( ‘wp-admin/plugin-install.php?tab=search&type=term&s=WooCommerce&plugin-search-input=Search+Plugins’);

    $output = “<p>You need to install and activate the WooCommerce Shop Plugin to display Products</p>”;

    return $output;

    }

    extract($element[0]);

    global $avia_config, $more, $woocommerce_loop;

    if($shop_columns == 5 && strpos($avia_config,’dual’) !== false ) $shop_columns = 4;

    if($shop_text == ‘yes’) $avia_config = ‘active';

    $woocommerce_loop = $avia_config = $shop_columns;

    $avia_config = array(

    ‘post_type’ => ‘product’,

    ‘post_status’ => ‘publish’,

    ‘ignore_sticky_posts’ => 1,

    “paged” => get_query_var( ‘paged’ ),

    ‘posts_per_page’ => $shop_item_count,

    ‘orderby’ => ‘price’,

    ‘order’ => ‘ASC’,

    ‘meta_query’ => array(

    array(

    ‘key’ => ‘_visibility’,

    ‘value’ => array(‘catalog’, ‘visible’),

    ‘compare’ => ‘IN’

    )

    )

    );

    if(empty($shop_cats_dynamic) || $shop_cats_dynamic == ‘null’)

    {

    $avia_config = “product”;

    }

    else

    {

    $avia_config = array( array( ‘taxonomy’ => ‘product_cat’,

    ‘field’ => ‘id’,

    ‘terms’ => explode(‘,’, $shop_cats_dynamic),

    ‘operator’ => ‘IN’

    ));

    }

    query_posts($avia_config);

    ob_start();

    woocommerce_get_template_part( ‘loop’, ‘shop’ );

    $products = ob_get_clean();

    $extraClass = “dynamic_el_”.$this->dynamic_counter;

    $output .= “<div class=’$extraClass container_wrap “.$avia_config.” template-shop shop_columns_”.$avia_config.”‘>”;

    $output .= “<div class=’template-shop content shop_slider_$shop_slider’ data-interval=’$shop_autorotate’>”;

    $output .= $products;

    if($shop_pagination == ‘yes’) $output .= avia_pagination();

    $output .= “</div>”;

    $output .= “</div>”;

    wp_reset_query();

    return $output;

    }

    #81717

    Hello,

    I think the update hasn’t been implemented by Kriesi yet. Please hold on for further updates.

    Regards,

    Ismael

    #81718

    Hi Ismael,

    Thanks for your reply.

    As you can see, I have implemented a workaround code above.

    Am I doing it correctly of sorting the products by price without including the date?

    Where is the file that execute the sorting by date as default for “Products Element” in the Template Builder?

    $avia_config = array(

    ‘post_type’ => ‘product’,

    ‘post_status’ => ‘publish’,

    ‘ignore_sticky_posts’ => 1,

    “paged” => get_query_var( ‘paged’ ),

    ‘posts_per_page’ => $shop_item_count,

    ‘orderby’ => ‘price’,

    ‘order’ => ‘ASC’,

    ‘meta_query’ => array(

    array(

    ‘key’ => ‘_visibility’,

    ‘value’ => array(‘catalog’, ‘visible’),

    ‘compare’ => ‘IN’

    )

    )

    );

    #81719

    Hello,

    You can find the product query on includes > helper-template.php. Find this code.

    $avia_config['new_query'] = array(
    'post_type' => 'product',
    'post_status' => 'publish',
    'ignore_sticky_posts' => 1,
    "paged" => get_query_var( 'paged' ),
    'posts_per_page' => $shop_item_count,
    'orderby' => 'id',
    'order' => 'asc',
    'meta_query' => array(
    array(
    'key' => '_visibility',
    'value' => array('catalog', 'visible'),
    'compare' => 'IN'
    )
    )
    );

    Regards,

    Ismael

    #81720

    Hi Ismael,

    Yes that is what I have modified Ismael.

    But its sorting the products by date and by price.

    If I set the date to the earliest time its publish and the price to smallest to highest.

    I only want the products to be sorted by price without referring to the date a product is publish.

    Can I ask where is the php code that uses by date as the default sort for Products Elements?

    #81721

    Afaik you can’t use “price” as orderby parameter because it’s a meta value and it requires a meta query – something like:

    $avia_config['new_query'] = array(
    'post_type' => 'product',
    'post_status' => 'publish',
    'ignore_sticky_posts' => 1,
    "paged" => get_query_var( 'paged' ),
    'posts_per_page' => $shop_item_count,
    'orderby' => 'meta_value_num',
    'order' => 'asc',
    'meta_query' => array(
    array(
    'key' => '__price'
    )
    )
    );

    should work though…

    #81722

    Hi Dude,

    Thanks for your reply.

    I tried the php codes that you posted:

    $avia_config = array(

    ‘post_type’ => ‘product’,

    ‘post_status’ => ‘publish’,

    ‘ignore_sticky_posts’ => 1,

    “paged” => get_query_var( ‘paged’ ),

    ‘posts_per_page’ => $shop_item_count,

    ‘orderby’ => ‘meta_value_num’,

    ‘order’ => ‘asc’,

    ‘meta_query’ => array(

    array(

    ‘key’ => ‘__price’

    )

    )

    );

    in helper-template.php but its still the same.

    Its still referring to by date to the earliest time its publish and the price to smallest to highest.

    What I want is to sort it only by price.

    Hope you can help.

    #81723

    I’m not sure why it doesn’t work. The orderby parameter is correct – maybe WooCommerce or a third party plugin manipulates the query somehow (with action hooks, etc). I’ll mark this thread for Kriesi – maybe he can provide any useful tips….

    #81724

    Ok, Thanks Dude and Ismael.

    #81725

    Hey!

    I’ll close this thread now – Kriesi can reopen it when he’s able to comment on the issue.

    Regards,

    Peter

    #81726

    Hi!

    Hey! Nxt update will allow to sort each dynamic element individually.

    Cheers!

    Regards,

    Kriesi

Viewing 12 posts - 1 through 12 (of 12 total)

The topic ‘Any Update in the Products Element Sorting Feature’ is closed to new replies.