Jump to content

Programatically create and update listings


Alejandro

Recommended Posts

Here's something you can try to programmatically create listings from other extensions/plugins:

<?php
// Load the JReviews framework
require_once JPATH_BASE.'/components/com_jreviews/jreviews/framework.php';

// Set the form token
$_POST[cmsFramework::getToken()] = 1;

// Let the framework know the code is accessed directly so it suppresses output headers
$_REQUEST['requested'] = 1;

// Build the request data
$params = [];

// Routing data

$params['data']['controller'] = 'listings';
$params['data']['action'] = '_save';

// Ensure that the form passes the consent checkbox validation if it's enabled
$params['data']['consent'] = true;

// Add  the standard fields
// Catid is required and must be a JReviews category, title is required if not disabled
$params['data']['Listing'] = [
	'catid' => 23,
	'title' => 'Programatically submitted listing',
	'introtext' => '<p>This is the listing summary.</p>',
	'fulltext' => '<p>This is the listing description.</p>',
];

// Add the custom field data
// For select,radio,checkbox fields, use the field option values
// Checkbox and multiselect fields need to use array inputs
$params['data']['Field']['Listing'] = [
	'jr_website' => 'http://origamiappbuilder.com',
	'jr_checkbox' => ['one','two']
];

$Dispatcher = new S2Dispatcher('jreviews');

// If running the script via cron without a specific Joomla user you will want to 
// set the listing owner by uncommenting the two lines below
// to load it using the user ID
// $auth = S2Object::make('auth');
// $auth->loadUser(46);

$output = $Dispatcher->dispatch($params);

$output = json_decode($output,true);

if ($output['success'] == true) 
{
	// Listing was successfully created

	$listingId = $output['listing_id'];	
}

 

Link to comment
  • 2 months later...
  • 11 months later...
  • 2 months later...
×
×
  • Create New...