Skip to content
Snippets Groups Projects
Commit a07f4537 authored by Reinhold Kainhofer's avatar Reinhold Kainhofer
Browse files

Initial Version

parents
Branches
No related tags found
No related merge requests found
.svn
*~
cache
*.kate-swp
logs
tmp
Makefile 0 → 100644
BASE=buyer_assign_group
PLUGINTYPE=vmcustom
ZIPBASE=opentools_vm2
VERSION=0.1
PLUGINFILES=$(BASE).php $(BASE).script.php $(BASE).xml index.html
TRANSLATIONS=$(call wildcard,language/*/*.plg_$(PLUGINTYPE)_$(BASE).*ini) language/index.html $(call wildcard,language/*/index.html)
# INDEXFILES=$(BASE)/index.html
INDEXFILES=$(call wildcard,language/**/index.html) $(call wildcard,elements/*.html)
# ELEMENTS=$(call wildcard,elements/*.php)
# TMPLFILES=$(call wildcard,$(BASE)/tmpl/*.php) $(BASE)/index.html $(BASE)/tmpl/index.html
# ASSETS=$(call wildcard,$(BASE)/assets/*.png) $(call wildcard,$(BASE)/assets/*.css)
ZIPFILE=plg_$(ZIPBASE)_$(BASE)_v$(VERSION).zip
zip: $(PLUGINFILES) $(TRANSLATIONS) $(ELEMENTS) $(TMPLFILES)
@echo "Packing all files into distribution file $(ZIPFILE):"
@zip -r $(ZIPFILE) $(PLUGINFILES) $(TRANSLATIONS) $(ELEMENTS) $(INDEXFILES) $(TMPLFILES) $(ASSETS)
clean:
rm -f $(ZIPFILE)
<?php
defined('_JEXEC') or die( 'Direct Access to ' . basename( __FILE__ ) . ' is not allowed.' ) ;
/**
* A custom field plugin to automatically add buyers to Joomla! groups
* @author Reinhold Kainhofer, office@open-tools.net
* @package VirtueMart
* @subpackage vmcustom
* @copyright Copyright (C) 2013 Reinhold Kainhofer, Open Tools
* @license GNU/GPLv3+, http://www.gnu.org/copyleft/gpl-3.0.html
*
* http://www.open-tools.net/
*/
if (!class_exists('vmCustomPlugin')) require(JPATH_VM_PLUGINS . DS . 'vmcustomplugin.php');
class plgVmCustomBuyer_Assign_Group extends vmCustomPlugin {
function __construct(& $subject, $config) {
parent::__construct($subject, $config);
$this->_tablepkey = 'id';
$this->tableFields = array_keys($this->getTableSQLFields());
$varsToPush = array(
'joomla_groups'=>array(array(), 'array'),
'joomla_groups_remove'=>array(array(), 'array'),
'shopper_groups'=>array(array(), 'array'),
'shopper_groups_remove'=>array(array(), 'array'),
'purchased_status' => array(array(), 'array'),
);
$this->setConfigParameterable('custom_params',$varsToPush);
$this->onStoreInstallPluginTable($this->_psType);
}
function addJoomlaGroup($user, $group) {
# TODO
}
function removeJoomlaGroup($user, $group) {
# TODO
}
function addShopperGroup($user, $group) {
# TODO
}
function removeShopperGroup($user, $group) {
# TODO
}
/**
* @see Form displayed in the product edit page in the BE, configure the download file
* @author Reinhold Kainhofer
*/
function plgVmOnProductEdit($field, $product_id, &$row,&$retValue) {
if ($field->custom_element != $this->_name) return '';
$html = '';
$this->parseCustomParams($field);
// $html .= "<pre>States: ".join(", ", $this->purchased_status)."</pre>";
$html .= "<pre>Field: ".print_r($this, 1)."</pre>";
$html .= '<table class="admintable">';
$html .= VmHTML::row (array('JHTML', '_'),'VMCUSTOM_BUYER_GROUP_JOOMLA', 'access.usergroup', 'custom_param['.$row.'][joomla_groups][]', $field->joomla_groups, ' multiple data-placeholder=" "', false);
$html .= VmHTML::row (array('JHTML', '_'),'VMCUSTOM_BUYER_GROUP_JOOMLA_REMOVE', 'access.usergroup', 'custom_param['.$row.'][joomla_groups_remove][]', $field->joomla_groups_remove, ' multiple data-placeholder=" "', true);
$html .= VmHTML::row (array('ShopFunctions', 'renderShopperGroupList'), 'VMCUSTOM_BUYER_GROUP_SHOPPER', $field->shopper_groups, TRUE, 'custom_param['.$row.'][shopper_groups][]', ' ');
$html .= VmHTML::row (array('ShopFunctions', 'renderShopperGroupList'), 'VMCUSTOM_BUYER_GROUP_SHOPPER_REMOVE', $field->shopper_groups_remove, TRUE, 'custom_param['.$row.'][shopper_groups_remove][]', ' ');
$html .= '</table></fieldset>';
$retValue .= $html;
$row++;
return true ;
}
/**
* We must reimplement this triggers for joomla 1.7
* vmplugin triggers note by Max Milbers
*/
public function plgVmOnStoreInstallPluginTable($psType, $name) {
return $this->onStoreInstallPluginTable($psType, $name);
}
function plgVmDeclarePluginParamsCustom($psType,$name,$id, &$data){
return $this->declarePluginParams('custom', $name, $id, $data);
}
function plgVmSetOnTablePluginParamsCustom($name, $id, &$table){
return $this->setOnTablePluginParams($name, $id, $table);
}
function plgVmOnDisplayEdit($virtuemart_custom_id,&$customPlugin){
return $this->onDisplayEditBECustom($virtuemart_custom_id,$customPlugin);
}
/**
* Create the database table for this plugin.
*/
public function getVmPluginCreateTableSQL() {
return $this->createTableSQL('VM Buyer Assign Groups Plugin tracking');
}
function getTableSQLFields() {
$SQLfields = array(
'id' => 'int(1) UNSIGNED NOT NULL AUTO_INCREMENT',
'order_id' => 'int(11) UNSIGNED NOT NULL DEFAULT 0',
'user_id' => 'int(11) UNSIGNED DEFAULT 0',
'virtuemart_user_id' => 'int(11) UNSIGNED NOT NULL DEFAULT 0',
'virtuemart_custom_id' => 'int(11) UNSIGNED NOT NULL DEFAULT 0',
'virtuemart_customfield_id' => 'int(11) UNSIGNED NOT NULL DEFAULT 0',
'virtuemart_order_item_id' => 'int(11) UNSIGNED NULL DEFAULT 0',
'group_id' => 'int(11) UNSIGNED NULL DEFAULT 0',
'group_type' => 'int(1) UNSIGNED NULL DEFAULT 0',
'group_add' => 'bool DEFAULT 1',
'modified' => 'bool DEFAULT 1',
);
return $SQLfields;
}
function updateOrderStatus ($order_id, $order_status, $old_order_status) {
// 1) Load all entries associated with this order
$db = JFactory::getDbo();
$db->setQuery("SELeCT * FROM `".$this->_tablename."` WHERE `order_id` = ".(int)$order_id . ";");
$orderEntries = $db->loadAssocList();
if (is_null($orderEntries)) {
JFactory::getApplication()->enqueueMessage("SQL query FAILED: Message: ".$db->getErrorMsg(), 'error');
}
if (empty($orderEntries)) {
// Nothing to do, exit!
return;
}
// 2) Load all associated custom field definitions (to retrieve the order states)
$customsModel = VmModel::getModel('custom');
$userModel = VmModel::getModel('user');
$pstates = array();
$users = array();
foreach ($orderEntries as $e) {
$uid = $e['virtuemart_user_id'];
if (!isset($users[$uid])) {
$userModel->setId($uid);
$users[$uid] = $userModel->getUser();
}
$cid = $e['virtuemart_custom_id'];
if (!isset($customs[$cid])) {
$customsModel->setId($cid);
$c = $customsModel->getData();
$this->parseCustomParams($c);
$pstates[$cid] = $c->purchased_status;
}
}
// 3) Check which custom field entries need some change
foreach ($orderEntries as $e) {
$uid = $e['virtuemart_user_id'];
$cid = $e['virtuemart_custom_id'];
$purchased = in_array($order_status, $pstates[$cid]) && !in_array($old_order_status, $pstates[$cid]);
$unpurchased = !in_array($order_status, $pstates[$cid]) && in_array($old_order_status, $pstates[$cid]);
if ($purchased) {
// TODO: Check if user is alreay part of the group. If not, add him and set the modified flag
} elseif ($unpurchased && $e['modified'] {
// Undo the addition/removal when a product purchase is cancelled
}
}
JFactory::getApplication()->enqueueMessage("Order Entries: <pre>".print_r($orderEntries,1)."</pre>", 'info');
JFactory::getApplication()->enqueueMessage("Purchased States: <pre>".print_r($pstates,1)."</pre>", 'info');
JFactory::getApplication()->enqueueMessage("Customs: <pre>".print_r($customs,1)."</pre>", 'info');
// TODO:
}
function plgVmCouponUpdateOrderStatus($data, $old_order_status) {
return $this->plgVmOnUpdateOrder($data, $old_order_status);
}
function plgVmOnUpdateOrder($data, $old_order_status) {
return $this->updateOrderStatus($data->virtuemart_order_id, $data->order_status, $old_order_status);
}
function plgVmConfirmedOrder($cart, $order) {
// Each custom field will have its own value for auto-subscribe, so we need to handle all purchased products!
$vuid = $order['details']['BT']->virtuemart_user_id;
$userModel = VmModel::getModel('user');
$user = $userModel->getCurrentUser();
$uid = $user->JUser->id;
$order_id = $order['details']['BT']->virtuemart_order_id;
$values = array();
$customModel = VmModel::getModel('customfields');
foreach ($order['items'] as $item) {
$customs = $customModel->getproductCustomslist ($item->virtuemart_product_id);
foreach ($customs as $field) {
if ($field->custom_element != $this->_name) continue;
$cdata = array ((int)$order_id, $uid, $vuid, (int)$field->virtuemart_custom_id, (int)$field->virtuemart_customfield_id, (int)$item->virtuemart_order_item_id);
foreach ($field->joomla_groups as $g) {
$values[] = join(", ", array_merge($cdata, array((int)$g, 0, 1)));
}
foreach ($field->joomla_groups_remove as $g) {
$values[] = join(", ", array_merge($cdata, array((int)$g, 0, 0)));
}
foreach ($field->shopper_groups as $g) {
$values[] = join(", ", array_merge($cdata, array((int)$g, 1, 1)));
}
foreach ($field->shopper_groups_remove as $g) {
$values[] = join(", ", array_merge($cdata, array((int)$g, 1, 0)));
}
}
}
if (!empty($values) && $uid==0 && $vuid==0) {
JFactory::getApplication()->enqueueMessage(JText::_('VMCUSTOM_BUYER_GROUP_NO_UID'), 'error');
return;
}
if (!empty($values)) {
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query->insert($this->_tablename);
$query->columns('`order_id`, `user_id`, `virtuemart_user_id`, `virtuemart_custom_id`, `virtuemart_customfield_id`, `virtuemart_order_item_id`, `group_id`, `group_type` , `group_add`');
$query->values($values);
$db->setQuery($query);
if (!$db->query()) {
JFactory::getApplication()->enqueueMessage("SQL query FAILED: Message: ".$db->getErrorMsg().", SQL: <pre>".$query->dump()."</pre>", 'error');
}
$this->updateOrderStatus($order_id, $order['details']['BT']->order_status, '');
}
}
}
// No closing tag
\ No newline at end of file
<?php
defined('_JEXEC') or die('Restricted access');
/**
* Installation script for the plugin
*
* @copyright Copyright (C) 2013 Reinhold Kainhofer, office@open-tools.net
* @license GPL v3+, http://www.gnu.org/copyleft/gpl.html
*/
class plgVmCustomBuyer_Assign_GroupInstallerScript
{
/**
* Constructor
*
* @param JAdapterInstance $adapter The object responsible for running this script
*/
// public function __constructor(JAdapterInstance $adapter);
/**
* Called before any type of action
*
* @param string $route Which action is happening (install|uninstall|discover_install)
* @param JAdapterInstance $adapter The object responsible for running this script
*
* @return boolean True on success
*/
// public function preflight($route, JAdapterInstance $adapter);
/**
* Called after any type of action
*
* @param string $route Which action is happening (install|uninstall|discover_install)
* @param JAdapterInstance $adapter The object responsible for running this script
*
* @return boolean True on success
*/
// public function postflight($route, JAdapterInstance $adapter);
/**
* Called on installation
*
* @param JAdapterInstance $adapter The object responsible for running this script
*
* @return boolean True on success
*/
public function install(JAdapterInstance $adapter)
{
// enabling plugin
$db =& JFactory::getDBO();
$db->setQuery('update #__extensions set enabled = 1 where type = "plugin" and element = "buyer_assign_group" and folder = "vmcustom"');
$db->query();
return True;
}
/**
* Called on update
*
* @param JAdapterInstance $adapter The object responsible for running this script
*
* @return boolean True on success
*/
// public function update(JAdapterInstance $adapter)
// {
// jimport( 'joomla.filesystem.file' );
// $file = JPATH_ROOT . DS . "administrator" . DS . "language" . DS . "en-GB" . DS . "en-GB.plg_vmshopper_ordernumber.sys.ini";
// if (JFile::exists($file)) JFile::delete($file);
// $file = JPATH_ROOT . DS . "administrator" . DS . "language" . DS . "de-DE" . DS . "de-DE.plg_vmshopper_ordernumber.sys.ini";
// if (JFile::exists($file)) JFile::delete($file);
// return true;
// }
/**
* Called on uninstallation
*
* @param JAdapterInstance $adapter The object responsible for running this script
*/
public function uninstall(JAdapterInstance $adapter)
{
// Remove plugin table
// $db =& JFactory::getDBO();
// $db->setQuery('DROP TABLE `#__virtuemart_shipment_plg_rules_shipping`;');
// $db->query();
}
}
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8" ?>
<install version="1.5" type="plugin" group="vmcustom" method="upgrade">
<name>VMCUSTOM_BUYER_GROUP</name>
<creationDate>2013-02-24</creationDate>
<author>Reinhold Kainhofer</author>
<authorUrl>http://www.open-tools.net/</authorUrl>
<copyright>Copyright (C) 2013 Reinhold Kainhofer. All rights reserved.</copyright>
<license>http://www.gnu.org/licenses/gpl.html GNU/GPL v3+</license>
<version>0.1</version>
<description>VMCUSTOM_BUYER_GROUP_DESC</description>
<files>
<filename plugin="buyer_assign_group">buyer_assign_group.php</filename>
<filename>buyer_assign_group.script.php</filename>
<filename>index.html</filename>
<folder>language</folder>
</files>
<languages folder="language">
<language tag="en-GB">en-GB/en-GB.plg_vmcustom_buyer_assign_group.ini</language>
<language tag="en-GB">en-GB/en-GB.plg_vmcustom_buyer_assign_group.sys.ini</language>
</languages>
<scriptfile>buyer_assign_group.script.php</scriptfile>
<params addpath="/plugins/vmcustom/buyer_assign_group/elements/" />
<params addpath="/administrator/components/com_virtuemart/elements/">
<param type="vmjpluginwarning" />
<param name="purchased_status" type="vmorderstates" default="C, S" multiple="multiple" label="VMCUSTOM_BUYER_GROUP_STATUS" description="VMCUSTOM_BUYER_GROUP_STATUS_DESC"/>
</params>
</install>
<?php
defined ('_JEXEC') or die();
/**
*
* @package VirtueMart
* @subpackage Plugins - Elements
* @author Valérie Isaksen
* @link http://www.virtuemart.net
* @copyright Copyright (c) 2004 - 2011 VirtueMart Team. All rights reserved.
* @license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see LICENSE.php
* VirtueMart is free software. This version may have been modified pursuant
* to the GNU General Public License, and as distributed it includes or
* is derivative of works licensed under the GNU General Public License or
* other free or open source software licenses.
* @version $Id:$
*/
/*
* This class is used by VirtueMart Payment or Shipment Plugins
* which uses JParameter
* So It should be an extension of JElement
* Those plugins cannot be configured througth the Plugin Manager anyway.
*/
class JElementVmOrderStates extends JElement {
/**
* Element name
*
* @access protected
* @var string
*/
var $_name = 'OrderStates';
function fetchElement ($name, $value, &$node, $control_name) {
$db = JFactory::getDBO ();
$query = 'SELECT `order_status_code` AS value, `order_status_name` AS text
FROM `#__virtuemart_orderstates`
WHERE `virtuemart_vendor_id` = 1
ORDER BY `ordering` ASC ';
$db->setQuery ($query);
$fields = $db->loadObjectList ();
$class = 'class="inputbox" multiple="multiple" size="6" ';
foreach ($fields as $field) {
$field->text= JText::_ ($field->text);
}
return JHTML::_ ('select.genericlist', $fields, $control_name . '[' . $name . '][]', $class, 'value', 'text', $value, $control_name . $name);
}
}
; Virtuemart! Project
; Copyright (C) 2013 Open Tools, Reinhold Kainhofer
; License http://www.gnu.org/licenses/gpl.html GNU/GPL, see LICENSE.php
; Note : All ini files need to be saved as UTF-8 - No BOM
VMCUSTOM_BUYER_GROUP="Add Buyers to Joomla Groups for VirtueMart"
VMCUSTOM_BUYER_GROUP_DESC="VirtueMart custom field plugin to automatically add buyers to a Joomla group."
VMCUSTOM_BUYER_GROUP_STATUS="Order status to indicate a successful purchase"
VMCUSTOM_BUYER_GROUP_STATUS_DESC="The user will be added to/removed from the groups (if neccessary) only if the order has one of these statuses. If the order status changes back to a non-authorized status, the user will be removed again from the corresponding groups (unless this plugin did not add the user)."
VMCUSTOM_BUYER_GROUP_JOOMLA="Add to Joomla Usergroups:"
VMCUSTOM_BUYER_GROUP_JOOMLA_REMOVE="Remove from Joomla Usergroups:"
VMCUSTOM_BUYER_GROUP_SHOPPER="Add to VM Shoppergroups:"
VMCUSTOM_BUYER_GROUP_SHOPPER_REMOVE="Remove from VM Shoppergroups:"
VMCUSTOM_BUYER_GROUP_NO_UID="Not logged in as Joomla and VirtueMart user, unable to add to user groups. Please contact the vendor."
\ No newline at end of file
; Virtuemart! Project
; Copyright (C) 2013 Open Tools, Reinhold Kainhofer
; License http://www.gnu.org/licenses/gpl.html GNU/GPL, see LICENSE.php
; Note : All ini files need to be saved as UTF-8 - No BOM
VMCUSTOM_BUYER_GROUP="Add Buyers to Joomla Groups for VirtueMart"
VMCUSTOM_BUYER_GROUP_DESC="VirtueMart custom field plugin to automatically add buyers to a Joomla group."
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment