2017-04-05 52 views
0

我们有一个新属性(特殊??)需要添加到产品中。只有一些产品具有该属性的值为真。所有其他人都认为这个价值是假的。Hybris属于产品组

如果我们在创造一个产品级别属性....总要有人去,并在后台....这是太辛苦了手动设置值的所有产品..

任何更好的方法来处理这个问题?......我们可以为产品子集创建一个产品组,然后在该组级别设置该属性?使成为保养的方便......

回答

0

有您可以考虑几个选择: 您可以用默认值false声明对产品项目级属性:

  <attribute qualifier="myAttribute" type="java.lang.Boolean"> 
       <description>what it dodes</description> 
       <persistence type="property" /> 
       <defaultvalue>Boolean.FALSE</defaultvalue> 
      </attribute> 

这将保证对每个新创建的产品默认值都是false。 请注意,这不会将false值设置为任何现有实例。 如果您将此属性添加到现有系统(例如,作为迁移的一部分),您可以在你的代码中将空值视为假,或者你可以编写一个beanshell脚本作为迁移的一部分执行一次,该迁移将更新所有值仍然为空的产品(请参阅http://experts.hybris.com/answers/3446/view.html)。

复制/从上采用hybris专家论坛,链接答案修改(但没有测试:)):

import de.hybris.platform.jalo.SearchResult; 
import de.hybris.platform.jalo.product.Product; 
import java.util.Collections; 
SearchResult products = de.hybris.platform.jalo.flexiblesearch.FlexibleSearch.getInstance().search("select {PK} from {Product} where {myAttribute} IS NULL", Collections.emptyMap(), Customer.class); 
int updatedCnt = 0; 
for (Product product : products.getResult()) 
{ 
    try 
    { 
     product.setAttribute("myAttribute", false); 
     updatedCnt++; 
    } catch (Exception e) 
    { 
     System.out.println("failed to update product " + product.getPK() + " " + e.getMessage()); 
    } 
} 
System.out.println("number updated = " + java.lang.Integer.toString(updatedCnt)); 

请注意,您仍然需要一些自定义逻辑值设置为true你的产品希望这个归属是真实的(除非这只是通过后台手动完成的)。

希望这会有帮助, Sebastian