<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>promotion &#8211; Halil UĞUR</title>
	<atom:link href="https://ugurhalil.com/tag/promotion/feed/" rel="self" type="application/rss+xml" />
	<link>https://ugurhalil.com</link>
	<description>Yazılım; yaşam ve düşünce tarzıdır.</description>
	<lastBuildDate>Wed, 27 Jul 2022 23:45:12 +0000</lastBuildDate>
	<language>tr</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=5.3.2</generator>

<image>
	<url>https://ugurhalil.com/wp-content/uploads/2020/08/HuLogoRGB256-150x150.png</url>
	<title>promotion &#8211; Halil UĞUR</title>
	<link>https://ugurhalil.com</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>How to create custom promotion?</title>
		<link>https://ugurhalil.com/promotion-condition-and-action/</link>
				<pubDate>Thu, 19 Mar 2020 14:20:22 +0000</pubDate>
		<dc:creator><![CDATA[Halil UĞUR]]></dc:creator>
				<category><![CDATA[Hybris]]></category>
		<category><![CDATA[create custom promotion]]></category>
		<category><![CDATA[hybris]]></category>
		<category><![CDATA[promotion]]></category>
		<category><![CDATA[promotion action]]></category>
		<category><![CDATA[promotion condition]]></category>

		<guid isPermaLink="false">http://ugurhalil.com/?p=69</guid>
				<description><![CDATA[<p>Create customer-promoting promotions. Promotion is an effective promotion tool used by companies to promote themselves and market their products. It comes from the word promotion in French. Encouragement in Turkish is encouragement. While products such as watches, agendas, key rings and pens are generally used, personal products can also be offered to customers as promotions [...]</p>
<p>The post <a rel="nofollow" href="https://ugurhalil.com/promotion-condition-and-action/">How to create custom promotion?</a> appeared first on <a rel="nofollow" href="https://ugurhalil.com">Halil UĞUR</a>.</p>
]]></description>
								<content:encoded><![CDATA[
<div class="wp-block-image"><figure class="aligncenter size-large"><img src="http://ugurhalil.com/wp-content/uploads/2020/03/stockvault-online-shopping-laptop-to-shopping-cart185859-1024x744.jpg" alt="How to create custom promotion?" class="wp-image-95" srcset="https://ugurhalil.com/wp-content/uploads/2020/03/stockvault-online-shopping-laptop-to-shopping-cart185859-1024x744.jpg 1024w, https://ugurhalil.com/wp-content/uploads/2020/03/stockvault-online-shopping-laptop-to-shopping-cart185859-300x218.jpg 300w, https://ugurhalil.com/wp-content/uploads/2020/03/stockvault-online-shopping-laptop-to-shopping-cart185859-768x558.jpg 768w, https://ugurhalil.com/wp-content/uploads/2020/03/stockvault-online-shopping-laptop-to-shopping-cart185859-1536x1116.jpg 1536w, https://ugurhalil.com/wp-content/uploads/2020/03/stockvault-online-shopping-laptop-to-shopping-cart185859-2048x1488.jpg 2048w" sizes="(max-width: 1024px) 100vw, 1024px" /><figcaption>Create customer-promoting promotions.</figcaption></figure></div>



<p>Promotion is an effective promotion tool used by companies to promote themselves and market their products. It comes from the word promotion in French. Encouragement in Turkish is encouragement. While products such as watches, agendas, key rings and pens are generally used, personal products can also be offered to customers as promotions in line with their sales targets. </p>



<span id="more-69"></span>



<p>In this context, there are many ways to create promotions on Hybris. Order discount, gift product, coupon identification etc. If you do not know how to use the promotions, you can get some information from this <a href="https://www.acorel.nl/2018/01/sap-hybris-commerce-promotion-engine/">link.</a></p>



<p>When creating a promotion, we sometimes ask that it take different actions as a result of certain conditions. We will see how we can accomplish this. First, I share the list below to see what we will do step by step.</p>



<h4>Follow List for Create a Special Promotion</h4>



<ol><li>We determine the condition of the promotion. (existing conditions may be useless.)</li><li>We determine the action we want to perform as a result of the condition. (existing actions may not be useless)</li><li>We are creating a new class with a contingent name that we will create.<ul><li>We implement the <strong><em>RuleConditionTranslator</em></strong> interface class to the created class.</li><li>We define the parameter to be used in the condition as fixed.</li><li>We fill the translate method according to the desired condition.</li></ul></li><li>We create a new class suitable for the action that will occur as a result of the condition.<ul><li>We implement the <strong><em>RuleExecutableAction</em></strong> interface class into the created class.</li><li>We fill the <em>executeAction</em> method according to the desired action.</li><li>Writing impex file.</li></ul></li></ol>



<h4>Let&#8217;s create one problem about promotion</h4>



<p>The promotion is activated when there is &#8220;happy birthday&#8221; text in the product description. When the promotion is activated, add a 50 percent discount to the order. So I want create so special condition and action.</p>



<h4>We create <strong><em>Condition</em></strong> class</h4>



<div class="hcb_wrap"><pre class="prism line-numbers lang-java" data-lang="Java"><code>public class RuleQualifyingSearchedWordConditionTranslator implements RuleConditionTranslator {

    private final String SEARCHED_WORD = &quot;searchedWord&quot;;

    @Override
    public RuleIrCondition translate(RuleCompilerContext context, RuleConditionData condition, RuleConditionDefinitionData conditionDefinition) throws RuleCompilerException {
        try {
            RuleParameterData searchedWord = condition.getParameters().get(SEARCHED_WORD);
            if (searchedWord != null) {
                String word = searchedWord.getValue();

                final String cartRAOVariable = context.generateVariable(CartRAO.class);

                final RuleIrAttributeCondition ruleIrAttributeCondition = new RuleIrAttributeCondition();
                ruleIrAttributeCondition.setVariable(cartRAOVariable);
                ruleIrAttributeCondition.setOperator(RuleIrAttributeOperator.CONTAINS);
                ruleIrAttributeCondition.setAttribute(SEARCHED_WORD);
                ruleIrAttributeCondition.setValue(word);

                final RuleIrGroupCondition ruleIrGroupCondition = new RuleIrGroupCondition();
                ruleIrGroupCondition.setOperator(RuleIrGroupOperator.AND);
                ruleIrGroupCondition.setChildren(new ArrayList&lt;&gt;());
                ruleIrGroupCondition.getChildren().add(ruleIrAttributeCondition);
                return ruleIrGroupCondition;
            }
        } catch (Exception ex) {
            LOG.error(ex);
            throw ex;
        }
        return new RuleIrFalseCondition();
    }
}
</code></pre></div>



<h4>We create <strong><em>Action</em></strong> class</h4>



<div class="hcb_wrap"><pre class="prism line-numbers lang-java" data-lang="Java"><code>public class RuleSearchedWordAddScoreAction implements RuleExecutableAction {

    @Override
    public void executeAction(final RuleActionContext context, final Map&lt;String, Object&gt; parameters) throws RuleEvaluationException {

        final String value = (String) parameters.get(&quot;value&quot;);
        final RuleEngineResultRAO result = context.getValue(RuleEngineResultRAO.class);
        final CartRAO cartRAO = context.getValue(CartRAO.class);

        Optional&lt;OrderEntryRAO&gt; orderEntry = cartRAO.getEntries()
                .stream()
                .filter(orderEntryRAO -&gt; orderEntryRAO.getProduct().getDescription().equalsIgnoreCase(value))
                .findFirst();

        orderEntry.ifPresent(orderEntryRAO -&gt; this.addOrderEntryDiscountRAOAction.addOrderEntryLevelDiscount(orderEntryRAO, false, value, result, context.getDelegate()));
    }

    public AddOrderEntryDiscountRAOAction getAddOrderEntryDiscountRAOAction() {
        return this.addOrderEntryDiscountRAOAction;
    }

    @Required
    public void setAddOrderEntryDiscountRAOAction(final AddOrderEntryDiscountRAOAction addOrderEntryDiscountRAOAction) {
        this.addOrderEntryDiscountRAOAction = addOrderEntryDiscountRAOAction;
    }
}</code></pre></div>



<h4>We Write Impex File</h4>



<div class="hcb_wrap"><pre class="prism line-numbers lang-impex" data-lang="Impex"><code>$lang = en
$trLang = tr

############################# CONDITIONS ##########################

INSERT_UPDATE RuleConditionDefinitionCategory; id[unique = true]; name[lang = $lang]; name[lang = $trLang]; priority
                                             ; general              ; general               ; general                 ; 1250

INSERT_UPDATE RuleConditionDefinition; id[unique = true]                        ; name[lang = $lang]               ; name[lang = $trLang]             ; priority; breadcrumb[lang = $lang]                                     ; breadcrumb[lang = $trLang]                                   ; allowsChildren; translatorId                                               ; translatorParameters; categories(id)
                                     ; y_qualifying_searchedWord            ; Searched Word              ; Searched Word             ; 1111    ; Searched Word                                          ; How Many Passenger?                                          ; false         ; ruleQualifyingSearchedWordConditionTranslator          ;                     ; ido

INSERT_UPDATE RuleConditionDefinitionParameter; definition(id)[unique = true]          ; id[unique = true]   ; priority; name[lang = $lang]            ; name[lang = $trLang]          ; description[lang = $lang]                                                           ; description[lang = $trLang]                                                         ; type                                                        ; value              ; required[default = true]; validators;
                                              ; y_qualifying_searchedWord          ; searchedWord    ; 1111    ; Searched Word            ; Searched Word            ; Searched Word                                                                  ; Searched Word                                                                  ; java.lang.Integer                                           ;                    ; true                    ;

INSERT_UPDATE RuleConditionDefinitionRuleTypeMapping; definition(id)[unique = true]            ; ruleType(code)[unique = true]
                                                    ; y_qualifying_searchedWord            ; PromotionSourceRule


############################## Actions ###########################

INSERT_UPDATE RuleActionDefinition; id[unique = true]                          ; name[lang = $lang]                               ; name[lang = $trLang]                             ; priority; breadcrumb[lang = $lang]                                             ; breadcrumb[lang = $trLang]                                           ; translatorId                   ; translatorParameters                                         ; categories(id)
                                  ; searched_word_percentage_discount ; Percentage discount by the word   ; Percentage discount by the word   ; 1400    ; Apply {value} discount by the word                    ; Apply {value} discount by the word                    ; ruleExecutableActionTranslator ; actionId-&gt;ruleSearchedWordAddScoreAction       ; general


INSERT_UPDATE RuleActionDefinitionParameter; definition(id)[unique = true]              ; id[unique = true]; priority; name[lang = $lang]        ; name[lang = $trLang]      ; description[lang = $lang]                                                          ; description[lang = $trLang]                                                        ; type                                         ; value; required[default = true]; validators
                                           ; searched_word_percentage_discount ; value            ; 1000    ; Percentage discount value ; Percentage discount value ; Percentage discount that will be applied by the word                ; Percentage discount that will be applied by the word                ; java.lang.String                         ;      ;                         ; rulePercentageParameterValidator

INSERT_UPDATE RuleActionDefinitionRuleTypeMapping; definition(id)[unique = true]              ; ruleType(code)[default = PromotionSourceRule][unique = true]
                                                 ; searched_word_percentage_discount ;</code></pre></div>



<p>See you in our next post.</p>
<p>The post <a rel="nofollow" href="https://ugurhalil.com/promotion-condition-and-action/">How to create custom promotion?</a> appeared first on <a rel="nofollow" href="https://ugurhalil.com">Halil UĞUR</a>.</p>
]]></content:encoded>
										</item>
	</channel>
</rss>
