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

Task #141211 chore: Order View for Vendor in frontend #30

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
97 changes: 87 additions & 10 deletions src/com_tjvendors/site/models/vendor.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@
defined('_JEXEC') or die;

jimport('joomla.application.component.modeladmin');

use Joomla\CMS\Table\Table;
use Joomla\CMS\Factory;
use Joomla\CMS\MVC\Model\AdminModel;

JLoader::import('fronthelper', JPATH_SITE . '/components/com_tjvendors/helpers');
JLoader::import('tjvendors', JPATH_ADMINISTRATOR . '/components/com_tjvendors/helpers');

Expand All @@ -18,7 +23,7 @@
*
* @since 1.6
*/
class TjvendorsModelVendor extends JModelAdmin
class TjvendorsModelVendor extends AdminModel
{
/**
* @var string client data
Expand Down Expand Up @@ -57,7 +62,7 @@ class TjvendorsModelVendor extends JModelAdmin
*/
public function getTable($type = 'Vendor', $prefix = 'TjvendorsTable', $config = array())
{
return JTable::getInstance($type, $prefix, $config);
return Table::getInstance($type, $prefix, $config);
}

/**
Expand All @@ -73,7 +78,7 @@ public function getTable($type = 'Vendor', $prefix = 'TjvendorsTable', $config =
public function getForm($data = array(), $loadData = true)
{
// Initialise variables.
$app = JFactory::getApplication();
$app = Factory::getApplication();

// Get the form.
$form = $this->loadForm(
Expand All @@ -100,11 +105,11 @@ public function getForm($data = array(), $loadData = true)
*/
protected function loadFormData()
{
$app = JFactory::getApplication();
$app = Factory::getApplication();
$input = $app->input;
$client = $input->get('client', '', 'STRING');

$data = JFactory::getApplication()->getUserState('com_tjvendors.edit.vendor.data', array());
$data = Factory::getApplication()->getUserState('com_tjvendors.edit.vendor.data', array());

if (empty($data))
{
Expand Down Expand Up @@ -146,8 +151,8 @@ public function getItem($pk = null)
{
$item = parent::getItem($pk);

JTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_tjvendors/tables');
$vendorXref = JTable::getInstance('VendorClientXref', 'TjvendorsTable');
Table::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_tjvendors/tables');
$vendorXref = Table::getInstance('VendorClientXref', 'TjvendorsTable');
$vendorXref->load(array('vendor_id' => $item->vendor_id));
$item->params = $vendorXref->params;

Expand Down Expand Up @@ -328,9 +333,9 @@ public function generateGatewayFields($payment_gateway, $parentTag)
public function save($data)
{
$table = $this->getTable();
$db = JFactory::getDbo();
$user = JFactory::getUser();
$app = JFactory::getApplication();
$db = Factory::getDbo();
$user = Factory::getUser();
$app = Factory::getApplication();
$input = $app->input;
$layout = $input->get('layout', '', 'STRING');
$xrefData = array();
Expand Down Expand Up @@ -607,4 +612,76 @@ public static function getPayableAmount($vendorId, $client = '', $currency = '')

return $payableAmount;
}

/**
* Get the vendor id
*
* @param Int $userId user id
*
* @param String $client client ex->"com_tjlms/com_jticketing"
*
* @return Int
*
* @since __DEPLOY_VERSION__
*/
public function validateVendor($userId, $client)
Copy link
Contributor

Choose a reason for hiding this comment

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

@amit4106udale the function name needs to be updated as per the functionality of the method.

The function seems to be checking if a user is already a vendor and if he is not then adding him as a vendor.

What exactly we are validating in this function?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@ankush-maherwal - We are checking the user is a vendor or not. If the user is not a vendor then make him. if he is a vendor the returning the id as it is. Discussed this with @twsvaishali @thite-amol

Copy link
Contributor

@ankush-maherwal ankush-maherwal Apr 17, 2019

Choose a reason for hiding this comment

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

@thite-amol @twsvaishali @amit4106udale Seems the function is wrongly named....validateVendor sounds as if we are performing some kind of validation for the vendor (Creating the vendor should not be the part of this function). To check if a user is a vendor for some client we already have a function named "checkVendor"

{
if (!class_exists('TjvendorFrontHelper'))
{
JLoader::register('TjvendorFrontHelper', JPATH_SITE . '/components/com_tjvendors/helpers/fronthelper.php');
JLoader::load('TjvendorFrontHelper');
}

if (!class_exists('TjvendorsHelper'))
{
JLoader::register('TjvendorsHelper', JPATH_ADMINISTRATOR . '/components/com_tjvendors/helpers/tjvendors.php');
JLoader::load('TjvendorsHelper');
}

// Generating vendor
$tjvendorFrontHelper = new TjvendorFrontHelper;
$tjvendorsHelper = new TjvendorsHelper;

// Checked if the user is a vendor
$getVendorId = $tjvendorFrontHelper->checkVendor($userId, $client);

// Collecting vendor data
$vendorData = array();
$vendorData['vendor_client'] = $client;
$vendorData['user_id'] = $userId;

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

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

Table::addIncludePath(JPATH_ROOT . '/administrator/components/com_tjvendors/tables');
$table = Table::getInstance('vendor', 'TJVendorsTable', array());
$table->load(
array(
'user_id' => $userId
)
);

// Check for vendor's id if not adds a vendor
if (empty($table->vendor_id))
{
$vendorId = $tjvendorsHelper->addVendor($vendorData);
}
elseif (empty($getVendorId))
{
$vendorData['vendor_id'] = $table->vendor_id;
$vendorId = $tjvendorsHelper->addVendor($vendorData);
}
else
{
$vendorId = $getVendorId;
}

return $vendorId;
}
}