2018-12-13 17:19:55 +00:00
|
|
|
export default function getQuery( attributes, name ) {
|
2018-11-19 16:33:17 +00:00
|
|
|
const { categories, columns, orderby, rows } = attributes;
|
|
|
|
|
|
|
|
const query = {
|
2018-11-26 16:03:26 +00:00
|
|
|
status: 'publish',
|
2018-11-19 16:33:17 +00:00
|
|
|
per_page: rows * columns,
|
|
|
|
};
|
|
|
|
|
2018-12-13 17:19:55 +00:00
|
|
|
if ( categories && categories.length ) {
|
2018-11-19 16:33:17 +00:00
|
|
|
query.category = categories.join( ',' );
|
|
|
|
}
|
|
|
|
|
2018-12-13 17:19:55 +00:00
|
|
|
if ( orderby ) {
|
|
|
|
if ( 'price_desc' === orderby ) {
|
|
|
|
query.orderby = 'price';
|
|
|
|
query.order = 'desc';
|
|
|
|
} else if ( 'price_asc' === orderby ) {
|
|
|
|
query.orderby = 'price';
|
|
|
|
query.order = 'asc';
|
|
|
|
} else if ( 'title' === orderby ) {
|
|
|
|
query.orderby = 'title';
|
|
|
|
query.order = 'asc';
|
|
|
|
} else if ( 'menu_order' === orderby ) {
|
|
|
|
query.orderby = 'menu_order';
|
|
|
|
query.order = 'asc';
|
|
|
|
} else {
|
|
|
|
query.orderby = orderby;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Toggle shortcode atts depending on block type.
|
|
|
|
switch ( name ) {
|
|
|
|
case 'woocommerce/product-best-sellers':
|
|
|
|
query.orderby = 'popularity';
|
|
|
|
break;
|
2018-12-15 02:08:58 +00:00
|
|
|
<<<<<<< HEAD
|
2018-12-14 19:45:19 +00:00
|
|
|
case 'woocommerce/product-top-rated':
|
2018-12-14 20:21:56 +00:00
|
|
|
query.orderby = 'rating';
|
2018-12-15 02:08:58 +00:00
|
|
|
=======
|
2018-12-14 23:47:16 +00:00
|
|
|
case 'woocommerce/product-on-sale':
|
|
|
|
query.on_sale = 1;
|
2018-12-15 02:08:58 +00:00
|
|
|
>>>>>>> 75e957b33c668e2ef98500fab68ecfe8ca705ac4
|
2018-12-14 20:21:56 +00:00
|
|
|
break;
|
2018-11-19 16:33:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return query;
|
|
|
|
}
|