Zurmo subscribe to marketing list workflow with products

Zurmo subscribe to marketing list workflow with products

Yes, that’s right! Another installment about Zurmo. This time I’ll discuss an interesting feature about Zurmo: you can create a workflow that automatically subscribes your zurmo CRM contacts to a certain marketing list, based on some triggers. So, how to create this subscribe to marketing list workflow with products functionality?

The problem with current workflows

The problem is you can currently (3.0.2) only subscribe contacts based on the contacts model! This means my usecase didn’t work without some sourcecode modification.

My subscribe to marketing list usecase

If a product enters the closed: won stage, I’d like to automatically subscribe the contact, related to this product, to a certain marketing list.

Currently, the workflow code checks if the current model is an instance of the Contact model and FAILS on everything else. This is annoying, so let’s fix this. Go to the following file:

/path/to/zurmo/app/protected/modules/workflows/utils/WorkflowActionProcessingHelper.php

In this file, locate the processSubscribeToListAction() function, and locate this chunk of code:

if (count($actionAttributes) > 1 ||
!isset($actionAttributes[‘marketingList’]) ||
!$this->triggeredModel instanceof Contact)
{
throw new NotSupportedException();
}

If you can read a little bit of code, it should be obvious that it’s checking if the instance of the triggered model is a Contact. The reason is simple: only contacts can be subscribed to marketing lists, naturally. But we are now passing the Product model instead! That’s why we’ll get a notsupportedException and no subscription will occur. So how to fix this?

Easy: just make sure that zurmo is working with the Contact that’s related to the Product instead of the Product itself! This is how I did it. I changed to chunk of code to this:

  if (count($actionAttributes) > 1 ||
!isset($actionAttributes[‘marketingList’]) ||
!$this->triggeredModel instanceof Contact)
{
//hack to make products/contacts able to subscribe to list
//removed: throw new NotSupportedException();
//added:
if($this->triggeredModel instanceof Product && $this->triggeredModel->contact)
{
$this->triggeredModel = $this->triggeredModel->contact;
}else
{
throw new NotSupportedException();
}
// end of hack
}

As you can see, I moved the NotSupportedException to a next step and added another check: if we’re dealing with a Product instead of a Contact, just load the Product’s related Contact instead (triggeredModel becomes triggeredModel->contact). Now zurmo’s happy because it can successfully subscribe the Contact to the marketing list!

Hope this helps guys. This is how to subscribe to marketing list workflow with products instead of contacts. Don’t forget to check this modified file every time you perform an upgrade to a newer version because the upgrade process will ignore your changes! You’ll have to include this hack every time until the devs decide that they want to include this functionality themselves!

Good luck and let me know in the comments below if you run into problems or if you have any suggestions. Enjoy your automated life!

Laurens (7 Posts)

Laurens Vercaigne is an IT-consultant, web developer, programmer and copywriter with profound expertise of both Linux and Windows environments. He has experience in developing and optimizing trading scripts and robots for forex- and stockmarkets. There is also a lot of fun to be had with automating as much as possible, or making tasks and processes more efficient, practical of just smart. After all, computers are here to make our lives easier, aren't they?


  •  
  •  
  •  
  •  
  •  

Leave a Reply