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

Issue #143458 fix:Create a function which will create a vendor for th… #31

Open
wants to merge 1 commit into
base: release-1.4.4
Choose a base branch
from
Open
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
62 changes: 62 additions & 0 deletions src/com_tjvendors/site/models/vendor.php
Original file line number Diff line number Diff line change
Expand Up @@ -607,4 +607,66 @@ public static function getPayableAmount($vendorId, $client = '', $currency = '')

return $payableAmount;
}

/**
* Check if vendor exists, if not create
*
* @param Int $userId user id
*
* @param String $client client ex->"com_tjlms/com_jticketing"
*
* @return Int|Boolean
*
* @since __DEPLOY_VERSION__
*/
public function checkOrCreateVendor($userId, $client)
{
if (!$userId || !$client)
{
return false;
}

$vendorData = array();
$vendorData['vendor_client'] = $client;
$vendorData['user_id'] = $userId;
$vendorData['vendor_title'] = Factory::getUser($userId)->name;
$vendorData['state'] = "1";

// Collecting payment gateway details
$paymentDetails = array();
$paymentDetails['payment_gateway'] = '';
$vendorData['paymentDetails'] = json_encode($paymentDetails);

try
{
$vendorTable = $this->getTable();
$vendorTable->load(array('user_id' => $userId));

if (!$vendorTable->vendor_id)
{
return $this->save($vendorData);
}

$vendorId = $vendorTable->vendor_id;

// Check if vendor id is added against client
$xreftable = Table::getInstance('vendorclientxref', 'TjvendorsTable');
$xreftable->load(array('vendor_id' => $vendorTable->vendor_id, 'client' => $client));

if (!$xreftable->id)
{
$vendorData['vendor_id'] = $vendorId;

return $this->save($vendorData);
}

return $vendorId;
}
catch (Exception $e)
{
JFactory::getApplication()->enqueueMessage(JText::_('COM_TJVENDORS_DB_EXCEPTION_WARNING_MESSAGE'), 'error');

return false;
}
}
}