diff --git a/tjsendy/language/en-GB/en-GB.plg_rdmedia_tjsendy.ini b/tjsendy/language/en-GB/en-GB.plg_rdmedia_tjsendy.ini new file mode 100644 index 0000000..3a72cce --- /dev/null +++ b/tjsendy/language/en-GB/en-GB.plg_rdmedia_tjsendy.ini @@ -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" diff --git a/tjsendy/language/en-GB/en-GB.plg_rdmedia_tjsendy.sys.ini b/tjsendy/language/en-GB/en-GB.plg_rdmedia_tjsendy.sys.ini new file mode 100644 index 0000000..843e2ab --- /dev/null +++ b/tjsendy/language/en-GB/en-GB.plg_rdmedia_tjsendy.sys.ini @@ -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" diff --git a/tjsendy/tjsendy.php b/tjsendy/tjsendy.php new file mode 100644 index 0000000..1dd6622 --- /dev/null +++ b/tjsendy/tjsendy.php @@ -0,0 +1,114 @@ + + * @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; + } + } +} diff --git a/tjsendy/tjsendy.xml b/tjsendy/tjsendy.xml new file mode 100644 index 0000000..7faa8d0 --- /dev/null +++ b/tjsendy/tjsendy.xml @@ -0,0 +1,55 @@ + + + plg_rdmedia_tjsendy + Techjoomla + 18th Octobar 2019 + Copyright (C) 2009 - 2020 Techjoomla. All rights reserved. + http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL + extensions@techjoomla.com + https://techjoomla.com + 1.0.0 + PLG_RDMEDIA_SENDY_XML_DESCRIPTION + + tjsendy.php + + + en-GB/en-GB.plg_rdmedia_tjsendy.ini + en-GB/en-GB.plg_rdmedia_tjsendy.sys.ini + + + +
+ + + + +
+ + + + +
+
+
+