X-Cart: shopping cart software

X-Cart forums (https://forum.x-cart.com/index.php)
-   Dev Questions (X-Cart 5) (https://forum.x-cart.com/forumdisplay.php?f=56)
-   -   Custom Module that Runs Every Hour (https://forum.x-cart.com/showthread.php?t=73146)

backyardfruit 11-24-2015 03:05 PM

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.';
    }
}


totaltec 11-25-2015 10:27 AM

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:



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

Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.