Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature #155571 feat: Sendy Techjoomla Integration Plugin #1

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions tjsendy/language/en-GB/en-GB.plg_rdmedia_tjsendy.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
PLG_RDMEDIA_TJSENDY="Tj- Sendy"
PLG_RDMEDIA_SENDY_XML_DESCRIPTION="This plugin used to add subscribe users in the sendy list"
PLG_TJSENDY_API_KEY="API Key"
PLG_TJSENDY_API_KEY_DESC="Enter your API Key, available in Settings"
PLG_TJSENDY_SENDY_URL="Sendy Url"
PLG_TJSENDY_ID_FIELD="List ID field"
PLG_TJSENDY_PRODUCT_CATEGORY="Select category"
PLG_TJSENDY_LIST_ID="Sendy list id"
PLG_TJSENDY_ERROR="Plugin Tj-Sendy Error: %s"
2 changes: 2 additions & 0 deletions tjsendy/language/en-GB/en-GB.plg_rdmedia_tjsendy.sys.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
PLG_RDMEDIA_TJSENDY="Tj- Sendy"
PLG_RDMEDIA_SENDY_XML_DESCRIPTION="This plugin used to add subscribe users in the sendy list"
114 changes: 114 additions & 0 deletions tjsendy/tjsendy.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
<?php
/**
* @package Tjsendy
* @author Techjoomla <[email protected]>
* @copyright Copyright (c) 2009-2020 TechJoomla. All rights reserved.
* @license GNU General Public License version 2 or later.
*/

defined('_JEXEC') or die();

use Joomla\CMS\Http\HttpFactory;
use Joomla\CMS\Factory;
use Joomla\CMS\Language\Text;

jimport('joomla.event.plugin');

/**
* Plug-in to save subscriber to sendy list
*
* @since __DEPLOY_VERSION__
*/
class PlgRDMediaTjsendy extends JPlugin
{
/**
* Load the language file on instantiation.
*
* @var boolean
* @since __DEPLOY_VERSION__
*/
protected $autoloadLanguage = true;

/**
* Runs after process subscription
*
* @param array $data An array containing the data of order.
*
* @return void
*
* @since __DEPLOY_VERSION__
*/
public function onAfterProcessSubscription($data)
{
$productCat = $this->getCategory($data['product_id']);
$user = Factory::getUser($data['userid']);

foreach ($this->params['field-name'] as $value)
{
$lists[] = $value;
}

foreach ($lists as $list)
{
$array[$list->category] = $list->listid;
}

$this->subscribeUser($user, $array[$productCat]);
}

/**
* function to get product category id
*
* @param integer $productId product id.
*
* @return integer category id
*
* @since __DEPLOY_VERSION__
*/
public function getCategory($productId)
{
$db = Factory::getDbo();

$query = $db->getQuery(true)
->select('category_id')
->from($db->quoteName('#__rd_subs_product2category'))
->where($db->quoteName('product_id') . ' = ' . (int) $productId);

$db->setQuery($query);

return $db->loadResult();
}

/**
* function to add subscribe user in sendy
*
* @param object $user user data.
*
* @param integer $listId sendy list id.
*
* @return string
*
* @since __DEPLOY_VERSION__
*/
public function subscribeUser($user, $listId)
{
try
{
$http = HttpFactory::getHttp();
$data = array();
$data['api_key'] = $this->params['api_key'];
$data['name'] = $user->name;
$data['email'] = $user->email;
$data['list'] = $listId;
$data['boolean'] = 'true';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check the sendy subscribe API, There are a few more attributes that can be set.

  • country
  • IP

In addition, to this we also need to be able to populate custom fields in Sendy. Can you propose how this can be done ?

cc @manojLondhe @ankush-maherwal


$return = $http->post($this->params['sendy_url'] . '/subscribe', $data);
}
catch (Exception $e)
{
JError::raiseWarning(500, Text::sprintf('PLG_TJSENDY_ERROR', $e->getMessage()));

return;
}
}
}
55 changes: 55 additions & 0 deletions tjsendy/tjsendy.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?xml version="1.0" encoding="utf-8"?>
<extension version="3.1" type="plugin" group="rdmedia" method="upgrade">
<name>plg_rdmedia_tjsendy</name>
<author>Techjoomla</author>
<creationDate>18th Octobar 2019</creationDate>
<copyright>Copyright (C) 2009 - 2020 Techjoomla. All rights reserved.</copyright>
<license>http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL</license>
<authorEmail>[email protected]</authorEmail>
<authorUrl>https://techjoomla.com</authorUrl>
<version>1.0.0</version>
<description>PLG_RDMEDIA_SENDY_XML_DESCRIPTION</description>
<files>
<filename plugin="tjsendy">tjsendy.php</filename>
</files>
<languages folder="language">
<language tag="en-GB">en-GB/en-GB.plg_rdmedia_tjsendy.ini</language>
<language tag="en-GB">en-GB/en-GB.plg_rdmedia_tjsendy.sys.ini</language>
</languages>
<config>
<fields name="params">
<fieldset name="widget" label="COM_PLUGINS_BASIC_FIELDSET_LABEL">
<field name="api_key" type="text" label="PLG_TJSENDY_API_KEY" description="Enter your API Key, available in Settings" />
<field name="sendy_url" type="text" label="Sendy Url"/>

<field
name="field-name"
type="subform"
label="PLG_TJSENDY_ID_FIELD"
multiple="true"
min="1"
max="10"
>
<form>
<field
name="category"
type="sql"
default="10"
label="PLG_TJSENDY_PRODUCT_CATEGORY"
query="SELECT id, name FROM #__rd_subs_categories"
key_field="id"
value_field="name"
/>
<field
name="listid"
type="textarea"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does not need to be textarea. The list id is not very long.

label="PLG_TJSENDY_LIST_ID"
cols="40"
rows="8"
/>
</form>
</field>
</fieldset>
</fields>
</config>
</extension>