/** * Create promotion. * * @param promotionName * @param code * @param ruleSet we have to know what kind of promotion need to be created * @return rule */ private Rule createPromotion( final String promotionName, final String code, final RuleSet ruleSet, final boolean couponEnabled) { final Rule promotionRule = beanFactory.getBean(ContextIdNames.PROMOTION_RULE); promotionRule.setRuleSet(ruleSet); promotionRule.initialize(); if (ruleSet.getScenario() == RuleScenarios.CATALOG_BROWSE_SCENARIO) { // shopping cart scenario must use selling context for set the date ranges promotionRule.setStartDate(new Date()); } promotionRule.setCmUser(tac.getPersistersFactory().getStoreTestPersister().getCmUser()); promotionRule.setName(promotionName); if (code != null) { promotionRule.setCode(code); } promotionRule.setCouponEnabled(couponEnabled); promotionRule.setEnabled(true); promotionRule.setDescription( "Simple shopping cart promotion rule: discount for the given product sku"); return promotionRule; }
/** * Creates and persists a simple (10% off subtotal) shopping cart promotion. * * @param promotionName the name of the promotion * @param storeCode the store code * @param code the promoCode (not coupon code) * @param couponEnabled whether the promo is coupon enabled * @return rule */ public Rule createAndPersistSimpleShoppingCartPromotion( final String promotionName, final String storeCode, final String code, final boolean couponEnabled) { RuleParameter param = beanFactory.getBean(ContextIdNames.RULE_PARAMETER); param.setKey(RuleParameter.DISCOUNT_PERCENT_KEY); param.setValue("10"); RuleAction action = beanFactory.getBean(ContextIdNames.CART_SUBTOTAL_PERCENT_DISCOUNT_ACTION); action.getParameters().clear(); action.addParameter(param); Rule rule = createShoppingCartPromotion(promotionName, storeCode, code, couponEnabled); rule.addAction(action); return persistPromotionRule(rule); }
/** * Promotion test persister constructor. * * @param beanFactory the bean factory */ public PromotionTestPersister(final BeanFactory beanFactory) { this.beanFactory = beanFactory; tac = beanFactory.getBean("testApplicationContext"); ruleService = beanFactory.getBean(ContextIdNames.RULE_SERVICE); ruleSetService = beanFactory.getBean(ContextIdNames.RULE_SET_SERVICE); storeService = beanFactory.getBean(ContextIdNames.STORE_SERVICE); catalogService = beanFactory.getBean(ContextIdNames.CATALOG_SERVICE); sellingContextService = beanFactory.getBean(ContextIdNames.SELLING_CONTEXT_SERVICE); tagConditionService = beanFactory.getBean(ContextIdNames.TAG_CONDITION_SERVICE); ruleEngine = beanFactory.getBean("epRuleEngine"); ruleEngine.resetRuleBaseCache(); }
private HttpServletRequestResponseFacade createRequestResponseFacade( final ServletRequest inRequest, final ServletResponse inResponse) { if (!(inRequest instanceof HttpServletRequest)) { throw new IllegalArgumentException("ServletRequest must be instance of HttpServletRequest"); } if (!(inResponse instanceof HttpServletResponse)) { throw new IllegalArgumentException("ServletResponse must be instance of HttpServletResponse"); } final HttpServletRequest request = (HttpServletRequest) inRequest; final HttpServletResponse response = (HttpServletResponse) inResponse; final HttpServletFacadeFactory httpServletFacadeFactory = beanFactory.getBean("httpServletFacadeFactory"); return httpServletFacadeFactory.createRequestResponseFacade(request, response); }
/** * Convenience method for getting a bean instance. * * @param <T> the type of bean to return * @param beanName the name of the bean to get and instance of. * @return an instance of the requested bean. */ public <T> T getBean(final String beanName) { return beanFactory.<T>getBean(beanName); }