如何编写查询来显示所有产品?

时间:2016-07-09 11:04:17

标签: magento-1.7

我想更新所有产品的价格。为此,我想获取所有记录,然后在Magento中更新产品。

$ product = Mage :: getModel('catalog / product');

1 个答案:

答案 0 :(得分:0)

public static String prepareTemplate(HashMap<String, String> documentContentHashmap,String templateLocation) throws NamingException{
    System.out.println("Document Contents :"+documentContentHashmap);
    ArrayList documentList=new ArrayList();
    documentList.add(documentContentHashmap);
    System.out.println(documentList);
    String templatePath=templateLocation.replaceAll("\\\\","/");
    String[] splittedTemplatePath = templatePath.split("/");
    String templateName=splittedTemplatePath[splittedTemplatePath.length-1];
    VelocityEngine ve = new VelocityEngine();
    Properties properties = new Properties();
    properties.setProperty("resource.loader","file");
    properties.setProperty("file.resource.loader.class", "org.apache.velocity.runtime.resource.loader.FileResourceLoader");
    properties.setProperty("file.resource.loader.path", templatePath.substring(0, templatePath.lastIndexOf("/"))+"/");           
    properties.setProperty("file.resource.loader.cache", "false");
    properties.setProperty("file.resource.loader.modificationCheckInterval", "0");
    ve.init(properties);
    Template t = ve.getTemplate(templateName);
    VelocityContext context = new VelocityContext();
    //for (Entry<String, String> entry : documentContentHashmap.entrySet()) {
        //context.put(entry.getKey(), entry.getValue());
    //}
    context.put("documentList", documentList);
    StringWriter writer = new StringWriter();
    t.merge( context, writer );
    System.out.println("writer"+writer);
    String documentBytes=generateDocument(writer);
    if(documentBytes!=null){
        return documentBytes;
    }else{
        return null;
    }
}

这将帮助您更新所有产品的价格..