ugurhalil.com Open in urlscan Pro
46.17.175.25  Public Scan

URL: https://ugurhalil.com/promotion-condition-and-action/
Submission: On October 12 via manual from IN — Scanned from DE

Form analysis 2 forms found in the DOM

POST https://ugurhalil.com/wp-comments-post.php

<form action="https://ugurhalil.com/wp-comments-post.php" method="post" id="commentform" class="comment-form" novalidate="">
  <p class="comment-notes"><span id="email-notes">E-posta hesabınız yayımlanmayacak.</span> Gerekli alanlar <span class="required">*</span> ile işaretlenmişlerdir</p>
  <p class="comment-form-comment"><label for="comment">Comment:<span class="required">*</span></label><textarea id="comment" name="comment" cols="45" rows="5" aria-required="true"></textarea></p>
  <p class="comment-form-author"><label for="author">Name:<span class="required">*</span></label><input id="author" name="author" type="text" value="" size="30"></p>
  <p class="comment-form-email"><label for="email">Email Address:<span class="required">*</span></label><input id="email" name="email" type="text" value="" size="30"></p>
  <p class="comment-form-url"><label for="url">Website:</label><input id="url" name="url" type="text" value="" size="30"></p>
  <p class="comment-form-cookies-consent"><input id="wp-comment-cookies-consent" name="wp-comment-cookies-consent" type="checkbox" value="yes"><label for="wp-comment-cookies-consent">Save my name, email, and website in this browser for the next time
      I comment.</label></p>
  <p class="form-submit"><input name="submit" type="submit" id="submit" class="submit" value="Add Comment"> <input type="hidden" name="comment_post_ID" value="69" id="comment_post_ID"> <input type="hidden" name="comment_parent" id="comment_parent"
      value="0"></p>
</form>

GET https://ugurhalil.com

<form method="get" id="searchform" class="search-form" action="https://ugurhalil.com" _lpchecked="1">
  <fieldset> <input type="text" name="s" id="s" value="Search this site..." onblur="if (this.value == '') {this.value = 'Search this site...';}" onfocus="if (this.value == 'Search this site...') {this.value = '';}"> <input type="submit"
      value="Search"></fieldset>
</form>

Text Content

Skip to content


HALIL UĞUR

Yazılım; yaşam ve düşünce tarzıdır.
Menu
 * Java
 * Hybris
 * Ağ (Network)
 * Diyagramlar
 * Data Creator




19/03/2020
HomeHybrisHow to create custom promotion?


HOW TO CREATE CUSTOM PROMOTION?

By Halil UĞUR Hybris  0 Comments
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 in line with their sales targets.

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 link.

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.

FOLLOW LIST FOR CREATE A SPECIAL PROMOTION

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

LET’S CREATE ONE PROBLEM ABOUT PROMOTION

The promotion is activated when there is “happy birthday” 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.

WE CREATE CONDITION CLASS

public class RuleQualifyingSearchedWordConditionTranslator implements RuleConditionTranslator {

    private final String SEARCHED_WORD = "searchedWord";

    @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<>());
                ruleIrGroupCondition.getChildren().add(ruleIrAttributeCondition);
                return ruleIrGroupCondition;
            }
        } catch (Exception ex) {
            LOG.error(ex);
            throw ex;
        }
        return new RuleIrFalseCondition();
    }
}


WE CREATE ACTION CLASS

public class RuleSearchedWordAddScoreAction implements RuleExecutableAction {

    @Override
    public void executeAction(final RuleActionContext context, final Map<String, Object> parameters) throws RuleEvaluationException {

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

        Optional<OrderEntryRAO> orderEntry = cartRAO.getEntries()
                .stream()
                .filter(orderEntryRAO -> orderEntryRAO.getProduct().getDescription().equalsIgnoreCase(value))
                .findFirst();

        orderEntry.ifPresent(orderEntryRAO -> 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;
    }
}

WE WRITE IMPEX FILE

$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->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 ;

See you in our next post.

Tags:create custom promotion, hybris, promotion, promotion action, promotion
condition


RELATED POSTS

HYBRIS DOSYA YAPISI, EXTENSION OLUŞTURMA: BÖLÜM 2

HYBRIS NEDIR VE NASIL KURULUR : BÖLÜM 1

ABOUT AUTHOR

HALIL UĞUR



ADD A COMMENT

Cevabı iptal et

E-posta hesabınız yayımlanmayacak. Gerekli alanlar * ile işaretlenmişlerdir

Comment:*

Name:*

Email Address:*

Website:

Save my name, email, and website in this browser for the next time I comment.




KATEGORILER

 * Ağ (Network) (5)
 * Diyagramlar (1)
 * Genel (1)
 * Hybris (3)


ARŞIVLER

 * Ağustos 2020 (1)
 * Temmuz 2020 (1)
 * Mart 2020 (2)
 * Şubat 2020 (5)


SON YAZILAR

 * Hybris Dosya Yapısı, Extension Oluşturma: Bölüm 2
 * Hybris Nedir ve Nasıl Kurulur : Bölüm 1
 * Diyagramlar ve Ödeme Sistemi Diyagramı
 * How to create custom promotion?
 * TFTP ile Router Yedekleme ve Geri Yükleme

Halil UĞUR Copyright © 2021.
Back to Top ↑