-
Notifications
You must be signed in to change notification settings - Fork 1
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
tushar33
wants to merge
3
commits into
techjoomla:master
Choose a base branch
from
tushar33:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'; | ||
|
||
$return = $http->post($this->params['sendy_url'] . '/subscribe', $data); | ||
} | ||
catch (Exception $e) | ||
{ | ||
JError::raiseWarning(500, Text::sprintf('PLG_TJSENDY_ERROR', $e->getMessage())); | ||
|
||
return; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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> |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.
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