Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 5.3

...

The purpose of this campaign is to send out coupons every Sunday night to customers who have ordered in the past week. (You'll see references to 8 days below. I added a day to give a little overlap.)

Step Layout

These are the steps laid out for you. The logic steps are detailed below.

...

Code Block
languagenone
themeConfluence
linenumberstrue
#if( $dateManager.isCurrentTimeBetween("Sun", "18:00", "Sun", "23:59"))
   #set( $result = 'OrderedInLast8Days?' )
#else
   #set( $result = 'Pause1Hour' )
#end

OrderedInLast8Days?

There's two ways to determine if a customer has ordered in the past 8 days.

...

The Long Painful Way

...

Code Block
themeDJango
linenumberstrue
$logger.log($customer.orders.size())
#set( $hasOrdered = false )

#set( $sevenDaysAgo = $dateManager.currentTime())
$sevenDaysAgo.add("day", -7)
$logger.log($sevenDaysAgo.format("MM/dd/yyyy"))

#foreach( $order in $customer.orders )
   $logger.log($order.orderId)
   $logger.log($order.paymentDate.time)

   #if($order.paymentDate.time > $sevenDaysAgo.timeInMillis)
      $logger.log('order was within 8 days')
      #set( $hasOrdered = true )
   #else
      $logger.log('order was NOT within 8 days')
   #end
#end

#if($hasOrdered)
   #set( $result = 'DidOrder' )
#else
   #set( $result = 'DidNotOrder' )
#end

...

  • Line 1: A log statement to see if this customer has placed any orders. A good thing to know, yes?
  • Line 2: create a flag variable and set it to false.
  • Line 4: I need a variable to check the payment dates against. So initialize a date variable. At first, it points to 'now'.
  • Line 5: move the date variable back 7 days
  • Line 14: If the payment date was within the last seven days, set the flag variable to true. (Could probably break out of the for-loop here...)
  • Line 20: If they have ordered, direct them to the 'DidOrder' step, otherwise, send them to the 'DidNotOrder' step.
Info

The code block above makes liberal use of the $logger.log() function. This will print out any velocity object. This is an invaluable tool for developing logic blocks. It won't hurt to keep it in place for production runs.


...

The Better Way

...

Code Block
themeDJango
linenumberstrue
#if($customer.hasPurchasedInLastDays(8))
   #set( $result = 'DidOrder' )
#else
   #set( $result = 'DidNotOrder' )
#end
Info
The code block above makes liberal use of the $logger.log() function. This will print out any velocity object. This is an invaluable tool for developing logic blocks. It won't hurt to keep it in place for production runs.


Goto Logic Blocks

Code Block
themeDJango
linenumberstrue
#set( $result = '_GOTO_:IsItSundayNight?' )

...