我有一个shopify商店的开发主题。基本上它是一个儿童主题。我想知道如何在首页上展示最畅销的产品。我试过这样的事情,但没有运气可能因为样品已经过时了。
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.util.concurrent.Callable;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
public class ThreadingExamples {
public static void main(String[] args) throws InterruptedException {
final CountDownLatch cdl = new CountDownLatch(1);
ExecutorService es = Executors.newFixedThreadPool(2);
es.submit(new ForLoo1(cdl));
es.submit(new ForLoop2(cdl));
es.shutdown();
es.awaitTermination(1, TimeUnit.DAYS);
}
}
class ForLoo1 implements Callable<Object> {
CountDownLatch cdl;
public ForLoo1(CountDownLatch cdl){
this.cdl=cdl;
}
@Override
public Object call() throws Exception {
System.out.println("I am writing content into file....");
String s = "This is the content to write into a file";
File file = new File("/home/f.txt");
if (!file.exists()) {
file.createNewFile();
}
FileWriter fw = new FileWriter(file);
BufferedWriter bw = new BufferedWriter(fw);
bw.write(s);
bw.close();
System.out.println("Now you can read content from files...");
cdl.countDown();
return null;
}
}
class ForLoop2 implements Callable<Object> {
CountDownLatch cdl;
public ForLoop2(CountDownLatch cdl){
this.cdl=cdl;
}
@Override
public Object call() throws Exception {
cdl.await();
System.out.println("Okay i am now going to read content of files...");
BufferedReader br = new BufferedReader(new FileReader(new File("/home/f.txt")));
String str;
System.out.println("I am done with reading.....");
while ((str = br.readLine()) != null) {
System.out.println(str);
}
return null;
}
}
我们有什么办法可以创造这样的东西吗?提前谢谢。
答案 0 :(得分:3)
一种简单的方法,就像Shopify上的sort
无法使用值best-seller
一样,就是创建一个名为(例如)畅销书您拥有所有产品的地方(如果适用于您的商店,您可以设定产品价格大于0美元的唯一条件)。
然后,将该集合排序设置为管理信息中心上的By best selling
。
最后,按照以下类似的方式使用Liquid:
<div class="row">
{% for product in collections.best-sellers.products | limit:12 %}
{% include 'product-grid-item' with "all" %}
{% endfor %}
</div>