Follow us on Twitter X-Cart on Facebook Wiki
Shopping cart software Solutions for online shops and malls
 

Custom Module that Runs Every Hour

 
Reply
   X-Cart forums > X-Cart 5 > Dev Questions (X-Cart 5)
 
Thread Tools Search this Thread
  #1  
Old 11-24-2015, 03:05 PM
 
backyardfruit backyardfruit is offline
    
Join Date: Nov 2015
Posts: 1
 

Default Custom Module that Runs Every Hour

I've got a blank new module. How would I go about adding some functionality to get my module to push product information to a third party every hour?

I'm totally new to writing modules for X-Cart. How do I find what functions I can extend/override?

PHP Code:
<?php
namespace XLite\Module\BackyardFruit\Indexing;
 
 
abstract class 
Main extends \XLite\Module\AModule
{
    
/**
     * Author name
     *
     * @return string
     */
    
public static function getAuthorName()
    {
        return 
'backyardfruit';
    }
 
    
/**
     * Module name
     *
     * @return string
     */
    
public static function getModuleName()
    {
        return 
'Indexing Module';
    }
 
    
/**
     * Get module major version
     *
     * @return string
     */
    
public static function getMajorVersion()
    {
        return 
'0.1';
    }
 
    
/**
     * Module version
     *
     * @return string
     */
    
public static function getMinorVersion()
    {
        return 
1;
    }
 
    
/**
     * Module description
     *
     * @return string
     */
    
public static function getDescription()
    {
        return 
'This module will send all products to third party every hour.';
    }
}
__________________
---
X-Cart 5.2.7
Reply With Quote
  #2  
Old 11-25-2015, 10:27 AM
  totaltec's Avatar 
totaltec totaltec is offline
 

X-Guru
  
Join Date: Jan 2007
Location: Louisville, KY USA
Posts: 5,823
 

Default Re: Custom Module that Runs Every Hour

You want to tap into X-Cart 5's cron jobs. You will see a database table called tasks that lists these jobs.

http://kb.x-cart.com/pages/viewpage.action?pageId=7504112 --this is how you setup your server to run X-Cart's cron.

In your YAML file you put something like this:
Code:
XLite\Model\Task: - owner: XLite\Module\DevID\ModuleName\Core\Task\Sync

Then you further define the task in your Sync.php like this:
Code:
namespace XLite\Module\DevId\ModuleName\Core\Task; use XLite\Module\DevId\ModuleName\Core\ModuleName; /** * Syncs with something. */ class Sync extends \XLite\Core\Task\Base\Periodic { const INT_1_MIN = 60; const INT_5_MIN = 300; const INT_10_MIN = 600; const INT_15_MIN = 900; const INT_30_MIN = 1800; const INT_1_HOUR = 3600; const INT_2_HOURS = 7200; const INT_4_HOURS = 14400; const INT_6_HOURS = 21600; const INT_12_HOURS = 43200; const INT_1_DAY = 86400; /** * Get title * * @return string */ public function getTitle() { return static::t('Module Name sync'); } /** * Run step * * @return void */ protected function runStep() { error_log('syncing'); ModuleName::getInstance()->sync(); } /** * Get period (seconds) * * @return integer */ protected function getPeriod() { return \XLite\Core\Config::getInstance()->DevId->ModuleName->updateInterval; } }

You can see that my example refers to an updateInterval you create such a setting in your YAML file like this:
Code:
XLite\Model\Config: - name: updateInterval category: DevId\ModuleName type: XLite\View\FormField\Input\Text orderby: 500 value: '3600' translations:
__________________
Mike White - Now Accepting new clients and projects! Work with the best, get a US based development team for just $125 an hour. Call 1-502-773-6454, email mike at babymonkeystudios.com, or skype b8bym0nkey

XcartGuru
X-cart Tutorials | X-cart 5 Tutorials

Check out the responsive template for X-cart.
Reply With Quote

The following user thanks totaltec for this useful post:
qualiteam (11-26-2015)
Reply
   X-Cart forums > X-Cart 5 > Dev Questions (X-Cart 5)



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -8. The time now is 01:13 AM.

   

 
X-Cart forums © 2001-2020