Skip to content

Instantly share code, notes, and snippets.

@gunjanpatel
Created September 23, 2016 14:09
Show Gist options
  • Select an option

  • Save gunjanpatel/8d07e477569bc4414e4867ab8da466da to your computer and use it in GitHub Desktop.

Select an option

Save gunjanpatel/8d07e477569bc4414e4867ab8da466da to your computer and use it in GitHub Desktop.
redSHOP CLI script to add e-conomic orders using CRON
<?php
/**
* @package Joomla.Cli
*
* @copyright Copyright (C) 2005 - 2016 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
// Make sure we're being called from the command line, not a web interface
if (PHP_SAPI !== 'cli')
{
die('This is a command line only application.');
}
// We are a valid entry point.
const _JEXEC = 1;
// Load system defines
if (file_exists(dirname(__DIR__) . '/defines.php'))
{
require_once dirname(__DIR__) . '/defines.php';
}
if (!defined('_JDEFINES'))
{
define('JPATH_BASE', dirname(__DIR__));
require_once JPATH_BASE . '/includes/defines.php';
}
define('JPATH_COMPONENT_ADMINISTRATOR', JPATH_ADMINISTRATOR . '/components/com_finder');
// Get the framework.
require_once JPATH_LIBRARIES . '/import.legacy.php';
// Bootstrap the CMS libraries.
require_once JPATH_LIBRARIES . '/cms.php';
// Import the configuration.
require_once JPATH_CONFIGURATION . '/configuration.php';
// Configure error reporting to maximum for CLI output.
error_reporting(E_ALL);
ini_set('display_errors', 1);
// Load Library language
$lang = JFactory::getLanguage();
$lang->load('com_redshop');
/**
* A command line cron job to attempt to remove files that should have been deleted at update.
*
* @since 3.0
*/
class EconomicCli extends JApplicationCli
{
/**
* Entry point for CLI script
*
* @return void
*
* @since 3.0
*/
public function doExecute()
{
// Print a blank line.
$this->out(JText::_('COM_REDSHOP_ECONOMIC_ORDER_CREATE_CLI'));
$this->out('============================');
$this->out('Loading redSHOP Library');
// Load redSHOP Library
JLoader::import('redshop.library');
$this->out('redSHOP Library loaded');
$this->out('============================');
// Economic Integration start for invoice generate
if (Redshop::getConfig()->get('ECONOMIC_INTEGRATION') == 1)
{
$orders = $this->getOrders();
foreach ($orders as $order)
{
$this->out('Processing order ' . $order->order_id);
try
{
economic::getInstance()->renewInvoiceInEconomic($order);
$this->out('Order created in e-conomic for ' . $order->order_id);
}
catch (Exception $e)
{
$this->out('Error Processing ' . $order->order_id);
$this->out($e->getMessage());
}
$this->out('============================');
}
}
else
{
$this->out('e-conomic is not enabled.');
}
}
/**
* Get order information from order id.
*
* @return object Order Information Object
*/
public function getOrders()
{
$db = JFactory::getDbo();
$query = $db->getQuery(true)
->select('*')
->from($db->qn('#__redshop_orders'))
->where($db->qn('is_booked') . ' = 0')
->where($db->qn('invoice_no') . ' = ' . $db->q(''))
->where($db->qn('order_status') . ' = ' . $db->q('C'))
->where($db->qn('order_payment_status') . ' = ' . $db->q('Paid'));
// Set the query and load the result.
$orders = $db->setQuery($query)->loadObjectList();
// Check for a database error.
if ($db->getErrorNum())
{
JError::raiseWarning(500, $db->getErrorMsg());
return null;
}
return $orders;
}
}
// Instantiate the application object, passing the class name to JCli::getInstance
// and use chaining to execute the application.
JApplicationCli::getInstance('EconomicCli')->execute();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment