Tuesday 30 October 2018

Backoffice Customization in Hybris


Requirement:-

* Add StandardCurrency attribute to the list view.
* StandardCurrency attribute have ISO code[USD] only, you need to add currency symbol to ISO code. [$USD]
* For the above requirement, we have to write renderer class to combine ISO code and currency symbol.

Follow the below steps to achieve above requirement,



Step 1:-
/trainingbackoffice/resources/trainingbackoffice-backoffice-config.xml



<context type="Customer" component="advanced-search" merge-by="type" parent="User">
<advanced-search:advanced-search>
    <advanced-search:field-list>
          <advanced-search:field name="Europe1PriceFactory_UPG" selected="true" operator="startsWith"/>
    </advanced-search:field-list>
</advanced-search:advanced-search>
</context>

<context merge-by="type" parent="User" type="Customer" component="listview" merge-mode="append">
<list-view:list-view>
       <list-view:column qualifier="sessionCurrency" spring-bean="trainingListViewRenderer"/>
</list-view:list-view>

</context>


Step 2:-
            Create class in backoffice/src folder.
/trainingbackoffice/backoffice/src/org/training/provider/TrainingCurrencyListViewRenderer.java

/**
 *
 */
package org.training.provider;

import de.hybris.platform.core.model.c2l.CurrencyModel;
import de.hybris.platform.core.model.user.CustomerModel;
import de.hybris.platform.util.Config;

import java.util.Objects;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.zkoss.zul.Label;
import org.zkoss.zul.Listcell;

import com.hybris.cockpitng.core.config.impl.jaxb.listview.ListColumn;
import com.hybris.cockpitng.dataaccess.facades.type.DataType;
import com.hybris.cockpitng.engine.WidgetInstanceManager;
import com.hybris.cockpitng.util.UITools;
import com.hybris.cockpitng.widgets.common.AbstractWidgetComponentRenderer;


/**
 * @author
 *
 */
public class TrainingCurrencyListViewRenderer extends AbstractWidgetComponentRenderer<Listcell, ListColumn, Object>
{
//private static final String CSS_CELL_LABEL = "yw-listview-cell-label";
private static final Logger LOG = LoggerFactory.getLogger(TrainingCurrencyListViewRenderer.class);

@SuppressWarnings("deprecation")
@Override
public void render(final Listcell parent, final ListColumn configuration, final Object object, final DataType dataType,
final WidgetInstanceManager widgetInstanceManager)
{
CurrencyModel currency = null;
if (object instanceof CustomerModel) //checking whether object is of type CustomerModel or not
{
final CustomerModel discount = (CustomerModel) object; //assigning object to customermodel
if (Objects.isNull(discount.getSessionCurrency()))
{
currency = new CurrencyModel(Config.getParameter("training.currency.iso"),
Config.getParameter("training.currency.symbol"));

}
else
{
currency = discount.getSessionCurrency();
}
}

else
{
LOG.warn("Passed object: [{}] is not of supported type", Objects.toString(object));
}


this.renderComponents(parent, configuration, object, currency);

}
protected void renderComponents(final Listcell parent, final ListColumn configuration, final Object object,
final CurrencyModel currency)
{
String labelText = null;
if (currency.getIsocode() != null && currency.getSymbol() != null)
{
labelText = currency.getSymbol() + currency.getIsocode();
}
final Label label = new Label(labelText);
UITools.modifySClass(label, "yw-listview-cell-label", true);
label.setAttribute("hyperlink-candidate", Boolean.TRUE);
parent.appendChild(label);
this.fireComponentRendered(label, parent, configuration, object);
this.fireComponentRendered(parent, configuration, object);
}

}




Step 3:- Configure this class.
/trainingbackoffice/resources/trainingbackoffice-backoffice-spring.xml


 <alias name="trainingCurrencyListViewRenderer" alias="trainingListViewRenderer"/>
    <bean id="trainingCurrencyListViewRenderer" class="org.training.provider.TrainingCurrencyListViewRenderer">
    </bean>

Step 4:-  Place below properties in local.properties file.


training.currency.iso=USD
training.currency.symbol=$


Step 5:- Do ant all & update the system.







Backoffice, backoffice customization,rendarer class in hybris,backoffice customization using renderer class.